git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Confusing git pull error message

From
Jeff King <peff@peff.net>
Date
Oct 5, 2009, 19:35 UTC
Message-ID
<20091005193516.GB20078@coredump.intra.peff.net>
In-Reply-To
<20091005191257.GA24305@coredump.intra.peff.net>
On Mon, Oct 05, 2009 at 03:12:57PM -0400, Jeff King wrote:
> > I think you are right.
> 
> Nope, I'm not. I figured out one more case that it needs to handle.
> Revised patch coming up in a few minutes.

OK, here it is, which I think covers all of the cases. I also re-wrapped the text, as I agree with JSixt that it was pretty ugly. I also re-wrapped some of the existing text, as it gave the very choppy:

  Your configuration specifies to merge the ref
  'foo' from the remote, but no such ref
  was fetched.

It would be really nice to just pipe it through 'fmt', but I suspect that will create portability problems.

-- >8 --
Subject: [PATCH] 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 <peff@peff.net>
---
 git-pull.sh |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/git-pull.sh b/git-pull.sh
index edf3ce3..8b0b6f6 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -90,8 +90,17 @@ error_on_no_merge_candidates () {
 
 	curr_branch=${curr_branch#refs/heads/}
 	upstream=$(git config "branch.$curr_branch.merge")
+	remote=$(git config "branch.$curr_branch.remote")
 
-	if [ -z "$curr_branch" ]; then
+	if [ $# -gt 1 ]; then
+		echo "There are no candidates for merging in the refs that you just fetched."
+		echo "Generally this means that you provided a wildcard refspec which had no"
+		echo "matches on the remote end."
+	elif [ $# -gt 0 ] && [ "$1" != "$remote" ]; then
+		echo "You asked to pull from the remote '$1', but did not specify"
+		echo "a branch to merge. Because this is not the default configured remote"
+		echo "for your current branch, you must specify a branch on the command line."
+	elif [ -z "$curr_branch" ]; then
 		echo "You are not currently on a branch, so I cannot use any"
 		echo "'branch.<branchname>.merge' in your configuration file."
 		echo "Please specify which branch you want to merge on the command"
@@ -116,9 +125,8 @@ error_on_no_merge_candidates () {
 		echo
 		echo "See git-config(1) for details."
 	else
-		echo "Your configuration specifies to merge the ref"
-		echo "'${upstream#refs/heads/}' from the remote, but no such ref"
-		echo "was fetched."
+		echo "Your configuration specifies to merge the ref '${upstream#refs/heads/}' from the"
+		echo "remote, but no such ref was fetched."
 	fi
 	exit 1
 }
-- 
1.6.5.rc2.219.g00ca
Previous: Jeff KingNext: Nanako Shiraishi
Message 23 of 28 in “Confusing git pull error message”
  1. John TapsellSep 12, 2009
  2. Jeff KingSep 12, 2009
  3. John TapsellSep 12, 2009
  4. Jeff KingSep 12, 2009
  5. Sverre RabbelierSep 12, 2009
  6. Jeff KingSep 12, 2009
  7. Sverre RabbelierSep 12, 2009
  8. Junio C HamanoSep 13, 2009
  9. Jeff KingSep 13, 2009
  10. Junio C HamanoSep 13, 2009
  11. Jeff KingSep 13, 2009
  12. Junio C HamanoSep 13, 2009
  13. John TapsellSep 13, 2009
  14. Junio C HamanoSep 13, 2009
  15. Junio C HamanoSep 13, 2009
  16. Jeff KingSep 13, 2009
  17. Jeff KingSep 14, 2009
  18. Johannes SixtOct 5, 2009
  19. Jeff KingOct 5, 2009
  20. Johannes SixtOct 5, 2009
  21. Junio C HamanoOct 5, 2009
  22. Jeff KingOct 5, 2009
  23. Jeff KingOct 5, 2009
  24. Nanako ShiraishiOct 8, 2009
  25. Junio C HamanoOct 9, 2009
  26. Junio C HamanoOct 10, 2009
  27. Junio C HamanoOct 5, 2009
  28. Jeff KingOct 5, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.