3
# Copyright (c) 2005 Linus Torvalds
4
# Copyright (c) 2005 Junio C Hamano
12
USAGE='[--edit | --no-edit] [-n] <commit-ish>' ;;
17
USAGE='[--edit] [-n] [-r] [-x] <commit-ish>' ;;
19
die "What are you talking about?" ;;
24
while case "$#" in 0) break ;; esac
27
-n|--n|--no|--no-|--no-c|--no-co|--no-com|--no-comm|\
28
--no-commi|--no-commit)
31
-e|--e|--ed|--edi|--edit)
34
--n|--no|--no-|--no-e|--no-ed|--no-edi|--no-edit)
39
-x|--i-really-want-to-expose-my-private-commit-object-name)
52
test "$me,$replay" = "revert,t" && usage
56
# We do not intend to commit immediately. We just want to
57
# merge the differences in.
58
head=$(git-write-tree) ||
59
die "Your index file is unmerged."
62
head=$(git-rev-parse --verify HEAD) ||
63
die "You do not have a valid HEAD"
64
files=$(git-diff-index --cached --name-only $head) || exit
66
die "Dirty index: cannot $me (dirty: $files)"
71
rev=$(git-rev-parse --verify "$@") &&
72
commit=$(git-rev-parse --verify "$rev^0") ||
73
die "Not a single commit $@"
74
prev=$(git-rev-parse --verify "$commit^1" 2>/dev/null) ||
75
die "Cannot run $me a root commit"
76
git-rev-parse --verify "$commit^2" >/dev/null 2>&1 &&
77
die "Cannot run $me a multi-parent commit."
79
# "commit" is an existing commit. We would want to apply
80
# the difference it introduces since its first parent "prev"
81
# on top of the current HEAD if we are cherry-pick. Or the
82
# reverse of it if we are revert.
86
git-rev-list --pretty=oneline --max-count=1 $commit |
91
echo "This reverts commit $commit."
92
test "$rev" = "$commit" ||
93
echo "(original 'git revert' arguments: $@)"
94
base=$commit next=$prev
100
s/'\''/'\''\\'\'\''/g
102
s/^author \([^<]*\) <[^>]*> .*$/\1/
104
s/.*/GIT_AUTHOR_NAME='\''&'\''/p
107
s/^author [^<]* <\([^>]*\)> .*$/\1/
109
s/.*/GIT_AUTHOR_EMAIL='\''&'\''/p
112
s/^author [^<]* <[^>]*> \(.*\)$/\1/
114
s/.*/GIT_AUTHOR_DATE='\''&'\''/p
118
set_author_env=`git-cat-file commit "$commit" |
119
LANG=C LC_ALL=C sed -ne "$pick_author_script"`
120
eval "$set_author_env"
121
export GIT_AUTHOR_NAME
122
export GIT_AUTHOR_EMAIL
123
export GIT_AUTHOR_DATE
125
git-cat-file commit $commit | sed -e '1,/^$/d'
128
echo "(cherry picked from commit $commit)"
129
test "$rev" = "$commit" ||
130
echo "(original 'git cherry-pick' arguments: $@)"
133
base=$prev next=$commit
138
# This three way merge is an interesting one. We are at
139
# $head, and would want to apply the change between $commit
140
# and $prev on top of us (when reverting), or the change between
141
# $prev and $commit on top of us (when cherry-picking or replaying).
143
echo >&2 "First trying simple merge strategy to $me."
144
git-read-tree -m -u --aggressive $base $head $next &&
145
result=$(git-write-tree 2>/dev/null) || {
146
echo >&2 "Simple $me fails; trying Automatic $me."
147
git-merge-index -o git-merge-one-file -a || {
148
mv -f .msg "$GIT_DIR/MERGE_MSG"
153
git ls-files --unmerged |
154
sed -e 's/^[^ ]* / /' |
156
} >>"$GIT_DIR/MERGE_MSG"
157
echo >&2 "Automatic $me failed. After resolving the conflicts,"
158
echo >&2 "mark the corrected paths with 'git-update-index <paths>'"
159
echo >&2 "and commit the result."
162
echo >&2 "You may choose to use the following when making"
163
echo >&2 "the commit:"
164
echo >&2 "$set_author_env"
168
result=$(git-write-tree) || exit
170
echo >&2 "Finished one $me."
172
# If we are cherry-pick, and if the merge did not result in
173
# hand-editing, we will hit this commit and inherit the original
174
# author date and name.
175
# If we are revert, or if our cherry-pick results in a hand merge,
176
# we had better say that the current user is responsible for that.
180
git-commit -n -F .msg $edit