Skip to content

Commit 6e8f993

Browse files
moygitster
authored andcommitted
branch: die explicitly why when calling "git branch [-a|-r] branchname".
The -a and -r options used to be silently ignored in such a command. Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e97ca7f commit 6e8f993

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

builtin-branch.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
582582
rename_branch(head, argv[0], rename > 1);
583583
else if (rename && (argc == 2))
584584
rename_branch(argv[0], argv[1], rename > 1);
585-
else if (argc <= 2)
585+
else if (argc <= 2) {
586+
if (kinds != REF_LOCAL_BRANCH)
587+
die("-a and -r options to 'git branch' do not make sense with a branch name");
586588
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
587589
force_create, reflog, track);
588-
else
590+
} else
589591
usage_with_options(builtin_branch_usage, options);
590592

591593
return 0;

t/t5403-post-checkout-hook.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ test_description='Test the post-checkout hook.'
77
. ./test-lib.sh
88

99
test_expect_success setup '
10-
echo Data for commit0. >a &&
11-
echo Data for commit0. >b &&
12-
git update-index --add a &&
13-
git update-index --add b &&
14-
tree0=$(git write-tree) &&
15-
commit0=$(echo setup | git commit-tree $tree0) &&
16-
git update-ref refs/heads/master $commit0 &&
17-
git clone ./. clone1 &&
18-
git clone ./. clone2 &&
19-
GIT_DIR=clone2/.git git branch -a new2 &&
20-
echo Data for commit1. >clone2/b &&
21-
GIT_DIR=clone2/.git git add clone2/b &&
22-
GIT_DIR=clone2/.git git commit -m new2
10+
echo Data for commit0. >a &&
11+
echo Data for commit0. >b &&
12+
git update-index --add a &&
13+
git update-index --add b &&
14+
tree0=$(git write-tree) &&
15+
commit0=$(echo setup | git commit-tree $tree0) &&
16+
git update-ref refs/heads/master $commit0 &&
17+
git clone ./. clone1 &&
18+
git clone ./. clone2 &&
19+
GIT_DIR=clone2/.git git branch new2 &&
20+
echo Data for commit1. >clone2/b &&
21+
GIT_DIR=clone2/.git git add clone2/b &&
22+
GIT_DIR=clone2/.git git commit -m new2
2323
'
2424

2525
for clone in 1 2; do

0 commit comments

Comments
 (0)