]> git.ipfire.org Git - thirdparty/git.git/blobdiff - remote.c
remote.c: report specific errors from branch_get_upstream
[thirdparty/git.git] / remote.c
index dca3442abacfdc45561df0483f031e7ee7c06259..1b7051a18722700907f969e6c88f355b91f5ec3b 100644 (file)
--- 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;