Skip to content

Commit 17c8221

Browse files
keszybzgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bb0dab5 commit 17c8221

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

sha1_name.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,12 @@ int interpret_branch_name(const char *name, struct strbuf *buf)
865865
if (!upstream->merge || !upstream->merge[0]->dst) {
866866
if (!ref_exists(upstream->refname))
867867
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);
869874
}
870875
free(cp);
871876
cp = shorten_unambiguous_ref(upstream->merge[0]->dst, 0);

t/t1507-rev-parse-upstream.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ test_expect_success 'branch@{u} works when tracking a local branch' '
125125

126126
test_expect_success 'branch@{u} error message when no upstream' '
127127
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}
129129
fatal: Needed a single revision
130130
EOF
131131
error_message non-tracking@{u} 2>actual &&
@@ -134,7 +134,7 @@ test_expect_success 'branch@{u} error message when no upstream' '
134134

135135
test_expect_success '@{u} error message when no upstream' '
136136
cat >expect <<-EOF &&
137-
error: No upstream branch found for ${sq}master${sq}
137+
error: No upstream configured for branch ${sq}master${sq}
138138
fatal: Needed a single revision
139139
EOF
140140
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' '
162162

163163
test_expect_success 'branch@{u} error message if upstream branch not fetched' '
164164
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
166166
fatal: Needed a single revision
167167
EOF
168168
error_message bad-upstream@{u} 2>actual &&

0 commit comments

Comments
 (0)