]>
Commit | Line | Data |
---|---|---|
acb4441e JH |
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 | ||
cbc75a12 | 13 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
14 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
15 | ||
acb4441e JH |
16 | . ./test-lib.sh |
17 | ||
18 | test_expect_success setup ' | |
19 | ||
20 | for l in a b c d e f g h i j k l m n o | |
21 | do | |
db5875aa | 22 | echo $l$l$l$l$l$l$l$l$l || return 1 |
acb4441e JH |
23 | done >oops && |
24 | ||
25 | test_tick && | |
26 | git add oops && | |
27 | git commit -m initial && | |
28 | git tag initial && | |
29 | ||
30 | test_tick && | |
31 | echo "Add extra line at the end" >>oops && | |
32 | git commit -a -m added && | |
33 | git tag added && | |
34 | ||
35 | test_tick && | |
36 | git mv oops spoo && | |
37 | git commit -m rename1 && | |
38 | git tag rename1 && | |
39 | ||
40 | test_tick && | |
41 | git checkout -b side initial && | |
42 | git mv oops opos && | |
43 | git commit -m rename2 && | |
44 | git tag rename2 | |
45 | ' | |
46 | ||
e0ef8495 JN |
47 | test_expect_success 'cherry-pick --nonsense' ' |
48 | ||
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" && | |
c76b84a1 | 53 | test_i18ngrep "[Uu]sage:" msg |
e0ef8495 JN |
54 | ' |
55 | ||
56 | test_expect_success 'revert --nonsense' ' | |
57 | ||
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" && | |
c76b84a1 | 62 | test_i18ngrep "[Uu]sage:" msg |
e0ef8495 JN |
63 | ' |
64 | ||
acb4441e JH |
65 | test_expect_success 'cherry-pick after renaming branch' ' |
66 | ||
67 | git checkout rename2 && | |
9e54dc6c | 68 | git cherry-pick added && |
944019c8 | 69 | test $(git rev-parse HEAD^) = $(git rev-parse rename2) && |
acb4441e | 70 | test -f opos && |
643cb5f7 CC |
71 | grep "Add extra line at the end" opos && |
72 | git reflog -1 | grep cherry-pick | |
acb4441e JH |
73 | |
74 | ' | |
75 | ||
76 | test_expect_success 'revert after renaming branch' ' | |
77 | ||
78 | git checkout rename1 && | |
9e54dc6c | 79 | git revert added && |
944019c8 | 80 | test $(git rev-parse HEAD^) = $(git rev-parse rename1) && |
acb4441e | 81 | test -f spoo && |
643cb5f7 CC |
82 | ! grep "Add extra line at the end" spoo && |
83 | git reflog -1 | grep revert | |
acb4441e JH |
84 | |
85 | ' | |
86 | ||
f6ce1f25 JN |
87 | test_expect_success 'cherry-pick on stat-dirty working tree' ' |
88 | git clone . copy && | |
89 | ( | |
90 | cd copy && | |
91 | git checkout initial && | |
0e496492 | 92 | test-tool chmtime +40 oops && |
f6ce1f25 JN |
93 | git cherry-pick added |
94 | ) | |
95 | ' | |
96 | ||
fff1bb3a | 97 | test_expect_success 'revert forbidden on dirty working tree' ' |
0f2d4476 JK |
98 | |
99 | echo content >extra_file && | |
100 | git add extra_file && | |
101 | test_must_fail git revert HEAD 2>errors && | |
93b3df6f | 102 | test_i18ngrep "your local changes would be overwritten by " errors |
0f2d4476 JK |
103 | |
104 | ' | |
105 | ||
7a96c386 | 106 | test_expect_success 'cherry-pick on unborn branch' ' |
334ae397 MZ |
107 | git checkout --orphan unborn && |
108 | git rm --cached -r . && | |
109 | rm -rf * && | |
110 | git cherry-pick initial && | |
111 | git diff --quiet initial && | |
2c9e125b | 112 | test_cmp_rev ! initial HEAD |
334ae397 MZ |
113 | ' |
114 | ||
182d7dc4 HU |
115 | test_expect_success 'cherry-pick "-" to pick from previous branch' ' |
116 | git checkout unborn && | |
117 | test_commit to-pick actual content && | |
cbc75a12 | 118 | git checkout main && |
182d7dc4 HU |
119 | git cherry-pick - && |
120 | echo content >expect && | |
121 | test_cmp expect actual | |
122 | ' | |
123 | ||
124 | test_expect_success 'cherry-pick "-" is meaningless without checkout' ' | |
125 | test_create_repo afresh && | |
126 | ( | |
127 | cd afresh && | |
128 | test_commit one && | |
129 | test_commit two && | |
130 | test_commit three && | |
131 | test_must_fail git cherry-pick - | |
132 | ) | |
133 | ' | |
134 | ||
d644c550 JK |
135 | test_expect_success 'cherry-pick "-" works with arguments' ' |
136 | git checkout -b side-branch && | |
137 | test_commit change actual change && | |
cbc75a12 | 138 | git checkout main && |
d644c550 JK |
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 | |
145 | ' | |
146 | ||
2f682e21 | 147 | test_expect_success 'cherry-pick works with dirty renamed file' ' |
05f2dfb9 JS |
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 && | |
153 | test_tick && | |
154 | git commit -m renamed && | |
155 | echo modified >renamed && | |
f670adb4 | 156 | git cherry-pick refs/heads/unrelated && |
fd53b7ff | 157 | test $(git rev-parse :0:renamed) = $(git rev-parse HEAD~2:to-rename.t) && |
7c5585ff | 158 | grep -q "^modified$" renamed |
05f2dfb9 JS |
159 | ' |
160 | ||
f172556b ZH |
161 | test_expect_success 'advice from failed revert' ' |
162 | test_commit --no-tag "add dream" dream dream && | |
163 | dream_oid=$(git rev-parse --short HEAD) && | |
164 | cat <<-EOF >expected && | |
165 | error: could not revert $dream_oid... add dream | |
166 | hint: After resolving the conflicts, mark them with | |
167 | hint: "git add/rm <pathspec>", then run | |
168 | hint: "git revert --continue". | |
169 | hint: You can instead skip this commit with "git revert --skip". | |
170 | hint: To abort and get back to the state before "git revert", | |
171 | hint: run "git revert --abort". | |
172 | EOF | |
173 | test_commit --append --no-tag "double-add dream" dream dream && | |
174 | test_must_fail git revert HEAD^ 2>actual && | |
175 | test_cmp expected actual | |
176 | ' | |
acb4441e | 177 | test_done |