git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tay Ray Chuan <rctay89@gmail.com>
To: git@vger.kernel.org
Cc: "Stefan Näwe" <stefan.naewe@atlas-elektronik.com>,
	"Junio C. Hamano" <gitster@pobox.com>
Subject: [PATCH] branch -m: handle no arg properly
Date: Wed,  2 Nov 2011 23:01:38 +0800	[thread overview]
Message-ID: <1320246098-6912-1-git-send-email-rctay89@gmail.com> (raw)
In-Reply-To: <4EB153B4.6070404@atlas-elektronik.com>

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.

Reported-by: Stefan Näwe <stefan.naewe@atlas-elektronik.com>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---
 builtin/branch.c  |   13 ++++++++-----
 t/t3200-branch.sh |    4 ++++
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/builtin/branch.c b/builtin/branch.c
index 009b713..ebda8e7 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
+			die(_("new branch not specified for -m|--move"));
+	} 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,
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 2f5eada..78587fe 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -75,6 +75,10 @@ test_expect_success \
         git branch l'
 
 test_expect_success \
+    'git branch -m with no arg fails' \
+       'test_must_fail git branch -m'
+
+test_expect_success \
     'git branch -m m m/m should work' \
        'git branch -l m &&
         git branch -m m m/m &&
-- 
1.7.7.1.599.g03eec

  reply	other threads:[~2011-11-02 15:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-02 14:29 'git -m' dumps core Stefan Näwe
2011-11-02 15:01 ` Tay Ray Chuan [this message]
2011-11-02 15:09   ` [PATCH] branch -m: handle no arg properly Stefan Näwe
2011-11-02 16:17     ` Tay Ray Chuan
2011-11-02 15:07 ` [PATCH] t3200: add test case for 'branch -m' Stefan Naewe
2011-11-02 19:43   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1320246098-6912-1-git-send-email-rctay89@gmail.com \
    --to=rctay89@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=stefan.naewe@atlas-elektronik.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).