summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJohan Herland <johan@herland.net>2010-02-13 22:28:38 +0100
committerJunio C Hamano <gitster@pobox.com>2010-02-13 19:36:17 -0800
commite73bbd96c6e9ce11a101dac03402d0f718a1bd23 (patch)
treeb4922667d15dbc5bca2d4a3b0898cb30b7bdedd5 /t
parent5848769f9de68cfb0735710c6c4d2f08aa53f317 (diff)
downloadgit-e73bbd96c6e9ce11a101dac03402d0f718a1bd23.tar.gz
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>
Diffstat (limited to 't')
-rwxr-xr-xt/t3301-notes.sh63
1 files changed, 63 insertions, 0 deletions
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index 6447e5f54e..90178f96d2 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -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' '
+ : > a12 &&
+ git add a12 &&
+ test_tick &&
+ git commit -m 12th &&
+ : > a13 &&
+ git add a13 &&
+ test_tick &&
+ git commit -m 13th &&
+ test_must_fail git notes copy HEAD^ HEAD
+'
+
test_done