Be more specific if upstream branch is not tracked

If the branch configured as upstream didn't have a local tracking branch, git said "Upstream branch not found". We can be more helpful, and separate the cases when upstream is not configured, and when it is configured, but the upstream branch is not tracked in a local branch. The following configuration leads to the second scenario: [remote "origin"] url = ... fetch = refs/heads/master [branch "master"] remote = origin merge = refs/heads/master 'git pull' will work on master, but master@{upstream} is not defined. Signed-off-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Zbigniew Jędrzejewski-Szmek committed Apr 14, 2012 at 09:54 UTC 17c82211ec2d29a6e7221948cba8dae9074dc5a6
2 files changed +9 -4
sha1_name.c
+6 -1
@@ -865,7 +865,12 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
865 if (!upstream->merge || !upstream->merge[0]->dst) {
866 if (!ref_exists(upstream->refname))
867 return error("No such branch: '%s'", cp);
868 - return error("No upstream branch found for '%s'", upstream->name);
868 + if (!upstream->merge)
869 + return error("No upstream configured for branch '%s'",
870 + upstream->name);
871 + return error(
872 + "Upstream branch '%s' not stored as a remote-tracking branch",
873 + upstream->merge[0]->src);
874 }
875 free(cp);
876 cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0);
t/t1507-rev-parse-upstream.sh
+3 -3
@@ -125,7 +125,7 @@ test_expect_success 'branch@{u} works when tracking a local branch' '
125
126 test_expect_success 'branch@{u} error message when no upstream' '
127 cat >expect <<-EOF &&
128 - error: No upstream branch found for ${sq}non-tracking${sq}
128 + error: No upstream configured for branch ${sq}non-tracking${sq}
129 fatal: Needed a single revision
130 EOF
131 error_message non-tracking@{u} 2>actual &&
@@ -134,7 +134,7 @@ test_expect_success 'branch@{u} error message when no upstream' '
134
135 test_expect_success '@{u} error message when no upstream' '
136 cat >expect <<-EOF &&
137 - error: No upstream branch found for ${sq}master${sq}
137 + error: No upstream configured for branch ${sq}master${sq}
138 fatal: Needed a single revision
139 EOF
140 test_must_fail git rev-parse --verify @{u} 2>actual &&
@@ -162,7 +162,7 @@ test_expect_success '@{u} error message when not on a branch' '
162
163 test_expect_success 'branch@{u} error message if upstream branch not fetched' '
164 cat >expect <<-EOF &&
165 - error: No upstream branch found for ${sq}bad-upstream${sq}
165 + error: Upstream branch ${sq}refs/heads/side${sq} not stored as a remote-tracking branch
166 fatal: Needed a single revision
167 EOF
168 error_message bad-upstream@{u} 2>actual &&