summaryrefslogtreecommitdiff
path: root/builtin/branch.c
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2013-03-26 12:43:05 -0700
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-03-26 12:43:05 -0700
commit307d68e275d21b7e54d464f1e372b33e9444fef2 (patch)
tree6441c3095c1a86b51fccacd0aad284e8ad3e923a /builtin/branch.c
parentMerge branch 'ap/maint-update-index-h-is-for-help' into maint (diff)
parentbranch: segfault fixes and validation (diff)
downloadtgif-307d68e275d21b7e54d464f1e372b33e9444fef2.tar.xz
Merge branch 'nd/branch-error-cases' into maint
"git branch" had more cases where it did not bother to check nonsense command line parameters. * nd/branch-error-cases: branch: segfault fixes and validation
Diffstat (limited to 'builtin/branch.c')
-rw-r--r--builtin/branch.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index 6371bf96c4..00d17d25d1 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -889,6 +889,17 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
} else if (new_upstream) {
struct branch *branch = branch_get(argv[0]);
+ if (argc > 1)
+ die(_("too many branches to set new upstream"));
+
+ if (!branch) {
+ if (!argc || !strcmp(argv[0], "HEAD"))
+ die(_("could not set upstream of HEAD to %s when "
+ "it does not point to any branch."),
+ new_upstream);
+ die(_("no such branch '%s'"), argv[0]);
+ }
+
if (!ref_exists(branch->refname))
die(_("branch '%s' does not exist"), branch->name);
@@ -901,6 +912,16 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
struct branch *branch = branch_get(argv[0]);
struct strbuf buf = STRBUF_INIT;
+ if (argc > 1)
+ die(_("too many branches to unset upstream"));
+
+ if (!branch) {
+ if (!argc || !strcmp(argv[0], "HEAD"))
+ die(_("could not unset upstream of HEAD when "
+ "it does not point to any branch."));
+ die(_("no such branch '%s'"), argv[0]);
+ }
+
if (!branch_has_merge_config(branch)) {
die(_("Branch '%s' has no upstream information"), branch->name);
}
@@ -916,6 +937,12 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
int branch_existed = 0, remote_tracking = 0;
struct strbuf buf = STRBUF_INIT;
+ if (!strcmp(argv[0], "HEAD"))
+ die(_("it does not make sense to create 'HEAD' manually"));
+
+ if (!branch)
+ die(_("no such branch '%s'"), argv[0]);
+
if (kinds != REF_LOCAL_BRANCH)
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));