Skip to content

Commit 92c62a3

Browse files
artagnongitster
authored andcommitted
Porcelain scripts: Rewrite cryptic "needs update" error message
Although Git interally has the facility to differentiate between porcelain and plubmbing commands and appropriately print errors, several shell scripts invoke plubming commands triggering cryptic plumbing errors to be displayed on a porcelain interface. This patch replaces the "needs update" message in git-pull and git-rebase, when `git update-index` is run, with a more friendly message. Reported-by: Joshua Jensen <jjensen@workspacewhiz.com> Reported-by: Thore Husfeldt <thore.husfeldt@gmail.com> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ca20906 commit 92c62a3

4 files changed

Lines changed: 34 additions & 28 deletions

File tree

git-pull.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,7 @@ test true = "$rebase" && {
201201
die "updating an unborn branch with changes added to the index"
202202
fi
203203
else
204-
git update-index --ignore-submodules --refresh &&
205-
git diff-files --ignore-submodules --quiet &&
206-
git diff-index --ignore-submodules --cached --quiet HEAD -- ||
207-
die "refusing to pull with rebase: your working tree is not up-to-date"
204+
require_clean_work_tree "pull with rebase" "Please commit or stash them."
208205
fi
209206
oldremoteref= &&
210207
. git-parse-remote &&

git-rebase--interactive.sh

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,14 +153,6 @@ run_pre_rebase_hook () {
153153
fi
154154
}
155155

156-
require_clean_work_tree () {
157-
# test if working tree is dirty
158-
git rev-parse --verify HEAD > /dev/null &&
159-
git update-index --ignore-submodules --refresh &&
160-
git diff-files --quiet --ignore-submodules &&
161-
git diff-index --cached --quiet HEAD --ignore-submodules -- ||
162-
die "Working tree is dirty"
163-
}
164156

165157
ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
166158

@@ -557,7 +549,7 @@ do_next () {
557549
exit "$status"
558550
fi
559551
# Run in subshell because require_clean_work_tree can die.
560-
if ! (require_clean_work_tree)
552+
if ! (require_clean_work_tree "rebase")
561553
then
562554
warn "Commit or stash your changes, and then run"
563555
warn
@@ -768,7 +760,7 @@ first and then run 'git rebase --continue' again."
768760

769761
record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
770762

771-
require_clean_work_tree
763+
require_clean_work_tree "rebase"
772764
do_rest
773765
;;
774766
--abort)
@@ -866,7 +858,7 @@ first and then run 'git rebase --continue' again."
866858

867859
comment_for_reflog start
868860

869-
require_clean_work_tree
861+
require_clean_work_tree "rebase" "Please commit or stash them."
870862

871863
if test ! -z "$1"
872864
then

git-rebase.sh

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -416,19 +416,7 @@ else
416416
fi
417417
fi
418418

419-
# The tree must be really really clean.
420-
if ! git update-index --ignore-submodules --refresh > /dev/null; then
421-
echo >&2 "cannot rebase: you have unstaged changes"
422-
git diff-files --name-status -r --ignore-submodules -- >&2
423-
exit 1
424-
fi
425-
diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)
426-
case "$diff" in
427-
?*) echo >&2 "cannot rebase: your index contains uncommitted changes"
428-
echo >&2 "$diff"
429-
exit 1
430-
;;
431-
esac
419+
require_clean_work_tree "rebase" "Please commit or stash them."
432420

433421
if test -z "$rebase_root"
434422
then

git-sh-setup.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,35 @@ require_work_tree () {
145145
die "fatal: $0 cannot be used without a working tree."
146146
}
147147
148+
require_clean_work_tree () {
149+
git rev-parse --verify HEAD >/dev/null || exit 1
150+
git update-index -q --ignore-submodules --refresh
151+
err=0
152+
153+
if ! git diff-files --quiet --ignore-submodules
154+
then
155+
echo >&2 "Cannot $1: You have unstaged changes."
156+
err=1
157+
fi
158+
159+
if ! git diff-index --cached --quiet --ignore-submodules HEAD --
160+
then
161+
if [ $err = 0 ]
162+
then
163+
echo >&2 "Cannot $1: Your index contains uncommitted changes."
164+
else
165+
echo >&2 "Additionally, your index contains uncommitted changes."
166+
fi
167+
err=1
168+
fi
169+
170+
if [ $err = 1 ]
171+
then
172+
test -n "$2" && echo >&2 "$2"
173+
exit 1
174+
fi
175+
}
176+
148177
get_author_ident_from_commit () {
149178
pick_author_script='
150179
/^author /{

0 commit comments

Comments
 (0)