3 test_description
='test cherry-pick and revert with renames
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
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
18 test_expect_success setup
'
20 for l in a b c d e f g h i j k l m n o
22 echo $l$l$l$l$l$l$l$l$l
27 git commit -m initial &&
31 echo "Add extra line at the end" >>oops &&
32 git commit -a -m added &&
37 git commit -m rename1 &&
41 git checkout -b side initial &&
43 git commit -m rename2 &&
47 test_expect_success
'cherry-pick --nonsense' '
49 pos=$(git rev-parse HEAD) &&
50 git diff --exit-code HEAD &&
51 test_must_fail git cherry-pick --nonsense 2>msg &&
52 git diff --exit-code HEAD "$pos" &&
53 test_i18ngrep "[Uu]sage:" msg
56 test_expect_success
'revert --nonsense' '
58 pos=$(git rev-parse HEAD) &&
59 git diff --exit-code HEAD &&
60 test_must_fail git revert --nonsense 2>msg &&
61 git diff --exit-code HEAD "$pos" &&
62 test_i18ngrep "[Uu]sage:" msg
65 test_expect_success
'cherry-pick after renaming branch' '
67 git checkout rename2 &&
68 git cherry-pick added &&
69 test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
71 grep "Add extra line at the end" opos &&
72 git reflog -1 | grep cherry-pick
76 test_expect_success
'revert after renaming branch' '
78 git checkout rename1 &&
80 test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
82 ! grep "Add extra line at the end" spoo &&
83 git reflog -1 | grep revert
87 test_expect_success
'cherry-pick on stat-dirty working tree' '
91 git checkout initial &&
92 test-tool chmtime +40 oops &&
97 test_expect_success
'revert forbidden on dirty working tree' '
99 echo content >extra_file &&
100 git add extra_file &&
101 test_must_fail git revert HEAD 2>errors &&
102 test_i18ngrep "your local changes would be overwritten by " errors
106 test_expect_success
'cherry-pick on unborn branch' '
107 git checkout --orphan unborn &&
108 git rm --cached -r . &&
110 git cherry-pick initial &&
111 git diff --quiet initial &&
112 test_cmp_rev ! initial HEAD
115 test_expect_success
'cherry-pick "-" to pick from previous branch' '
116 git checkout unborn &&
117 test_commit to-pick actual content &&
120 echo content >expect &&
121 test_cmp expect actual
124 test_expect_success
'cherry-pick "-" is meaningless without checkout' '
125 test_create_repo afresh &&
131 test_must_fail git cherry-pick -
135 test_expect_success
'cherry-pick "-" works with arguments' '
136 git checkout -b side-branch &&
137 test_commit change actual change &&
139 git cherry-pick -s - &&
140 echo "Signed-off-by: C O Mitter <committer@example.com>" >expect &&
141 git cat-file commit HEAD | grep ^Signed-off-by: >signoff &&
142 test_cmp expect signoff &&
143 echo change >expect &&
144 test_cmp expect actual
147 test_expect_success
'cherry-pick works with dirty renamed file' '
148 test_commit to-rename &&
149 git checkout -b unrelated &&
150 test_commit unrelated &&
151 git checkout @{-1} &&
152 git mv to-rename.t renamed &&
154 git commit -m renamed &&
155 echo modified >renamed &&
156 git cherry-pick refs/heads/unrelated &&
157 test $(git rev-parse :0:renamed) = $(git rev-parse HEAD~2:to-rename.t) &&
158 grep -q "^modified$" renamed