Skip to content

Commit a8c9bef

Browse files
peffgitster
authored andcommitted
pull: improve advice for unconfigured error case
There are several reasons a git-pull invocation might not have anything marked for merge: 1. We're not on a branch, so there is no branch configuration. 2. We're on a branch, but there is no configuration for this branch. 3. We fetched from the configured remote, but the configured branch to merge didn't get fetched (either it doesn't exist, or wasn't part of the fetch refspec). 4. We fetched from the non-default remote, but didn't specify a branch to merge. We can't use the configured one because it applies to the default remote. 5. We fetched from a specified remote, and a refspec was given, but it ended up not fetching anything (this is actually hard to do; if the refspec points to a remote branch and it doesn't exist, then fetch will fail and we never make it to this code path. But if you provide a wildcard refspec like refs/bogus/*:refs/remotes/origin/* then you can see this failure). We have handled (1) and (2) for some time. Recently, commit a6dbf88 added code to handle case (3). This patch handles cases (4) and (5), which previously just fell under other cases, producing a confusing message. While we're at it, let's rewrap the text for case (3), which looks terribly ugly as it is. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 63d129d commit a8c9bef

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

git-pull.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,17 @@ error_on_no_merge_candidates () {
9090

9191
curr_branch=${curr_branch#refs/heads/}
9292
upstream=$(git config "branch.$curr_branch.merge")
93+
remote=$(git config "branch.$curr_branch.remote")
9394

94-
if [ -z "$curr_branch" ]; then
95+
if [ $# -gt 1 ]; then
96+
echo "There are no candidates for merging in the refs that you just fetched."
97+
echo "Generally this means that you provided a wildcard refspec which had no"
98+
echo "matches on the remote end."
99+
elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
100+
echo "You asked to pull from the remote '$1', but did not specify"
101+
echo "a branch to merge. Because this is not the default configured remote"
102+
echo "for your current branch, you must specify a branch on the command line."
103+
elif [ -z "$curr_branch" ]; then
95104
echo "You are not currently on a branch, so I cannot use any"
96105
echo "'branch.<branchname>.merge' in your configuration file."
97106
echo "Please specify which branch you want to merge on the command"
@@ -116,9 +125,8 @@ error_on_no_merge_candidates () {
116125
echo
117126
echo "See git-config(1) for details."
118127
else
119-
echo "Your configuration specifies to merge the ref"
120-
echo "'${upstream#refs/heads/}' from the remote, but no such ref"
121-
echo "was fetched."
128+
echo "Your configuration specifies to merge the ref '${upstream#refs/heads/}' from the"
129+
echo "remote, but no such ref was fetched."
122130
fi
123131
exit 1
124132
}

0 commit comments

Comments
 (0)