@matheusbsbs / matheus-bagliano / commits / acb4441e0d
Fork 0

Use merge-recursive in git-revert/git-cherry-pick

This makes revert and cherry-pick to use merge-recursive, to allow them to notice renames. A pair of test scripts demonstrate that an old change before a rename happened can be applied (reverted) after a rename with cherry-pick (with revert). Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 14, 2007 at 22:00 UTC acb4441e0dabaaa666ecae11fdafc27c3691e763
2 files changed +74 -17
git-revert.sh
+12 -17
@@ -151,32 +151,27 @@ esac >.msg
151 # and $prev on top of us (when reverting), or the change between
152 # $prev and $commit on top of us (when cherry-picking or replaying).
153
154 -echo >&2 "First trying simple merge strategy to $me."
155 -git-read-tree -m -u --aggressive $base $head $next &&
154 +git-merge-recursive $base -- $head $next &&
155 result=$(git-write-tree 2>/dev/null) || {
157 - echo >&2 "Simple $me fails; trying Automatic $me."
158 - git-merge-index -o git-merge-one-file -a || {
159 - mv -f .msg "$GIT_DIR/MERGE_MSG"
160 - {
161 - echo '
156 + mv -f .msg "$GIT_DIR/MERGE_MSG"
157 + {
158 + echo '
159 Conflicts:
160 '
161 git ls-files --unmerged |
162 sed -e 's/^[^ ]* / /' |
163 uniq
167 - } >>"$GIT_DIR/MERGE_MSG"
168 - echo >&2 "Automatic $me failed. After resolving the conflicts,"
169 - echo >&2 "mark the corrected paths with 'git-add <paths>'"
170 - echo >&2 "and commit the result."
171 - case "$me" in
172 - cherry-pick)
164 + } >>"$GIT_DIR/MERGE_MSG"
165 + echo >&2 "Automatic $me failed. After resolving the conflicts,"
166 + echo >&2 "mark the corrected paths with 'git-add <paths>'"
167 + echo >&2 "and commit the result."
168 + case "$me" in
169 + cherry-pick)
170 echo >&2 "You may choose to use the following when making"
171 echo >&2 "the commit:"
172 echo >&2 "$set_author_env"
176 - esac
177 - exit 1
178 - }
179 - result=$(git-write-tree) || exit
173 + esac
174 + exit 1
175 }
176 echo >&2 "Finished one $me."
177
t/t3501-revert-cherry-pick.sh new
+62
@@ -0,0 +1,62 @@
1 +#!/bin/sh
2 +
3 +test_description='test cherry-pick and revert with renames
4 +
5 + --
6 + + rename2: renames oops to opos
7 + + rename1: renames oops to spoo
8 + + added: adds extra line to oops
9 + ++ initial: has lines in oops
10 +
11 +'
12 +
13 +. ./test-lib.sh
14 +
15 +test_expect_success setup '
16 +
17 + for l in a b c d e f g h i j k l m n o
18 + do
19 + echo $l$l$l$l$l$l$l$l$l
20 + done >oops &&
21 +
22 + test_tick &&
23 + git add oops &&
24 + git commit -m initial &&
25 + git tag initial &&
26 +
27 + test_tick &&
28 + echo "Add extra line at the end" >>oops &&
29 + git commit -a -m added &&
30 + git tag added &&
31 +
32 + test_tick &&
33 + git mv oops spoo &&
34 + git commit -m rename1 &&
35 + git tag rename1 &&
36 +
37 + test_tick &&
38 + git checkout -b side initial &&
39 + git mv oops opos &&
40 + git commit -m rename2 &&
41 + git tag rename2
42 +'
43 +
44 +test_expect_success 'cherry-pick after renaming branch' '
45 +
46 + git checkout rename2 &&
47 + EDITOR=: VISUAL=: git cherry-pick added &&
48 + test -f opos &&
49 + grep "Add extra line at the end" opos
50 +
51 +'
52 +
53 +test_expect_success 'revert after renaming branch' '
54 +
55 + git checkout rename1 &&
56 + EDITOR=: VISUAL=: git revert added &&
57 + test -f spoo &&
58 + ! grep "Add extra line at the end" spoo
59 +
60 +'
61 +
62 +test_done