git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/1] notes: copy notes to HEAD by default

From
Doan Tran Cong Danh <congdanhqx@gmail.com>
Date
Oct 15, 2019, 16:36 UTC
Message-ID
<20191015163631.21808-2-congdanhqx@gmail.com>
In-Reply-To
<20191015163631.21808-1-congdanhqx@gmail.com>

The target objects for copying notes was defaulted to HEAD from very early stage of git-notes.

However, that default was limited by commit bbb1b8a35a, ("notes: check number of parameters to "git notes copy"", 2010-06-28).

Lift that limitation by adjust the check for numbers of arguments.
Signed-off-by: Doan Tran Cong Danh <congdanhqx@gmail.com>
---
 Documentation/git-notes.txt | 6 +++---
 builtin/notes.c             | 2 +-
 t/t3301-notes.sh            | 4 ++++
 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-notes.txt b/Documentation/git-notes.txt
index f56a5a9197..ced2e8280e 100644
--- a/Documentation/git-notes.txt
+++ b/Documentation/git-notes.txt
@@ -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>`
diff --git a/builtin/notes.c b/builtin/notes.c
index 02e97f55c5..95456f3165 100644
--- a/builtin/notes.c
+++ b/builtin/notes.c
@@ -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);
 	}
diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh
index d3fa298c6a..a8f9a0f36c 100755
--- a/t/t3301-notes.sh
+++ b/t/t3301-notes.sh
@@ -908,6 +908,10 @@ 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)" &&
+	git notes copy -f HEAD~2 &&
+	git log -1 >actual &&
+	test_cmp expect actual &&
 	test "$(git notes list HEAD)" = "$(git notes list HEAD~2)"
 '
 
-- 
2.23.0
Previous: Doan Tran Cong DanhNext: Junio C Hamano
Message 2 of 8 in “Allow default value for target of git-notes copy”
  1. 0/1 Allow default value for target of git-notes copyDoan Tran Cong Danh, Oct 15, 2019
  2. 1/1 notes: copy notes to HEAD by defaultDoan Tran Cong Danh, Oct 15, 2019
  3. Junio C HamanoOct 16, 2019
  4. Danh DoanOct 16, 2019
  5. 1/2 t3301: test diagnose messages for too few/many paramtersDoan Tran Cong Danh, Oct 16, 2019
  6. 2/2 notes: fix minimum number of parameters to "copy" subcommandDoan Tran Cong Danh, Oct 16, 2019
  7. Junio C HamanoOct 18, 2019
  8. Junio C HamanoOct 18, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.