git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 31/44] builtin-am: implement -S/--gpg-sign, commit.gpgsign

From
Paul Tan <pyokagan@gmail.com>
Date
Jul 7, 2015, 14:20 UTC
Message-ID
<1436278862-2638-32-git-send-email-pyokagan@gmail.com>
In-Reply-To
<1436278862-2638-1-git-send-email-pyokagan@gmail.com>

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>
---
Notes:
    v5
    
    * Renamed local "sign_commit" variable in am_state_init() to "gpgsign"
      to aid code review.
 builtin/am.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/builtin/am.c b/builtin/am.c
index d7bb159..81b3e31 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -124,6 +124,8 @@ struct am_state {
 
 	int ignore_date;
 
+	const char *sign_commit;
+
 	int rebasing;
 };
 
@@ -133,6 +135,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);
@@ -149,6 +153,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;
 }
 
 /**
@@ -1266,7 +1273,7 @@ static void do_commit(const struct am_state *state)
 			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");
@@ -1688,6 +1695,9 @@ int cmd_am(int argc, const char **argv, const char *prefix)
 			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()
-- 
2.5.0.rc1.76.gf60a929
Previous: Paul TanNext: Paul Tan
Message 39 of 63 in “Make git-am a builtin”
  1. 00/44 Make git-am a builtinPaul Tan, Jul 7, 2015
  2. 01/44 wrapper: implement xopen()Paul Tan, Jul 7, 2015
  3. 02/44 wrapper: implement xfopen()Paul Tan, Jul 7, 2015
  4. 03/44 builtin-am: implement skeletal builtin amPaul Tan, Jul 7, 2015
  5. 04/44 builtin-am: implement patch queue mechanismPaul Tan, Jul 7, 2015
  6. 05/44 builtin-am: split out mbox/maildir patches with git-mailsplitPaul Tan, Jul 7, 2015
  7. 06/44 builtin-am: auto-detect mbox patchesPaul Tan, Jul 7, 2015
  8. 07/44 builtin-am: extract patch and commit info with git-mailinfoPaul Tan, Jul 7, 2015
  9. 08/44 builtin-am: apply patch with git-applyPaul Tan, Jul 7, 2015
  10. 09/44 builtin-am: implement committing applied patchPaul Tan, Jul 7, 2015
  11. 10/44 builtin-am: refuse to apply patches if index is dirtyPaul Tan, Jul 7, 2015
  12. 11/44 builtin-am: implement --resolved/--continuePaul Tan, Jul 7, 2015
  13. 12/44 builtin-am: implement --skipPaul Tan, Jul 7, 2015
  14. Stefan BellerJul 13, 2015
  15. Paul TanJul 14, 2015
  16. Stefan BellerJul 14, 2015
  17. Paul TanJul 18, 2015
  18. 13/44 builtin-am: implement --abortPaul Tan, Jul 7, 2015
  19. 14/44 builtin-am: reject patches when there's a session in progressPaul Tan, Jul 7, 2015
  20. 15/44 builtin-am: implement -q/--quietPaul Tan, Jul 7, 2015
  21. 16/44 builtin-am: exit with user friendly message on failurePaul Tan, Jul 7, 2015
  22. 17/44 builtin-am: implement -s/--signoffPaul Tan, Jul 7, 2015
  23. 18/44 cache-tree: introduce write_index_as_tree()Paul Tan, Jul 7, 2015
  24. Junio C HamanoJul 7, 2015
  25. 19/44 builtin-am: implement --3way, am.threeWayPaul Tan, Jul 7, 2015
  26. Junio C HamanoJul 7, 2015
  27. Paul TanJul 14, 2015
  28. 20/44 builtin-am: implement --rebasing modePaul Tan, Jul 7, 2015
  29. 21/44 builtin-am: bypass git-mailinfo when --rebasingPaul Tan, Jul 7, 2015
  30. 22/44 builtin-am: handle stray state directoryPaul Tan, Jul 7, 2015
  31. 23/44 builtin-am: implement -u/--utf8Paul Tan, Jul 7, 2015
  32. 24/44 builtin-am: implement -k/--keep, --keep-non-patchPaul Tan, Jul 7, 2015
  33. 25/44 builtin-am: implement --[no-]message-id, am.messageidPaul Tan, Jul 7, 2015
  34. 26/44 builtin-am: support --keep-cr, am.keepcrPaul Tan, Jul 7, 2015
  35. 27/44 builtin-am: implement --[no-]scissorsPaul Tan, Jul 7, 2015
  36. 28/44 builtin-am: pass git-apply's options to git-applyPaul Tan, Jul 7, 2015
  37. 29/44 builtin-am: implement --ignore-datePaul Tan, Jul 7, 2015
  38. 30/44 builtin-am: implement --committer-date-is-author-datePaul Tan, Jul 7, 2015
  39. 31/44 builtin-am: implement -S/--gpg-sign, commit.gpgsignPaul Tan, Jul 7, 2015
  40. 32/44 builtin-am: invoke post-rewrite hookPaul Tan, Jul 7, 2015
  41. 33/44 builtin-am: support automatic notes copyingPaul Tan, Jul 7, 2015
  42. 34/44 builtin-am: invoke applypatch-msg hookPaul Tan, Jul 7, 2015
  43. 35/44 builtin-am: invoke pre-applypatch hookPaul Tan, Jul 7, 2015
  44. 36/44 builtin-am: invoke post-applypatch hookPaul Tan, Jul 7, 2015
  45. 37/44 builtin-am: rerere supportPaul Tan, Jul 7, 2015
  46. 38/44 builtin-am: support and auto-detect StGit patchesPaul Tan, Jul 7, 2015
  47. 39/44 builtin-am: support and auto-detect StGit series filesPaul Tan, Jul 7, 2015
  48. 40/44 builtin-am: support and auto-detect mercurial patchesPaul Tan, Jul 7, 2015
  49. 41/44 builtin-am: implement -i/--interactivePaul Tan, Jul 7, 2015
  50. 42/44 builtin-am: implement legacy -b/--binary optionPaul Tan, Jul 7, 2015
  51. 43/44 builtin-am: check for valid committer identPaul Tan, Jul 7, 2015
  52. 44/44 builtin-am: remove redirection to git-am.shPaul Tan, Jul 7, 2015
  53. Junio C HamanoJul 7, 2015
  54. Paul TanJul 7, 2015
  55. Junio C HamanoJul 8, 2015
  56. Paul TanJul 8, 2015
  57. Junio C HamanoJul 8, 2015
  58. Paul TanJul 8, 2015
  59. Junio C HamanoJul 9, 2015
  60. Paul TanJul 12, 2015
  61. Junio C HamanoJul 12, 2015
  62. Junio C HamanoJul 13, 2015
  63. Paul TanJul 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.