X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-revert.sh;h=bb8f1ca24aadf47734049b740be8f539e0e9325d;hb=850844e28f728625ba96b7880a0a264a5578e4c6;hp=2bf35d116c2141a1750a0ca0bd8f7297e0c237b6;hpb=182a8dabd5f5f646608f3857f10f3ac18c3d1445;p=git.git diff --git a/git-revert.sh b/git-revert.sh index 2bf35d116..bb8f1ca24 100755 --- a/git-revert.sh +++ b/git-revert.sh @@ -7,18 +7,25 @@ case "$0" in *-revert* ) test -t 0 && edit=-e + replay= me=revert USAGE='[--edit | --no-edit] [-n] ' ;; *-cherry-pick* ) + replay=t edit= me=cherry-pick - USAGE='[--edit] [-n] [-r] ' ;; + USAGE='[--edit] [-n] [-r] [-x] ' ;; * ) - die "What are you talking about?" ;; + echo >&2 "What are you talking about?" + exit 1 ;; esac + +SUBDIRECTORY_OK=Yes ;# we will cd up . git-sh-setup +require_work_tree +cd_to_toplevel -no_commit= replay= +no_commit= while case "$#" in 0) break ;; esac do case "$1" in @@ -32,8 +39,10 @@ do --n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit) edit= ;; - -r|--r|--re|--rep|--repl|--repla|--replay) - replay=t + -r) + : no-op ;; + -x|--i-really-want-to-expose-my-private-commit-object-name) + replay= ;; -*) usage @@ -72,6 +81,8 @@ prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) || git-rev-parse --verify "$commit^2" >/dev/null 2>&1 && die "Cannot run $me a multi-parent commit." +encoding=$(git repo-config i18n.commitencoding || echo UTF-8) + # "commit" is an existing commit. We would want to apply # the difference it introduces since its first parent "prev" # on top of the current HEAD if we are cherry-pick. Or the @@ -79,10 +90,11 @@ git-rev-parse --verify "$commit^2" >/dev/null 2>&1 && case "$me" in revert) - git-rev-list --pretty=oneline --max-count=1 $commit | + git show -s --pretty=oneline --encoding="$encoding" $commit | sed -e ' s/^[^ ]* /Revert "/ - s/$/"/' + s/$/"/ + ' echo echo "This reverts commit $commit." test "$rev" = "$commit" || @@ -111,17 +123,20 @@ cherry-pick) q }' - set_author_env=`git-cat-file commit "$commit" | + + logmsg=`git show -s --pretty=raw --encoding="$encoding" "$commit"` + set_author_env=`echo "$logmsg" | LANG=C LC_ALL=C sed -ne "$pick_author_script"` eval "$set_author_env" export GIT_AUTHOR_NAME export GIT_AUTHOR_EMAIL export GIT_AUTHOR_DATE - git-cat-file commit $commit | sed -e '1,/^$/d' + echo "$logmsg" | + sed -e '1,/^$/d' -e 's/^ //' case "$replay" in '') - echo "(cherry picked from $commit commit)" + echo "(cherry picked from commit $commit)" test "$rev" = "$commit" || echo "(original 'git cherry-pick' arguments: $@)" ;; @@ -131,28 +146,38 @@ cherry-pick) esac >.msg +eval GITHEAD_$head=HEAD +eval GITHEAD_$next='`git show -s \ + --pretty=oneline --encoding="$encoding" "$commit" | + sed -e "s/^[^ ]* //"`' +export GITHEAD_$head GITHEAD_$next + # This three way merge is an interesting one. We are at # $head, and would want to apply the change between $commit # and $prev on top of us (when reverting), or the change between # $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 --aggressive $base $head $next && +git-merge-recursive $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 resolving the conflicts," - echo >&2 "mark the corrected paths with 'git-update-index '" - echo >&2 "and commit with 'git commit -F .msg'" - case "$me" in - cherry-pick) + mv -f .msg "$GIT_DIR/MERGE_MSG" + { + echo ' +Conflicts: +' + git ls-files --unmerged | + sed -e 's/^[^ ]* / /' | + uniq + } >>"$GIT_DIR/MERGE_MSG" + echo >&2 "Automatic $me failed. After resolving the conflicts," + echo >&2 "mark the corrected paths with 'git-add '" + echo >&2 "and commit the result." + case "$me" in + cherry-pick) echo >&2 "You may choose to use the following when making" echo >&2 "the commit:" echo >&2 "$set_author_env" - esac - exit 1 - } - result=$(git-write-tree) || exit + esac + exit 1 } echo >&2 "Finished one $me."