git-tar-tree: no more void pointer arithmetic
[git.git] / git-revert.sh
index 722c4f7..de8b5f0 100755 (executable)
@@ -3,27 +3,20 @@
 # Copyright (c) 2005 Linus Torvalds
 # Copyright (c) 2005 Junio C Hamano
 #
-. git-sh-setup || die "Not a git archive"
 
 case "$0" in
 *-revert* )
-       me=revert ;;
+       test -t 0 && edit=-e
+       me=revert
+       USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
 *-cherry-pick* )
-       me=cherry-pick ;;
+       edit=
+       me=cherry-pick
+       USAGE='[--edit] [-n] [-r] <commit-ish>'  ;;
 * )
-       die "What are ou talking about?" ;;
+       die "What are you talking about?" ;;
 esac
-
-usage () {
-       case "$me" in
-       cherry-pick)
-               die "usage git $me [-n] [-r] <commit-ish>"
-               ;;
-       revert)
-               die "usage git $me [-n] <commit-ish>"
-               ;;
-       esac
-}
+. git-sh-setup
 
 no_commit= replay=
 while case "$#" in 0) break ;; esac
@@ -33,6 +26,12 @@ do
            --no-commi|--no-commit)
                no_commit=t
                ;;
+       -e|--e|--ed|--edi|--edit)
+               edit=-e
+               ;;
+       --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
+               edit=
+               ;;
        -r|--r|--re|--rep|--repl|--repla|--replay)
                replay=t
                ;;
@@ -56,9 +55,12 @@ t)
                die "Your index file is unmerged."
        ;;
 *)
-       check_clean_tree || die "Cannot run $me from a dirty tree."
        head=$(git-rev-parse --verify HEAD) ||
                die "You do not have a valid HEAD"
+       files=$(git-diff-index --cached --name-only $head) || exit
+       if [ "$files" ]; then
+               die "Dirty index: cannot $me (dirty: $files)"
+       fi
        ;;
 esac
 
@@ -91,6 +93,7 @@ revert)
 cherry-pick)
        pick_author_script='
        /^author /{
+               s/'\''/'\''\\'\'\''/g
                h
                s/^author \([^<]*\) <[^>]*> .*$/\1/
                s/'\''/'\''\'\'\''/g
@@ -109,7 +112,7 @@ cherry-pick)
                q
        }'
        set_author_env=`git-cat-file commit "$commit" |
-       sed -ne "$pick_author_script"`
+       LANG=C LC_ALL=C sed -ne "$pick_author_script"`
        eval "$set_author_env"
        export GIT_AUTHOR_NAME
        export GIT_AUTHOR_EMAIL
@@ -134,12 +137,13 @@ esac >.msg
 # $prev and $commit on top of us (when cherry-picking or replaying).
 
 echo >&2 "First trying simple merge strategy to $me."
-git-read-tree -m -u $base $head $next &&
+git-read-tree -m -u --aggressive $base $head $next &&
 result=$(git-write-tree 2>/dev/null) || {
     echo >&2 "Simple $me fails; trying Automatic $me."
     git-merge-index -o git-merge-one-file -a || {
-           echo >&2 "Automatic $me failed.  After fixing it up,"
-           echo >&2 "you can use \"git commit -F .msg\""
+           echo >&2 "Automatic $me failed.  After resolving the conflicts,"
+           echo >&2 "mark the corrected paths with 'git-update-index <paths>'"
+           echo >&2 "and commit with 'git commit -F .msg'"
            case "$me" in
            cherry-pick)
                echo >&2 "You may choose to use the following when making"
@@ -160,7 +164,7 @@ echo >&2 "Finished one $me."
 
 case "$no_commit" in
 '')
-       git-commit -n -F .msg
+       git-commit -n -F .msg $edit
        rm -f .msg
        ;;
 esac