Skip to content

Commit 7e35dac

Browse files
pyokagangitster
authored andcommitted
builtin-am: implement -S/--gpg-sign, commit.gpgsign
Since 3b4e395 (am: add the --gpg-sign option, 2014-02-01), git-am.sh supported the --gpg-sign option, and would pass it to git-commit-tree, thus GPG-signing the commit object. Re-implement this option in builtin/am.c. git-commit-tree would also sign the commit by default if the commit.gpgsign setting is true. Since we do not run commit-tree, we re-implement this behavior by handling the commit.gpgsign setting ourselves. Helped-by: Stefan Beller <[email protected]> Signed-off-by: Paul Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0cd4bcb commit 7e35dac

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

builtin/am.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ struct am_state {
110110
const char *resolvemsg;
111111
int committer_date_is_author_date;
112112
int ignore_date;
113+
const char *sign_commit;
113114
int rebasing;
114115
};
115116

@@ -119,6 +120,8 @@ struct am_state {
119120
*/
120121
static void am_state_init(struct am_state *state, const char *dir)
121122
{
123+
int gpgsign;
124+
122125
memset(state, 0, sizeof(*state));
123126

124127
assert(dir);
@@ -133,6 +136,9 @@ static void am_state_init(struct am_state *state, const char *dir)
133136
state->scissors = SCISSORS_UNSET;
134137

135138
argv_array_init(&state->git_apply_opts);
139+
140+
if (!git_config_get_bool("commit.gpgsign", &gpgsign))
141+
state->sign_commit = gpgsign ? "" : NULL;
136142
}
137143

138144
/**
@@ -1227,7 +1233,7 @@ static void do_commit(const struct am_state *state)
12271233
state->ignore_date ? "" : state->author_date, 1);
12281234

12291235
if (commit_tree(state->msg, state->msg_len, tree, parents, commit,
1230-
author, NULL))
1236+
author, state->sign_commit))
12311237
die(_("failed to write commit object"));
12321238

12331239
reflog_msg = getenv("GIT_REFLOG_ACTION");
@@ -1673,6 +1679,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
16731679
N_("lie about committer date")),
16741680
OPT_BOOL(0, "ignore-date", &state.ignore_date,
16751681
N_("use current timestamp for author date")),
1682+
{ OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
1683+
N_("GPG-sign commits"),
1684+
PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
16761685
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
16771686
N_("(internal use for git-rebase)")),
16781687
OPT_END()

0 commit comments

Comments
 (0)