]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'dd/notes-copy-default-dst-to-head'
authorJunio C Hamano <gitster@pobox.com>
Sun, 10 Nov 2019 09:02:12 +0000 (18:02 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sun, 10 Nov 2019 09:02:12 +0000 (18:02 +0900)
"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

Documentation/git-notes.txt
builtin/notes.c
t/t3301-notes.sh

index f56a5a91975d592b19d03edafef943519718c588..ced2e8280ef5e4c4c930fd1abdab83834c293140 100644 (file)
@@ -10,7 +10,7 @@ SYNOPSIS
 [verse]
 'git notes' [list [<object>]]
 'git notes' add [-f] [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
-'git notes' copy [-f] ( --stdin | <from-object> <to-object> )
+'git notes' copy [-f] ( --stdin | <from-object> [<to-object>] )
 'git notes' append [--allow-empty] [-F <file> | -m <msg> | (-c | -C) <object>] [<object>]
 'git notes' edit [--allow-empty] [<object>]
 'git notes' show [<object>]
@@ -68,8 +68,8 @@ add::
        subcommand).
 
 copy::
-       Copy the notes for the first object onto the second object.
-       Abort if the second object already has notes, or if the first
+       Copy the notes for the first object onto the second object (defaults to
+       HEAD). Abort if the second object already has notes, or if the first
        object has none (use -f to overwrite existing notes to the
        second object). This subcommand is equivalent to:
        `git notes add [-f] -C $(git notes list <from-object>) <to-object>`
index 02e97f55c5a01be452bb3eaa97ec396f58e2ed99..95456f316549c9a5890a4539446c643640429eb0 100644 (file)
@@ -513,7 +513,7 @@ static int copy(int argc, const char **argv, const char *prefix)
                }
        }
 
-       if (argc < 2) {
+       if (argc < 1) {
                error(_("too few parameters"));
                usage_with_options(git_notes_copy_usage, options);
        }
index d3fa298c6a1b382a2c6818495a401753a7dd4375..d66a5f6faa0ae8c4aecde52decde951d07080615 100755 (executable)
@@ -864,6 +864,24 @@ test_expect_success 'append to note from other note with "git notes append -c"'
 '
 
 test_expect_success 'copy note with "git notes copy"' '
+       commit=$(git rev-parse 4th) &&
+       cat >expect <<-EOF &&
+               commit $commit
+               Author: A U Thor <author@example.com>
+               Date:   Thu Apr 7 15:16:13 2005 -0700
+
+               ${indent}4th
+
+               Notes:
+               ${indent}This is a blob object
+       EOF
+       git notes copy 8th 4th &&
+       git log 3rd..4th >actual &&
+       test_cmp expect actual &&
+       test "$(git note list 4th)" = "$(git note list 8th)"
+'
+
+test_expect_success 'copy note with "git notes copy" with default' '
        test_commit 11th &&
        commit=$(git rev-parse HEAD) &&
        cat >expect <<-EOF &&
@@ -878,7 +896,7 @@ test_expect_success 'copy note with "git notes copy"' '
                ${indent}
                ${indent}yet another note
        EOF
-       git notes copy HEAD^ HEAD &&
+       git notes copy HEAD^ &&
        git log -1 >actual &&
        test_cmp expect actual &&
        test "$(git notes list HEAD)" = "$(git notes list HEAD^)"
@@ -892,6 +910,24 @@ test_expect_success 'prevent overwrite with "git notes copy"' '
 '
 
 test_expect_success 'allow overwrite with "git notes copy -f"' '
+       commit=$(git rev-parse HEAD) &&
+       cat >expect <<-EOF &&
+               commit $commit
+               Author: A U Thor <author@example.com>
+               Date:   Thu Apr 7 15:23:13 2005 -0700
+
+               ${indent}11th
+
+               Notes:
+               ${indent}This is a blob object
+       EOF
+       git notes copy -f HEAD~3 HEAD &&
+       git log -1 >actual &&
+       test_cmp expect actual &&
+       test "$(git notes list HEAD)" = "$(git notes list HEAD~3)"
+'
+
+test_expect_success 'allow overwrite with "git notes copy -f" with default' '
        commit=$(git rev-parse HEAD) &&
        cat >expect <<-EOF &&
                commit $commit
@@ -905,7 +941,7 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
                ${indent}
                ${indent}yet another note
        EOF
-       git notes copy -f HEAD~2 HEAD &&
+       git notes copy -f HEAD~2 &&
        git log -1 >actual &&
        test_cmp expect actual &&
        test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
@@ -1167,8 +1203,10 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
 '
 
 test_expect_success 'git notes copy diagnoses too many or too few parameters' '
-       test_must_fail git notes copy &&
-       test_must_fail git notes copy one two three
+       test_must_fail git notes copy 2>error &&
+       test_i18ngrep "too few parameters" error &&
+       test_must_fail git notes copy one two three 2>error &&
+       test_i18ngrep "too many parameters" error
 '
 
 test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '