Skip to content

Commit d58deb9

Browse files
sgngitster
authored andcommitted
notes: fix minimum number of parameters to "copy" subcommand
The builtin/notes.c::copy() function is prepared to handle either one or two arguments given from the command line; when one argument is given, to-obj defaults to HEAD. bbb1b8a ("notes: check number of parameters to "git notes copy"", 2010-06-28) tried to make sure "git notes copy" (with *no* other argument) does not dereference NULL by checking the number of parameters, but it incorrectly insisted that we need two arguments, instead of either one or two. This disabled the defaulting to-obj to HEAD. Correct it. Signed-off-by: Doan Tran Cong Danh <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8af69cf commit d58deb9

File tree

3 files changed

+42
-6
lines changed

3 files changed

+42
-6
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: 38 additions & 2 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)"

0 commit comments

Comments
 (0)