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 <sbeller@google.com> Signed-off-by: Paul Tan <pyokagan@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paul Tan committed
Aug 4, 2015 at 21:51 UTC
7e35dacbe392f0d5faf3c75e8964ae96aa4636a7
1 file changed
+10
-1
builtin/am.c
+10
-1
@@ -110,6 +110,7 @@ struct am_state {
110
const char *resolvemsg;
111
int committer_date_is_author_date;
112
int ignore_date;
113
+ const char *sign_commit;
114
int rebasing;
115
};
116
@@ -119,6 +120,8 @@ struct am_state {
120
*/
121
static void am_state_init(struct am_state *state, const char *dir)
122
{
123
+ int gpgsign;
124
+
125
memset(state, 0, sizeof(*state));
126
127
assert(dir);
@@ -133,6 +136,9 @@ static void am_state_init(struct am_state *state, const char *dir)
136
state->scissors = SCISSORS_UNSET;
137
138
argv_array_init(&state->git_apply_opts);
139
+
140
+ if (!git_config_get_bool("commit.gpgsign", &gpgsign))
141
+ state->sign_commit = gpgsign ? "" : NULL;
142
}
143
144
/**
@@ -1227,7 +1233,7 @@ static void do_commit(const struct am_state *state)
1233
state->ignore_date ? "" : state->author_date, 1);
1234
1235
if (commit_tree(state->msg, state->msg_len, tree, parents, commit,
1230
- author, NULL))
1236
+ author, state->sign_commit))
1237
die(_("failed to write commit object"));
1238
1239
reflog_msg = getenv("GIT_REFLOG_ACTION");
@@ -1673,6 +1679,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
1679
N_("lie about committer date")),
1680
OPT_BOOL(0, "ignore-date", &state.ignore_date,
1681
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) "" },
1685
OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
1686
N_("(internal use for git-rebase)")),
1687
OPT_END()