# 'git -m' dumps core

6 messages from 2011-11-02 to 2011-11-02. Participants: Stefan Näwe, Tay Ray Chuan, Stefan Naewe, Junio C Hamano.
Thread: https://gitlist.dev/t/28823

## Stefan Näwe, 2011-11-02 14:29

Subject: 'git -m' dumps core
Message-ID: <4EB153B4.6070404@atlas-elektronik.com>
URL: https://gitlist.dev/e/4EB153B4.6070404%40atlas-elektronik.com

```
$ /usr/local/git-v1.7.8-rc0/bin/git version
git version 1.7.8.rc0

$ /usr/local/git-v1.7.8-rc0/bin/git branch -m
Speicherzugriffsfehler (core dumped)

$ /usr/local/git-v1.7.8-rc0/bin/git branch --move
Speicherzugriffsfehler (core dumped)

GDB says:

(gdb) bt
#0  0xb74694f3 in strlen () from /lib/i686/cmov/libc.so.6
#1  0x0810f1ad in strbuf_branchname (sb=0xbfb20bbc, name=0x0) at sha1_name.c:873
#2  0x0810f20e in strbuf_check_branch_ref (sb=0xbfb20bbc, name=0x0) at sha1_name.c:882
#3  0x080b516a in validate_new_branchname (name=0x0, ref=0xbfb20bbc, force=0, attr_only=0) at branch.c:142
#4  0x080b550c in create_branch (head=0x94e32ab "master", name=0x0, start_name=0x94e32ab "master", force=0, reflog=0, track=BRANCH_TRACK_REMOTE)
    at branch.c:177
#5  0x0805a8fe in cmd_branch (argc=0, argv=0xbfb215f8, prefix=0x0) at builtin/branch.c:729
#6  0x0804ba29 in handle_internal_command (argc=2, argv=0xbfb215f8) at git.c:308
#7  0x0804bc67 in main (argc=2, argv=0xbfb215f8) at git.c:512


Stefan
-- 
----------------------------------------------------------------
/dev/random says: If ignorance is bliss, you must be ecstatic.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"

```

## Tay Ray Chuan, 2011-11-02 15:01

Subject: [PATCH] branch -m: handle no arg properly
Message-ID: <1320246098-6912-1-git-send-email-rctay89@gmail.com>
URL: https://gitlist.dev/e/1320246098-6912-1-git-send-email-rctay89%40gmail.com
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

```

## Stefan Naewe, 2011-11-02 15:07

Subject: [PATCH] t3200: add test case for 'branch -m'
Message-ID: <1320246425-2141-1-git-send-email-stefan.naewe@gmail.com>
URL: https://gitlist.dev/e/1320246425-2141-1-git-send-email-stefan.naewe%40gmail.com
In-Reply-To: <4EB153B4.6070404@atlas-elektronik.com>

```
Signed-off-by: Stefan Naewe <stefan.naewe@gmail.com>
---
 t/t3200-branch.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 2f5eada..3ce31b5 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -75,6 +75,11 @@ test_expect_success \
         git branch l'
 
 test_expect_success \
+    'git branch -m dumps usage' \
+       'test_expect_code 129 git branch -m 2>err &&
+        grep "[Uu]sage: git branch" err'
+
+test_expect_success \
     'git branch -m m m/m should work' \
        'git branch -l m &&
         git branch -m m m/m &&
-- 
1.7.8.rc0.1.gb345ae

```

## Stefan Näwe, 2011-11-02 15:09

Subject: Re: [PATCH] branch -m: handle no arg properly
Message-ID: <4EB15D20.1060107@atlas-elektronik.com>
URL: https://gitlist.dev/e/4EB15D20.1060107%40atlas-elektronik.com
In-Reply-To: <1320246098-6912-1-git-send-email-rctay89@gmail.com>

```
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...

Stefan
-- 
----------------------------------------------------------------
/dev/random says: If At First You Don't Succeed Ignore The Docs...
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"

```

## Tay Ray Chuan, 2011-11-02 16:17

Subject: Re: [PATCH] branch -m: handle no arg properly
Message-ID: <20111103001712.000024b9@unknown>
URL: https://gitlist.dev/e/20111103001712.000024b9%40unknown
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:

> 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

```

## Junio C Hamano, 2011-11-02 19:43

Subject: Re: [PATCH] t3200: add test case for 'branch -m'
Message-ID: <7vpqhaia3m.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpqhaia3m.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1320246425-2141-1-git-send-email-stefan.naewe@gmail.com>

```
Thanks, both.

```
