Skip to content

Commit 6360d34

Browse files
trastgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent eb2151b commit 6360d34

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

builtin-commit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,6 +1340,12 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
13401340
rerere(0);
13411341
run_hook(get_index_file(), "post-commit", NULL);
13421342
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+
}
13431349
run_rewrite_hook(head_sha1, commit_sha1);
13441350
}
13451351
if (!quiet)

t/t7501-commit.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,4 +425,16 @@ test_expect_success 'amend using the message from a commit named with tag' '
425425
426426
'
427427

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+
428440
test_done

0 commit comments

Comments
 (0)