summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-05-21 04:45:32 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-05-21 18:07:46 (GMT)
commit3a429d0af342d85ef6d561e3a60ae8793a34ae78 (patch)
treeb3571b0a39fa421440f5ff862ef4f8b270fb9bc8 /remote.c
parenta9f9f8cc1f59104257eb1a11a2d048f54dd92ee6 (diff)
downloadgit-3a429d0af342d85ef6d561e3a60ae8793a34ae78.zip
git-3a429d0af342d85ef6d561e3a60ae8793a34ae78.tar.gz
git-3a429d0af342d85ef6d561e3a60ae8793a34ae78.tar.bz2
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 'remote.c')
-rw-r--r--remote.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/remote.c b/remote.c
index dca3442..1b7051a 100644
--- a/remote.c
+++ b/remote.c
@@ -1705,10 +1705,35 @@ int branch_merge_matches(struct branch *branch,
return refname_match(branch->merge[i]->src, refname);
}
-const char *branch_get_upstream(struct branch *branch)
+__attribute((format (printf,2,3)))
+static const char *error_buf(struct strbuf *err, const char *fmt, ...)
{
- if (!branch || !branch->merge || !branch->merge[0])
- return NULL;
+ if (err) {
+ va_list ap;
+ va_start(ap, fmt);
+ strbuf_vaddf(err, fmt, ap);
+ va_end(ap);
+ }
+ return NULL;
+}
+
+const char *branch_get_upstream(struct branch *branch, struct strbuf *err)
+{
+ if (!branch)
+ return error_buf(err, _("HEAD does not point to a branch"));
+ if (!branch->merge || !branch->merge[0] || !branch->merge[0]->dst) {
+ if (!ref_exists(branch->refname))
+ return error_buf(err, _("no such branch: '%s'"),
+ branch->name);
+ if (!branch->merge)
+ return error_buf(err,
+ _("no upstream configured for branch '%s'"),
+ branch->name);
+ return error_buf(err,
+ _("upstream branch '%s' not stored as a remote-tracking branch"),
+ branch->merge[0]->src);
+ }
+
return branch->merge[0]->dst;
}
@@ -1921,7 +1946,7 @@ int stat_tracking_info(struct branch *branch, int *num_ours, int *num_theirs)
int rev_argc;
/* Cannot stat unless we are marked to build on top of somebody else. */
- base = branch_get_upstream(branch);
+ base = branch_get_upstream(branch, NULL);
if (!base)
return 0;