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

[PATCH v4 10/11] commit --amend: copy notes to the new commit

From
Thomas Rast <trast@student.ethz.ch>
Date
Feb 22, 2010, 00:10 UTC
Message-ID
<1847c7beec59d9069eba758eaf67649a0629a15f.1266797028.git.trast@student.ethz.ch>
In-Reply-To
<cover.1266797028.git.trast@student.ethz.ch>

Teaches 'git commit --amend' to copy notes. The catch is that this must also be guarded by --no-post-rewrite, which we use to prevent --amend from copying notes during a rebase -i 'edit'/'reword'.

Signed-off-by: Thomas Rast <trast@student.ethz.ch>
---
Unchanged from v3
 builtin-commit.c  |    6 ++++++
 t/t7501-commit.sh |   12 ++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index f476d85..ccc4f92 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	rerere(0);
 	run_hook(get_index_file(), "post-commit", NULL);
 	if (amend && !no_post_rewrite) {
+		struct notes_rewrite_cfg *cfg;
+		cfg = init_copy_notes_for_rewrite("amend");
+		if (cfg) {
+			copy_note_for_rewrite(cfg, head_sha1, commit_sha1);
+			finish_copy_notes_for_rewrite(cfg);
+		}
 		run_rewrite_hook(head_sha1, commit_sha1);
 	}
 	if (!quiet)
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 7940901..8297cb4 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' '
 
 '
 
+test_expect_success 'amend can copy notes' '
+
+	git config notes.rewrite.amend true &&
+	git config notes.rewriteRef "refs/notes/*" &&
+	test_commit foo &&
+	git notes add -m"a note" &&
+	test_tick &&
+	git commit --amend -m"new foo" &&
+	test "$(git notes show)" = "a note"
+
+'
+
 test_done
-- 
1.7.0.147.g5aeb9
Previous: Thomas RastNext: Thomas Rast
Message 14 of 17 in “several notes refs, post-rewrite, notes rewriting”
  1. 00/11 several notes refs, post-rewrite, notes rewritingThomas Rast, Feb 22, 2010
  2. 01/11 test-lib: unset GIT_NOTES_REF to stop it from influencing testsThomas Rast, Feb 22, 2010
  3. 02/11 Support showing notes from more than one notes treeThomas Rast, Feb 22, 2010
  4. Junio C HamanoFeb 22, 2010
  5. Thomas RastFeb 22, 2010
  6. Junio C HamanoFeb 23, 2010
  7. 03/11 Documentation: document post-rewrite hookThomas Rast, Feb 22, 2010
  8. 04/11 commit --amend: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  9. 05/11 rebase: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  10. 06/11 rebase -i: invoke post-rewrite hookThomas Rast, Feb 22, 2010
  11. 07/11 notes: implement 'git notes copy --stdin'Thomas Rast, Feb 22, 2010
  12. 08/11 notes: implement helpers needed for note copying during rewriteThomas Rast, Feb 22, 2010
  13. 09/11 rebase: support automatic notes copyingThomas Rast, Feb 22, 2010
  14. 10/11 commit --amend: copy notes to the new commitThomas Rast, Feb 22, 2010
  15. 11/11 notes: add shorthand --ref to override GIT_NOTES_REFThomas Rast, Feb 22, 2010
  16. Junio C HamanoFeb 22, 2010
  17. Thomas RastFeb 22, 2010

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.