@matheusbsbs / matheus-bagliano / commits / 92c62a3f4f
Fork 0

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>

Ramkumar Ramachandra committed Oct 19, 2010 at 20:09 UTC 92c62a3f4f93432c0c82e3031a9e64e03ba290f7
4 files changed +34 -28
git-pull.sh
+1 -4
@@ -201,10 +201,7 @@ test true = "$rebase" && {
201 die "updating an unborn branch with changes added to the index"
202 fi
203 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."
205 fi
206 oldremoteref= &&
207 . git-parse-remote &&
git-rebase--interactive.sh
+3 -11
@@ -153,14 +153,6 @@ run_pre_rebase_hook () {
153 fi
154 }
155
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 -}
156
157 ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION"
158
@@ -557,7 +549,7 @@ do_next () {
549 exit "$status"
550 fi
551 # Run in subshell because require_clean_work_tree can die.
560 - if ! (require_clean_work_tree)
552 + if ! (require_clean_work_tree "rebase")
553 then
554 warn "Commit or stash your changes, and then run"
555 warn
@@ -768,7 +760,7 @@ first and then run 'git rebase --continue' again."
760
761 record_in_rewritten "$(cat "$DOTEST"/stopped-sha)"
762
771 - require_clean_work_tree
763 + require_clean_work_tree "rebase"
764 do_rest
765 ;;
766 --abort)
@@ -866,7 +858,7 @@ first and then run 'git rebase --continue' again."
858
859 comment_for_reflog start
860
869 - require_clean_work_tree
861 + require_clean_work_tree "rebase" "Please commit or stash them."
862
863 if test ! -z "$1"
864 then
git-rebase.sh
+1 -13
@@ -416,19 +416,7 @@ else
416 fi
417 fi
418
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."
420
421 if test -z "$rebase_root"
422 then
git-sh-setup.sh
+29
@@ -145,6 +145,35 @@ require_work_tree () {
145 die "fatal: $0 cannot be used without a working tree."
146 }
147
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 +
177 get_author_ident_from_commit () {
178 pick_author_script='
179 /^author /{