]> git.ipfire.org Git - thirdparty/git.git/blobdiff - remote.c
remote.c: untangle error logic in branch_get_upstream
[thirdparty/git.git] / remote.c
index 1b7051a18722700907f969e6c88f355b91f5ec3b..d2519c22ce85921ae5c231b099ac0735bb09814e 100644 (file)
--- a/remote.c
+++ b/remote.c
@@ -1721,18 +1721,25 @@ 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 (!branch->merge || !branch->merge[0]) {
+               /*
+                * no merge config; is it because the user didn't define any,
+                * or because it is not a real branch, and get_branch
+                * auto-vivified it?
+                */
                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,
+                                _("no upstream configured for branch '%s'"),
+                                branch->name);
+       }
+
+       if (!branch->merge[0]->dst)
                return error_buf(err,
                                 _("upstream branch '%s' not stored as a remote-tracking branch"),
                                 branch->merge[0]->src);
-       }
 
        return branch->merge[0]->dst;
 }