{"thread":{"id":"6386","subject":"[PATCH] Use merge-recursive in git-revert/git-cherry-pick","startedAt":"2007-01-15T06:00:02Z","lastAt":"2007-01-15T06:00:02Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"31748","messageId":"7vk5zoesnx.fsf@assigned-by-dhcp.cox.net","threadId":"6386","inReplyTo":null,"subject":"[PATCH] Use merge-recursive in git-revert/git-cherry-pick","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-01-15T06:00:02Z","receivedAt":"2007-01-15T06:00:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This makes revert and cherry-pick to use merge-recursive, to\nallow them to notice renames.  A pair of test scripts\ndemonstrate that an old change before a rename happened can be\napplied (reverted) after a rename with cherry-pick (with revert).\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n git-revert.sh                 |   29 ++++++++-----------\n t/t3501-revert-cherry-pick.sh |   62 +++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 74 insertions(+), 17 deletions(-)\n\ndiff --git a/git-revert.sh b/git-revert.sh\nindex 71cbcbc..c74af99 100755\n--- a/git-revert.sh\n+++ b/git-revert.sh\n@@ -151,32 +151,27 @@ esac >.msg\n # and $prev on top of us (when reverting), or the change between\n # $prev and $commit on top of us (when cherry-picking or replaying).\n \n-echo >&2 \"First trying simple merge strategy to $me.\"\n-git-read-tree -m -u --aggressive $base $head $next &&\n+git-merge-recursive $base -- $head $next &&\n result=$(git-write-tree 2>/dev/null) || {\n-    echo >&2 \"Simple $me fails; trying Automatic $me.\"\n-    git-merge-index -o git-merge-one-file -a || {\n-\t    mv -f .msg \"$GIT_DIR/MERGE_MSG\"\n-\t    {\n-\t\techo '\n+\tmv -f .msg \"$GIT_DIR/MERGE_MSG\"\n+\t{\n+\t    echo '\n Conflicts:\n '\n \t\tgit ls-files --unmerged |\n \t\tsed -e 's/^[^\t]*\t/\t/' |\n \t\tuniq\n-\t    } >>\"$GIT_DIR/MERGE_MSG\"\n-\t    echo >&2 \"Automatic $me failed.  After resolving the conflicts,\"\n-\t    echo >&2 \"mark the corrected paths with 'git-add <paths>'\"\n-\t    echo >&2 \"and commit the result.\"\n-\t    case \"$me\" in\n-\t    cherry-pick)\n+\t} >>\"$GIT_DIR/MERGE_MSG\"\n+\techo >&2 \"Automatic $me failed.  After resolving the conflicts,\"\n+\techo >&2 \"mark the corrected paths with 'git-add <paths>'\"\n+\techo >&2 \"and commit the result.\"\n+\tcase \"$me\" in\n+\tcherry-pick)\n \t\techo >&2 \"You may choose to use the following when making\"\n \t\techo >&2 \"the commit:\"\n \t\techo >&2 \"$set_author_env\"\n-\t    esac\n-\t    exit 1\n-    }\n-    result=$(git-write-tree) || exit\n+\tesac\n+\texit 1\n }\n echo >&2 \"Finished one $me.\"\n \ndiff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh\nnew file mode 100755\nindex 0000000..552af1c\n--- /dev/null\n+++ b/t/t3501-revert-cherry-pick.sh\n@@ -0,0 +1,62 @@\n+#!/bin/sh\n+\n+test_description='test cherry-pick and revert with renames\n+\n+  --\n+   + rename2: renames oops to opos\n+  +  rename1: renames oops to spoo\n+  +  added:   adds extra line to oops\n+  ++ initial: has lines in oops\n+\n+'\n+\n+. ./test-lib.sh\n+\n+test_expect_success setup '\n+\n+\tfor l in a b c d e f g h i j k l m n o\n+\tdo\n+\t\techo $l$l$l$l$l$l$l$l$l\n+\tdone >oops &&\n+\n+\ttest_tick &&\n+\tgit add oops &&\n+\tgit commit -m initial &&\n+\tgit tag initial &&\n+\n+\ttest_tick &&\n+\techo \"Add extra line at the end\" >>oops &&\n+\tgit commit -a -m added &&\n+\tgit tag added &&\n+\n+\ttest_tick &&\n+\tgit mv oops spoo &&\n+\tgit commit -m rename1 &&\n+\tgit tag rename1 &&\n+\n+\ttest_tick &&\n+\tgit checkout -b side initial &&\n+\tgit mv oops opos &&\n+\tgit commit -m rename2 &&\n+\tgit tag rename2\n+'\n+\n+test_expect_success 'cherry-pick after renaming branch' '\n+\n+\tgit checkout rename2 &&\n+\tEDITOR=: VISUAL=: git cherry-pick added &&\n+\ttest -f opos &&\n+\tgrep \"Add extra line at the end\" opos\n+\n+'\n+\n+test_expect_success 'revert after renaming branch' '\n+\n+\tgit checkout rename1 &&\n+\tEDITOR=: VISUAL=: git revert added &&\n+\ttest -f spoo &&\n+\t! grep \"Add extra line at the end\" spoo\n+\n+'\n+\n+test_done\n-- \n1.5.0.rc1.gf4b6c\n"}]}