[PATCH] git-pull.sh: overhaul error handling when no candidates are found

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* The longish error message displayed when the user uses "git pull" but
  has no remote/merge/rebase lines configured for the current branch
  contains example configuration to remedy the situation... but the
  example uses a rather invalid syntax, using the dotted syntax "git
  config" accepts, but also "=" separators which are used in the config
  file format. It also implies that this syntax is valid in git config
  files. This changes the example to use valid config file syntax.

* When git pull --rebase is used, error_on_no_merge_candidates still
  thinks we're trying to merge, so the resulting message talks about
  merge all the time, and the function looks at the "branch.foo.merge"
  setting rather than the "branch.foo.rebase" setting, and so even tends
  to output the wrong message for the rebase case. This makes both the
  setting verification and the message depend on the mode of operation.

Signed-off-by: Jan Krüger <jk@xxxxx>
---
I tried to pick this apart into several patches but couldn't really
find any decent way of separating the changes. It should address all of
the confusion already identified plus some additional confusion, though.

I'll admit that the dynamification of the messages is a bit crude.

 git-pull.sh |   43 ++++++++++++++++++++++++++-----------------
 1 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/git-pull.sh b/git-pull.sh
index 37f3d93..906c827 100755
--- a/git-pull.sh
+++ b/git-pull.sh
@@ -91,45 +91,54 @@ error_on_no_merge_candidates () {
 		esac
 	done
 
+	if [ true = "$rebase" ]; then
+		op_type=rebase
+		op_prep=against
+	else
+		op_type=merge
+		op_prep=with
+	fi
+
 	curr_branch=${curr_branch#refs/heads/}
-	upstream=$(git config "branch.$curr_branch.merge")
+	upstream=$(git config "branch.$curr_branch.$op_type")
 	remote=$(git config "branch.$curr_branch.remote")
 
 	if [ $# -gt 1 ]; then
-		echo "There are no candidates for merging in the refs that you just fetched."
+		echo "There are no candidates for using 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 "a branch to use. 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"
+		echo "'branch.<branchname>.$op_type' in your configuration file."
+		echo "Please specify which branch you want to use on the command"
 		echo "line and try again (e.g. 'git pull <repository> <refspec>')."
 		echo "See git-pull(1) for details."
 	elif [ -z "$upstream" ]; then
 		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 "want to $op_type $op_prep, and 'branch.${curr_branch}.$op_type' in"
+		echo "your configuration file does not tell me either. Please"
+		echo "specify which branch you want to use 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 "If you often $op_type $op_prep the same branch, you may want to"
+		echo "use something like the following in your configuration 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 "    [branch \"${curr_branch}\"]"
+		echo "    remote = <nickname>"
+		echo "    $op_type = <remote-ref>"
+		echo "    [remote \"<nickname>\"]"
+		echo "    url = <url>"
+		echo "    fetch = <refspec>"
 		echo
 		echo "See git-config(1) for details."
 	else
-		echo "Your configuration specifies to merge the ref '${upstream#refs/heads/}' from the"
-		echo "remote, but no such ref was fetched."
+		echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
+		echo "from the remote, but no such ref was fetched."
 	fi
 	exit 1
 }
-- 
1.6.5.2.156.g89436
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]