Skip to contentSkip to conversation

'git -m' dumps core

PATCH In review Stefan Näwe 4 participants 6 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw
$ /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

Signature · 3 lines
----------------------------------------------------------------
/dev/random says: If ignorance is bliss, you must be ecstatic.
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"
#1 lore raw

PATCH 1/1 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.

Add a regression test in t3200-branch.sh while we're at it.

---
 builtin/branch.c  |   13 ++++++++-----
 t/t3200-branch.sh |    4 ++++
 2 files changed, 12 insertions(+), 5 deletions(-)
builtin/branch.c +8 -5
index 009b713..ebda8e7 100644
@@ -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,
t/t3200-branch.sh +4 -0
index 2f5eada..78587fe 100755
@@ -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 &&
Signature · 1 line
1.7.7.1.599.g03eec
#2 lore raw

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

Am 02.11.2011 16:01, schrieb Tay Ray Chuan:

Quoted 5 lines

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

Signature · 3 lines
----------------------------------------------------------------
/dev/random says: If At First You Don't Succeed Ignore The Docs...
python -c "print '73746566616e2e6e616577654061746c61732d656c656b74726f6e696b2e636f6d'.decode('hex')"
#3 lore raw

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

Quoted 8 lines · On Wed, 02 Nov 2011 16:09:20 +0100 Stefan Näwe…

Am 02.11.2011 16:01, schrieb Tay Ray Chuan:

Quoted 5 lines

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.

---
 builtin/branch.c |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)
builtin/branch.c +8 -5
index 009b713..51ca6a0 100644
@@ -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,
Signature · 7 lines
1.7.7.1.599.g03eec



--
Cheers,
Ray Chuan
#4 lore raw

PATCH 1/1 t3200: add test case for 'branch -m'

In reply to Stefan Näwe
---
 t/t3200-branch.sh |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)
t/t3200-branch.sh +5 -0
index 2f5eada..3ce31b5 100755
@@ -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 &&
Signature · 1 line
1.7.8.rc0.1.gb345ae