Thread (76 messages) flat view 76 messages, 5 authors, 2016-06-15
STALE3749d

[RFC PATCH v2 09/11] commit --amend: copy notes to the new commit

From: Thomas Rast <hidden>
Date: 2016-06-15 22:48:17
Subsystem: the rest · Maintainer: Linus Torvalds

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 <redacted>
---
 builtin-commit.c  |    6 ++++++
 t/t7501-commit.sh |   11 +++++++++++
 2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/builtin-commit.c b/builtin-commit.c
index 9b67649..1943615 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -1341,9 +1341,15 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	run_hook(get_index_file(), "post-commit", NULL);
 	if (amend && !no_post_rewrite) {
 		struct commit *commit;
+		struct notes_rewrite_cfg *cfg;
 		commit = lookup_commit(head_sha1);
 		if (!commit || parse_commit(commit))
 			die("HEAD commit disappeared right under my eyes?");
+		cfg = init_copy_notes_for_rewrite("amend");
+		if (cfg) {
+			copy_note_for_rewrite(cfg, commit->object.sha1, commit_sha1);
+			finish_copy_notes_for_rewrite(cfg);
+		}
 		run_rewrite_hook(commit->object.sha1, commit_sha1);
 	}
 	if (!quiet)
diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh
index 7940901..93d3c81 100755
--- a/t/t7501-commit.sh
+++ b/t/t7501-commit.sh
@@ -425,4 +425,15 @@ 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 &&
+	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.53.g5c2e6.dirty
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help