From: Junio C Hamano Date: Mon, 13 Dec 2010 05:49:51 +0000 (-0800) Subject: Merge branch 'mz/rebase-i-verify' X-Git-Tag: v1.7.4-rc0~59 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/cd425a1585bf0c1b92faa772b664dadd3294bf19?ds=inline;hp=-c Merge branch 'mz/rebase-i-verify' * mz/rebase-i-verify: rebase: support --verify --- cd425a1585bf0c1b92faa772b664dadd3294bf19 diff --combined git-rebase--interactive.sh index 5934b97fa1,4eabe54e36..a5ffd9a31e --- a/git-rebase--interactive.sh +++ b/git-rebase--interactive.sh @@@ -28,6 -28,7 +28,7 @@@ continue continue rebasing pr abort abort rebasing process and restore original branch skip skip current patch and continue rebasing process no-verify override pre-rebase hook from stopping the operation + verify allow pre-rebase hook to run root rebase all reachable commmits up to the root(s) autosquash move commits that begin with squash!/fixup! under -i " @@@ -153,6 -154,14 +154,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" @@@ -549,7 -558,7 +550,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 @@@ -667,27 -676,9 +668,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= @@@ -697,26 -688,14 +698,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" @@@ -749,6 -728,7 +750,7 @@@ d OK_TO_SKIP_PRE_REBASE=yes ;; --verify) + OK_TO_SKIP_PRE_REBASE= ;; --continue) is_standalone "$@" || usage @@@ -790,7 -770,7 +792,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) @@@ -888,7 -868,7 +890,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 3459fe4f60,7548f0cae4..d8e1903026 --- a/git-rebase.sh +++ b/git-rebase.sh @@@ -49,8 -49,7 +49,8 @@@ do_merge dotest="$GIT_DIR"/rebase-merge prec=4 verbose= -diffstat=$(git config --bool rebase.stat) +diffstat= +test "$(git config --bool rebase.stat)" = true && diffstat=t git_am_opt= rebase_root= force_rebase= @@@ -206,6 -205,9 +206,9 @@@ d --no-verify) OK_TO_SKIP_PRE_REBASE=yes ;; + --verify) + OK_TO_SKIP_PRE_REBASE= + ;; --continue) test -d "$dotest" -o -d "$GIT_DIR"/rebase-apply || die "No rebase in progress?" @@@ -275,16 -277,15 +278,16 @@@ die "No rebase in progress?" git rerere clear - if test -d "$dotest" - then - GIT_QUIET=$(cat "$dotest/quiet") - move_to_original_branch - else - dotest="$GIT_DIR"/rebase-apply - GIT_QUIET=$(cat "$dotest/quiet") - move_to_original_branch - fi + + test -d "$dotest" || dotest="$GIT_DIR"/rebase-apply + + head_name="$(cat "$dotest"/head-name)" && + case "$head_name" in + refs/*) + git symbolic-ref HEAD $head_name || + die "Could not move back to $head_name" + ;; + esac git reset --hard $(cat "$dotest/orig-head") rm -r "$dotest" exit @@@ -414,7 -415,19 +417,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