Skip to content

Commit 3c02396

Browse files
carlosmngitster
authored andcommitted
Make git-{pull,rebase} message without tracking information friendlier
The current message is too long and at too low a level for anybody to understand it if they don't know about the configuration format already. The text about setting up a remote is superfluous and doesn't help understand or recover from the error that has happened. Show the usage more prominently and explain how to set up the tracking information. If there is only one remote, that name is used instead of the generic <remote>. Also simplify the message we print on detached HEAD to remove unnecessary information which is better left for the documentation. Signed-off-by: Carlos Martín Nieto <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 222433e commit 3c02396

File tree

4 files changed

+24
-29
lines changed

4 files changed

+24
-29
lines changed

git-parse-remote.sh

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,34 +57,31 @@ error_on_missing_default_upstream () {
5757
op_prep="$3"
5858
example="$4"
5959
branch_name=$(git symbolic-ref -q HEAD)
60+
# If there's only one remote, use that in the suggestion
61+
remote="<remote>"
62+
if test $(git remote | wc -l) = 1
63+
then
64+
remote=$(git remote)
65+
fi
66+
6067
if test -z "$branch_name"
6168
then
62-
echo "You are not currently on a branch, so I cannot use any
63-
'branch.<branchname>.merge' in your configuration file.
64-
Please specify which branch you want to $op_type $op_prep on the command
65-
line and try again (e.g. '$example').
66-
See git-${cmd}(1) for details."
69+
echo "You are not currently on a branch. Please specify which
70+
branch you want to $op_type $op_prep. See git-${cmd}(1) for details.
71+
72+
$example
73+
"
6774
else
68-
echo "You asked me to $cmd without telling me which branch you
69-
want to $op_type $op_prep, and 'branch.${branch_name#refs/heads/}.merge' in
70-
your configuration file does not tell me, either. Please
71-
specify which branch you want to use on the command line and
72-
try again (e.g. '$example').
73-
See git-${cmd}(1) for details.
75+
echo "There is no tracking information for the current branch.
76+
Please specify which branch you want to $op_type $op_prep.
77+
See git-${cmd}(1) for details
78+
79+
$example
7480
75-
If you often $op_type $op_prep the same branch, you may want to
76-
use something like the following in your configuration file:
77-
[branch \"${branch_name#refs/heads/}\"]
78-
remote = <nickname>
79-
merge = <remote-ref>"
80-
test rebase = "$op_type" &&
81-
echo " rebase = true"
82-
echo "
83-
[remote \"<nickname>\"]
84-
url = <url>
85-
fetch = <refspec>
81+
If you wish to set tracking information for this branch you can do so with:
8682
87-
See git-config(1) for details."
83+
git branch --set-upstream ${branch_name#refs/heads/} $remote/<branch>
84+
"
8885
fi
8986
exit 1
9087
}

git-pull.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ error_on_no_merge_candidates () {
180180
elif [ -z "$curr_branch" -o -z "$upstream" ]; then
181181
. git-parse-remote
182182
error_on_missing_default_upstream "pull" $op_type $op_prep \
183-
"git pull <repository> <refspec>"
183+
"git pull <remote> <branch>"
184184
else
185185
echo "Your configuration specifies to $op_type $op_prep the ref '${upstream#refs/heads/}'"
186186
echo "from the remote, but no such ref was fetched."

git-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ then
380380
then
381381
. git-parse-remote
382382
error_on_missing_default_upstream "rebase" "rebase" \
383-
"against" "git rebase <upstream branch>"
383+
"against" "git rebase <branch>"
384384
fi
385385
;;
386386
*) upstream_name="$1"

t/t3400-rebase.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,12 @@ rm -f B
160160

161161
test_expect_success 'fail when upstream arg is missing and not on branch' '
162162
git checkout topic &&
163-
test_must_fail git rebase >output.out &&
164-
grep "You are not currently on a branch" output.out
163+
test_must_fail git rebase
165164
'
166165

167166
test_expect_success 'fail when upstream arg is missing and not configured' '
168167
git checkout -b no-config topic &&
169-
test_must_fail git rebase >output.out &&
170-
grep "branch.no-config.merge" output.out
168+
test_must_fail git rebase
171169
'
172170

173171
test_expect_success 'default to @{upstream} when upstream arg is missing' '

0 commit comments

Comments
 (0)