Merge branch 'rr/needs-clean-work-tree'
authorJunio C Hamano <gitster@pobox.com>
Tue, 30 Nov 2010 01:52:32 +0000 (17:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 30 Nov 2010 01:52:32 +0000 (17:52 -0800)
* rr/needs-clean-work-tree:
Porcelain scripts: Rewrite cryptic "needs update" error message

1  2 
git-rebase--interactive.sh
git-rebase.sh
index c2383bfed58f0d28d35b0a657a02b273d06d8b27,4d8a2a0e4e2b6f5f70e75269dde082d13838b5f2..5934b97fa106d73b1b091f050272c4c9f25eb646
@@@ -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=
                *" $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)
  
                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 10a238ae3cc942bc021db18195b7098e2866c266,988b3d8142c80fc58008025b4301c303502ce1a2..0e9d52a5007ed12a23d52a157a7118a50b7693f8
@@@ -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