builtin-am: implement -S/--gpg-sign, commit.gpgsign
[gitweb.git] / builtin / am.c
index 84d3e0519e6501408c5cc792f31c8db4bebc64e7..18611fa0c396bdf951cb66aca8377f3b11aed960 100644 (file)
@@ -108,7 +108,9 @@ struct am_state {
        int scissors; /* enum scissors_type */
        struct argv_array git_apply_opts;
        const char *resolvemsg;
+       int committer_date_is_author_date;
        int ignore_date;
+       const char *sign_commit;
        int rebasing;
 };
 
@@ -118,6 +120,8 @@ struct am_state {
  */
 static void am_state_init(struct am_state *state, const char *dir)
 {
+       int gpgsign;
+
        memset(state, 0, sizeof(*state));
 
        assert(dir);
@@ -132,6 +136,9 @@ static void am_state_init(struct am_state *state, const char *dir)
        state->scissors = SCISSORS_UNSET;
 
        argv_array_init(&state->git_apply_opts);
+
+       if (!git_config_get_bool("commit.gpgsign", &gpgsign))
+               state->sign_commit = gpgsign ? "" : NULL;
 }
 
 /**
@@ -1221,8 +1228,12 @@ static void do_commit(const struct am_state *state)
                        state->ignore_date ? NULL : state->author_date,
                        IDENT_STRICT);
 
+       if (state->committer_date_is_author_date)
+               setenv("GIT_COMMITTER_DATE",
+                       state->ignore_date ? "" : state->author_date, 1);
+
        if (commit_tree(state->msg, state->msg_len, tree, parents, commit,
-                               author, NULL))
+                               author, state->sign_commit))
                die(_("failed to write commit object"));
 
        reflog_msg = getenv("GIT_REFLOG_ACTION");
@@ -1663,8 +1674,14 @@ int cmd_am(int argc, const char **argv, const char *prefix)
                OPT_CMDMODE(0, "abort", &resume,
                        N_("restore the original branch and abort the patching operation."),
                        RESUME_ABORT),
+               OPT_BOOL(0, "committer-date-is-author-date",
+                       &state.committer_date_is_author_date,
+                       N_("lie about committer date")),
                OPT_BOOL(0, "ignore-date", &state.ignore_date,
                        N_("use current timestamp for author date")),
+               { OPTION_STRING, 'S', "gpg-sign", &state.sign_commit, N_("key-id"),
+                 N_("GPG-sign commits"),
+                 PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
                OPT_HIDDEN_BOOL(0, "rebasing", &state.rebasing,
                        N_("(internal use for git-rebase)")),
                OPT_END()