commit --amend: copy notes to the new commit
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> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Rast committed
Mar 12, 2010 at 18:04 UTC
6360d343af9acf7366be6ff89740f5077e12277b
2 files changed
+18
builtin-commit.c
+6
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1340
rerere(0);
1341
run_hook(get_index_file(), "post-commit", NULL);
1342
if (amend && !no_post_rewrite) {
1343
+ struct notes_rewrite_cfg *cfg;
1344
+ cfg = init_copy_notes_for_rewrite("amend");
1345
+ if (cfg) {
1346
+ copy_note_for_rewrite(cfg, head_sha1, commit_sha1);
1347
+ finish_copy_notes_for_rewrite(cfg);
1348
+ }
1349
run_rewrite_hook(head_sha1, commit_sha1);
1350
}
1351
if (!quiet)
t/t7501-commit.sh
+12
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' '
425
426
'
427
428
+test_expect_success 'amend can copy notes' '
429
+
430
+ git config notes.rewrite.amend true &&
431
+ git config notes.rewriteRef "refs/notes/*" &&
432
+ test_commit foo &&
433
+ git notes add -m"a note" &&
434
+ test_tick &&
435
+ git commit --amend -m"new foo" &&
436
+ test "$(git notes show)" = "a note"
437
+
438
+'
439
+
440
test_done