summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-05-21 00:45:32 -0400
committerJunio C Hamano <gitster@pobox.com>2015-05-21 11:07:46 -0700
commit3a429d0af342d85ef6d561e3a60ae8793a34ae78 (patch)
treeb3571b0a39fa421440f5ff862ef4f8b270fb9bc8 /sha1_name.c
parenta9f9f8cc1f59104257eb1a11a2d048f54dd92ee6 (diff)
downloadgit-3a429d0af342d85ef6d561e3a60ae8793a34ae78.tar.gz
remote.c: report specific errors from branch_get_upstream
When the previous commit introduced the branch_get_upstream helper, there was one call-site that could not be converted: the one in sha1_name.c, which gives detailed error messages for each possible failure. Let's teach the helper to optionally report these specific errors. This lets us convert another callsite, and means we can use the helper in other locations that want to give the same error messages. The logic and error messages come straight from sha1_name.c, with the exception that we start each error with a lowercase letter, as is our usual style (note that a few tests need updated as a result). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c25
1 files changed, 7 insertions, 18 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 6d10f052b5..461157a5bc 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1059,27 +1059,16 @@ static const char *get_upstream_branch(const char *branch_buf, int len)
{
char *branch = xstrndup(branch_buf, len);
struct branch *upstream = branch_get(*branch ? branch : NULL);
+ struct strbuf err = STRBUF_INIT;
+ const char *ret;
- /*
- * Upstream can be NULL only if branch refers to HEAD and HEAD
- * points to something different than a branch.
- */
- if (!upstream)
- die(_("HEAD does not point to a branch"));
- if (!upstream->merge || !upstream->merge[0]->dst) {
- if (!ref_exists(upstream->refname))
- die(_("No such branch: '%s'"), branch);
- if (!upstream->merge) {
- die(_("No upstream configured for branch '%s'"),
- upstream->name);
- }
- die(
- _("Upstream branch '%s' not stored as a remote-tracking branch"),
- upstream->merge[0]->src);
- }
free(branch);
- return upstream->merge[0]->dst;
+ ret = branch_get_upstream(upstream, &err);
+ if (!ret)
+ die("%s", err.buf);
+
+ return ret;
}
static int interpret_upstream_mark(const char *name, int namelen,