Skip to contentSkip to conversation

branch: die explicitly why when calling "git branch [-a|-r] branchname".

PATCH In review Matthieu Moy 2 participants 2 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

---
 builtin-branch.c |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
builtin-branch.c +5 -2
index c87e63b..8aef2bb 100644
@@ -638,10 +638,13 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		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 (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,
 			      force_create, reflog, track);
-	else
+	} else
 		usage_with_options(builtin_branch_usage, options);
 
 	return 0;
Signature · 1 line
1.6.6.71.gcc720.dirty
#1 lore raw

Thanks; will apply to 'maint', together with the SubmittingPatches addition.

Interestingly, this revealed a long-standing breakage in t5403.