public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox•com>
To: Jeff King <peff@peff•net>
Cc: John Tapsell <johnflux@gmail•com>, Git List <git@vger•kernel.org>
Subject: Re: Confusing git pull error message
Date: Sun, 13 Sep 2009 14:16:39 -0700	[thread overview]
Message-ID: <7v7hw2pmtk.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <20090913204231.GA8654@coredump.intra.peff.net> (Jeff King's message of "Sun\, 13 Sep 2009 16\:42\:31 -0400")

Jeff King <peff@peff•net> writes:

> On Sun, Sep 13, 2009 at 01:38:48PM -0700, Junio C Hamano wrote:
>
>> I saw some discussion on improving the wording.  Here is what I plan to
>> commit.
>
> Thanks for picking this up, I meant to re-post with improvements.

I am _not_ going to commit the following patch, because it will interfere
with this clarification effort, but I think we want to do something along
this line after the "clarification" settles.

An observation I'd like to make is that this is way too ugly:

	[advice]
        	pullNoMergeFound = false
                pushNonFastForward = false
                statusHints = false

than

	[IKnowWhatIAmDoingThankYouVeryMuch]
        	pullNoMergeFound
                pushNonFastForward
                statusHints

but this feature is for people who know what they are doing, so I guess
the current set-up would be fine.

 git-pull.sh |   78 ++++++++++++++++++++++++++++++++++++++++------------------
 1 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/git-pull.sh b/git-pull.sh
index 0bbd5bf..101545e 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -76,14 +76,64 @@ do
 	shift
 done
 
+advice_tags_only () {
+	if test -z "$1"
+	then
+		echo "Fetching tags only."
+		return
+	fi
+	echo "Fetching tags only, you probably meant:"
+	echo "  git fetch --tags"
+}
+
+advice_detached_head () {
+	if test -z "$1"
+	then
+		echo "No default merge candidate on a detached HEAD."
+		return
+	fi
+	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"
+	echo "line and try again (e.g. 'git pull <repository> <refspec>')."
+	echo "See git-pull(1) for details."
+}
+
+advice_no_merge_candidates () {
+	if test -z "$1"
+	then
+		echo "No merge candidate for the current branch fetched."
+		return
+	fi
+	cat <<EOF
+You asked me to pull without telling me which branch you
+want to merge with, and 'branch.$2.merge' in
+your configuration file does not tell me either.  Please
+specify which branch you want to merge on the command line and
+try again (e.g. 'git pull <repository> <refspec>').
+See git-pull(1) for details.
+
+If you often merge with the same branch, you may want to
+configure the following variables in your configuration
+file:
+
+    branch.$2.remote = <nickname>
+    branch.$2.merge = <remote-ref>
+    remote.<nickname>.url = <url>"
+    remote.<nickname>.fetch = <refspec>
+
+See git-config(1) for details.
+EOF
+}
+
 error_on_no_merge_candidates () {
 	exec >&2
+	advice=$(git config --bool advice.pullNoMergeFound)
 	for opt
 	do
 		case "$opt" in
 		-t|--t|--ta|--tag|--tags)
-			echo "Fetching tags only, you probably meant:"
-			echo "  git fetch --tags"
+			advice_tags_only "$advice"
 			exit 1
 		esac
 	done
@@ -91,29 +141,9 @@ error_on_no_merge_candidates () {
 	curr_branch=${curr_branch#refs/heads/}
 
 	if [ -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"
-		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
+		advice_detached_head "$advice"
 	else
-		echo "You asked me to pull without telling me which branch you"
-		echo "want to merge with, and 'branch.${curr_branch}.merge' in"
-		echo "your configuration file does not tell me either.	Please"
-		echo "specify which branch you want to merge on the command line and"
-		echo "try again (e.g. 'git pull <repository> <refspec>')."
-		echo "See git-pull(1) for details."
-		echo
-		echo "If you often merge with the same branch, you may want to"
-		echo "configure the following variables in your configuration"
-		echo "file:"
-		echo
-		echo "    branch.${curr_branch}.remote = <nickname>"
-		echo "    branch.${curr_branch}.merge = <remote-ref>"
-		echo "    remote.<nickname>.url = <url>"
-		echo "    remote.<nickname>.fetch = <refspec>"
-		echo
-		echo "See git-config(1) for details."
+		advice_no_merge_candidate "$advice" "$curr_branch"
 	fi
 	exit 1
 }

  parent reply	other threads:[~2009-09-13 21:16 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-12 20:01 Confusing git pull error message John Tapsell
2009-09-12 21:11 ` Jeff King
2009-09-12 21:31   ` John Tapsell
2009-09-12 22:34     ` Jeff King
2009-09-12 21:37   ` Sverre Rabbelier
2009-09-12 22:31     ` Jeff King
2009-09-12 22:37       ` Sverre Rabbelier
2009-09-13 20:38   ` Junio C Hamano
2009-09-13 20:42     ` Jeff King
2009-09-13 20:57       ` Junio C Hamano
2009-09-13 21:36         ` Jeff King
2009-09-13 22:11           ` Junio C Hamano
2009-09-13 20:57       ` John Tapsell
2009-09-13 21:18         ` Junio C Hamano
2009-09-13 21:16       ` Junio C Hamano [this message]
2009-09-13 22:39         ` Jeff King
2009-09-14 11:14     ` Jeff King
2009-10-05 11:32     ` Johannes Sixt
2009-10-05 11:53       ` Jeff King
2009-10-05 12:13         ` Johannes Sixt
2009-10-05 19:08         ` Junio C Hamano
2009-10-05 19:12           ` Jeff King
2009-10-05 19:35             ` Jeff King
2009-10-08 22:01               ` Nanako Shiraishi
2009-10-09  7:38                 ` Junio C Hamano
2009-10-10  0:57                   ` Junio C Hamano
2009-10-05 19:36             ` Junio C Hamano
2009-10-05 22:00               ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7v7hw2pmtk.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=johnflux@gmail$(echo .)com \
    --cc=peff@peff$(echo .)net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox