builtin-notes: Add "copy" subcommand for copying notes between objects
This is useful for keeping notes to objects that are being rewritten by e.g.
'git commit --amend', 'git rebase', or 'git cherry-pick'.
"git notes copy <from> <to>" is in practice equivalent to
"git notes add -C $(git notes list <from>) <to>", although it is somewhat
more convenient for regular users.
"git notes copy" takes the same -f option as "git add", to overwrite existing
notes at the target (instead of aborting with an error message).
If the <from>-object has no notes, "git notes copy" will abort with an error
message.
The patch includes tests verifying correct behaviour of the new subcommand.
Signed-off-by: Johan Herland <johan@herland.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Johan Herland15 years agocommitted byJunio C Hamano
@ -581,4 +581,67 @@ test_expect_success 'append to note from other note with "git notes append -c"'
@@ -581,4 +581,67 @@ test_expect_success 'append to note from other note with "git notes append -c"'
test_cmp expect actual
'
cat > expect << EOF
commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:23:13 2005 -0700
11th
Notes:
other note
$whitespace
yet another note
EOF
test_expect_success 'copy note with "git notes copy"' '
: > a11 &&
git add a11 &&
test_tick &&
git commit -m 11th &&
git notes copy HEAD^ HEAD &&
git log -1 > actual &&
test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
'
test_expect_success 'prevent overwrite with "git notes copy"' '
test_must_fail git notes copy HEAD~2 HEAD &&
git log -1 > actual &&
test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
'
cat > expect << EOF
commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:23:13 2005 -0700
11th
Notes:
yet another note
$whitespace
yet another note
EOF
test_expect_success 'allow overwrite with "git notes copy -f"' '
git notes copy -f HEAD~2 HEAD &&
git log -1 > actual &&
test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
'
test_expect_success 'cannot copy note from object without notes' '