From: Junio C Hamano Date: Tue, 30 Nov 2010 01:52:32 +0000 (-0800) Subject: Merge branch 'rr/needs-clean-work-tree' X-Git-Tag: v1.7.4-rc0~111 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/e4663556cfa0d85e7a80d731b07d4058335761ff?hp=-c Merge branch 'rr/needs-clean-work-tree' * rr/needs-clean-work-tree: Porcelain scripts: Rewrite cryptic "needs update" error message --- e4663556cfa0d85e7a80d731b07d4058335761ff diff --combined git-rebase--interactive.sh index c2383bfed5,4d8a2a0e4e..5934b97fa1 --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@@ -153,14 -153,6 +153,6 @@@ run_pre_rebase_hook () fi } - require_clean_work_tree () { - # test if working tree is dirty - git rev-parse --verify HEAD > /dev/null && - git update-index --ignore-submodules --refresh && - git diff-files --quiet --ignore-submodules && - git diff-index --cached --quiet HEAD --ignore-submodules -- || - die "Working tree is dirty" - } ORIG_REFLOG_ACTION="$GIT_REFLOG_ACTION" @@@ -557,7 -549,7 +549,7 @@@ do_next () exit "$status" fi # Run in subshell because require_clean_work_tree can die. - if ! (require_clean_work_tree) + if ! (require_clean_work_tree "rebase") then warn "Commit or stash your changes, and then run" warn @@@ -675,27 -667,9 +667,27 @@@ get_saved_options () # comes immediately after the former, and change "pick" to # "fixup"/"squash". rearrange_squash () { - sed -n -e 's/^pick \([0-9a-f]*\) \(squash\)! /\1 \2 /p' \ - -e 's/^pick \([0-9a-f]*\) \(fixup\)! /\1 \2 /p' \ - "$1" >"$1.sq" + # extract fixup!/squash! lines and resolve any referenced sha1's + while read -r pick sha1 message + do + case "$message" in + "squash! "*|"fixup! "*) + action="${message%%!*}" + rest="${message#*! }" + echo "$sha1 $action $rest" + # if it's a single word, try to resolve to a full sha1 and + # emit a second copy. This allows us to match on both message + # and on sha1 prefix + if test "${rest#* }" = "$rest"; then + fullsha="$(git rev-parse -q --verify "$rest" 2>/dev/null)" + if test -n "$fullsha"; then + # prefix the action to uniquely identify this line as + # intended for full sha1 match + echo "$sha1 +$action $fullsha" + fi + fi + esac + done >"$1.sq" <"$1" test -s "$1.sq" || return used= @@@ -705,26 -679,14 +697,26 @@@ *" $sha1 "*) continue ;; esac printf '%s\n' "$pick $sha1 $message" + used="$used$sha1 " while read -r squash action msg do - case "$message" in - "$msg"*) + case " $used" in + *" $squash "*) continue ;; + esac + emit=0 + case "$action" in + +*) + action="${action#+}" + # full sha1 prefix test + case "$msg" in "$sha1"*) emit=1;; esac ;; + *) + # message prefix test + case "$message" in "$msg"*) emit=1;; esac ;; + esac + if test $emit = 1; then printf '%s\n' "$action $squash $action! $msg" used="$used$squash " - ;; - esac + fi done <"$1.sq" done >"$1.rearranged" <"$1" cat "$1.rearranged" >"$1" @@@ -798,7 -760,7 +790,7 @@@ first and then run 'git rebase --contin record_in_rewritten "$(cat "$DOTEST"/stopped-sha)" - require_clean_work_tree + require_clean_work_tree "rebase" do_rest ;; --abort) @@@ -896,7 -858,7 +888,7 @@@ comment_for_reflog start - require_clean_work_tree + require_clean_work_tree "rebase" "Please commit or stash them." if test ! -z "$1" then diff --combined git-rebase.sh index 10a238ae3c,988b3d8142..0e9d52a500 --- a/git-rebase.sh +++ b/git-rebase.sh @@@ -311,6 -311,10 +311,6 @@@ d esac strategy_opts="$strategy_opts $(git rev-parse --sq-quote "--$newopt")" do_merge=t - if test -n "$strategy" - then - strategy=recursive - fi ;; -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\ --strateg=*|--strategy=*|\ @@@ -412,19 -416,7 +412,7 @@@ els fi fi - # The tree must be really really clean. - if ! git update-index --ignore-submodules --refresh > /dev/null; then - echo >&2 "cannot rebase: you have unstaged changes" - git diff-files --name-status -r --ignore-submodules -- >&2 - exit 1 - fi - diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --) - case "$diff" in - ?*) echo >&2 "cannot rebase: your index contains uncommitted changes" - echo >&2 "$diff" - exit 1 - ;; - esac + require_clean_work_tree "rebase" "Please commit or stash them." if test -z "$rebase_root" then