Skip to content

Commit d4a98e7

Browse files
committed
Merge branch 'dd/notes-copy-default-dst-to-head'
"git notes copy $original" ought to copy the notes attached to the original object to HEAD, but a mistaken tightening to command line parameter validation made earlier disabled that feature by mistake. * dd/notes-copy-default-dst-to-head: notes: fix minimum number of parameters to "copy" subcommand t3301: test diagnose messages for too few/many paramters
2 parents 5c8c0a0 + d58deb9 commit d4a98e7

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

Documentation/git-notes.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
[verse]
1111
'git notes' [list [<object>]]
1212
'git notes' add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
13-
'git notes' copy [-f] ( --stdin | <from-object> <to-object> )
13+
'git notes' copy [-f] ( --stdin | <from-object> [<to-object>] )
1414
'git notes' append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
1515
'git notes' edit [--allow-empty] [<object>]
1616
'git notes' show [<object>]
@@ -68,8 +68,8 @@ add::
6868
subcommand).
6969

7070
copy::
71-
Copy the notes for the first object onto the second object.
72-
Abort if the second object already has notes, or if the first
71+
Copy the notes for the first object onto the second object (defaults to
72+
HEAD). Abort if the second object already has notes, or if the first
7373
object has none (use -f to overwrite existing notes to the
7474
second object). This subcommand is equivalent to:
7575
`git notes add [-f] -C $(git notes list <from-object>) <to-object>`

builtin/notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static int copy(int argc, const char **argv, const char *prefix)
513513
}
514514
}
515515

516-
if (argc < 2) {
516+
if (argc < 1) {
517517
error(_("too few parameters"));
518518
usage_with_options(git_notes_copy_usage, options);
519519
}

t/t3301-notes.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,24 @@ test_expect_success 'append to note from other note with "git notes append -c"'
864864
'
865865

866866
test_expect_success 'copy note with "git notes copy"' '
867+
commit=$(git rev-parse 4th) &&
868+
cat >expect <<-EOF &&
869+
commit $commit
870+
Author: A U Thor <[email protected]>
871+
Date: Thu Apr 7 15:16:13 2005 -0700
872+
873+
${indent}4th
874+
875+
Notes:
876+
${indent}This is a blob object
877+
EOF
878+
git notes copy 8th 4th &&
879+
git log 3rd..4th >actual &&
880+
test_cmp expect actual &&
881+
test "$(git note list 4th)" = "$(git note list 8th)"
882+
'
883+
884+
test_expect_success 'copy note with "git notes copy" with default' '
867885
test_commit 11th &&
868886
commit=$(git rev-parse HEAD) &&
869887
cat >expect <<-EOF &&
@@ -878,7 +896,7 @@ test_expect_success 'copy note with "git notes copy"' '
878896
${indent}
879897
${indent}yet another note
880898
EOF
881-
git notes copy HEAD^ HEAD &&
899+
git notes copy HEAD^ &&
882900
git log -1 >actual &&
883901
test_cmp expect actual &&
884902
test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
@@ -892,6 +910,24 @@ test_expect_success 'prevent overwrite with "git notes copy"' '
892910
'
893911

894912
test_expect_success 'allow overwrite with "git notes copy -f"' '
913+
commit=$(git rev-parse HEAD) &&
914+
cat >expect <<-EOF &&
915+
commit $commit
916+
Author: A U Thor <[email protected]>
917+
Date: Thu Apr 7 15:23:13 2005 -0700
918+
919+
${indent}11th
920+
921+
Notes:
922+
${indent}This is a blob object
923+
EOF
924+
git notes copy -f HEAD~3 HEAD &&
925+
git log -1 >actual &&
926+
test_cmp expect actual &&
927+
test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
928+
'
929+
930+
test_expect_success 'allow overwrite with "git notes copy -f" with default' '
895931
commit=$(git rev-parse HEAD) &&
896932
cat >expect <<-EOF &&
897933
commit $commit
@@ -905,7 +941,7 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
905941
${indent}
906942
${indent}yet another note
907943
EOF
908-
git notes copy -f HEAD~2 HEAD &&
944+
git notes copy -f HEAD~2 &&
909945
git log -1 >actual &&
910946
test_cmp expect actual &&
911947
test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
@@ -1167,8 +1203,10 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
11671203
'
11681204

11691205
test_expect_success 'git notes copy diagnoses too many or too few parameters' '
1170-
test_must_fail git notes copy &&
1171-
test_must_fail git notes copy one two three
1206+
test_must_fail git notes copy 2>error &&
1207+
test_i18ngrep "too few parameters" error &&
1208+
test_must_fail git notes copy one two three 2>error &&
1209+
test_i18ngrep "too many parameters" error
11721210
'
11731211

11741212
test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '

0 commit comments

Comments
 (0)