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

Re: [PATCH] branch -m: handle no arg properly

From
Tay Ray Chuan <rctay89@gmail.com>
Date
Nov 2, 2011, 16:17 UTC
Message-ID
<20111103001712.000024b9@unknown>
In-Reply-To
<4EB15D20.1060107@atlas-elektronik.com>

On Wed, 02 Nov 2011 16:09:20 +0100 Stefan Näwe <stefan.naewe@atlas-elektronik.com> wrote:

Show 8 quoted lines
> Am 02.11.2011 16:01, schrieb Tay Ray Chuan:
> > Modify the option parsing heuristic to handle all -m (rename) cases,
> > including the no-arg case. Previously, this "fell through" to the argc
> > <= 2 case.
> > 
> > Add a regression test in t3200-branch.sh while we're at it.
> 
> Great. I just sent a patch for t3200 as well...
Hmm, yeah, printing usage is a good idea.
Popped my change to t3200 as well, yours looks better. :)
-->8--
Subject: [PATCH] branch -m: handle no arg properly

Modify the option parsing heuristic to handle all -m (rename) cases, including the no-arg case. Previously, this "fell through" to the argc <= 2 case.

Reported-by: Stefan Näwe <stefan.naewe@atlas-elektronik.com>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 builtin/branch.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 009b713..51ca6a0 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -719,11 +719,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 	else if (list)
 		return print_ref_list(kinds, detached, verbose, abbrev,
 				      with_commit, argv);
-	else if (rename && (argc == 1))
-		rename_branch(head, argv[0], rename > 1);
-	else if (rename && (argc == 2))
-		rename_branch(argv[0], argv[1], rename > 1);
-	else if (argc <= 2) {
+	else if (rename) {
+		if (argc == 1)
+			rename_branch(head, argv[0], rename > 1);
+		else if (argc == 2)
+			rename_branch(argv[0], argv[1], rename > 1);
+		else
+			usage_with_options(builtin_branch_usage, options);
+	} else if (argc <= 2) {
 		if (kinds != REF_LOCAL_BRANCH)
 			die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
 		create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
-- 
1.7.7.1.599.g03eec



--
Cheers,
Ray Chuan
Previous: Stefan NäweNext: Stefan Naewe
Message 4 of 6 in “'git -m' dumps core”
  1. Stefan NäweNov 2, 2011
  2. branch -m: handle no arg properlyTay Ray Chuan, Nov 2, 2011
  3. Stefan NäweNov 2, 2011
  4. Tay Ray ChuanNov 2, 2011
  5. t3200: add test case for 'branch -m'Stefan Naewe, Nov 2, 2011
  6. Junio C HamanoNov 2, 2011

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.