Skip to content

Commit

Permalink
commit --amend: copy notes to the new commit
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Thomas Rast authored and Junio C Hamano committed Mar 13, 2010
1 parent eb2151b commit 6360d34
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions t/t7501-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6360d34

Please sign in to comment.