t7800: improve test descriptions with empty arguments
[alt-git.git] / t / t3501-revert-cherry-pick.sh
blobaeab689a98d00919e0473380fc9bf40497b32c80
1 #!/bin/sh
3 test_description='miscellaneous basic tests for cherry-pick and revert'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 test_expect_success setup '
13 for l in a b c d e f g h i j k l m n o
15 echo $l$l$l$l$l$l$l$l$l || return 1
16 done >oops &&
18 test_tick &&
19 git add oops &&
20 git commit -m initial &&
21 git tag initial &&
23 test_tick &&
24 echo "Add extra line at the end" >>oops &&
25 git commit -a -m added &&
26 git tag added &&
28 test_tick &&
29 git mv oops spoo &&
30 git commit -m rename1 &&
31 git tag rename1 &&
33 test_tick &&
34 git checkout -b side initial &&
35 git mv oops opos &&
36 git commit -m rename2 &&
37 git tag rename2
40 test_expect_success 'cherry-pick --nonsense' '
42 pos=$(git rev-parse HEAD) &&
43 git diff --exit-code HEAD &&
44 test_must_fail git cherry-pick --nonsense 2>msg &&
45 git diff --exit-code HEAD "$pos" &&
46 test_grep "[Uu]sage:" msg
49 test_expect_success 'revert --nonsense' '
51 pos=$(git rev-parse HEAD) &&
52 git diff --exit-code HEAD &&
53 test_must_fail git revert --nonsense 2>msg &&
54 git diff --exit-code HEAD "$pos" &&
55 test_grep "[Uu]sage:" msg
58 # the following two test cherry-pick and revert with renames
60 # --
61 # + rename2: renames oops to opos
62 # + rename1: renames oops to spoo
63 # + added: adds extra line to oops
64 # ++ initial: has lines in oops
66 test_expect_success 'cherry-pick after renaming branch' '
68 git checkout rename2 &&
69 git cherry-pick added &&
70 test_cmp_rev rename2 HEAD^ &&
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 &&
79 git revert added &&
80 test_cmp_rev rename1 HEAD^ &&
81 test_path_is_file spoo &&
82 test_cmp_rev initial:oops HEAD:spoo &&
83 git reflog -1 | grep revert
87 test_expect_success 'cherry-pick on stat-dirty working tree' '
88 git clone . copy &&
90 cd copy &&
91 git checkout initial &&
92 test-tool chmtime +40 oops &&
93 git cherry-pick added
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_grep "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 . &&
109 rm -rf * &&
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 &&
118 git checkout main &&
119 git cherry-pick - &&
120 echo content >expect &&
121 test_cmp expect actual
124 test_expect_success 'cherry-pick "-" is meaningless without checkout' '
125 test_create_repo afresh &&
127 cd afresh &&
128 test_commit one &&
129 test_commit two &&
130 test_commit three &&
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 &&
138 git checkout main &&
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 &&
153 test_tick &&
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
161 test_expect_success 'advice from failed revert' '
162 test_when_finished "git reset --hard" &&
163 test_commit --no-tag "add dream" dream dream &&
164 dream_oid=$(git rev-parse --short HEAD) &&
165 cat <<-EOF >expected &&
166 error: could not revert $dream_oid... add dream
167 hint: After resolving the conflicts, mark them with
168 hint: "git add/rm <pathspec>", then run
169 hint: "git revert --continue".
170 hint: You can instead skip this commit with "git revert --skip".
171 hint: To abort and get back to the state before "git revert",
172 hint: run "git revert --abort".
174 test_commit --append --no-tag "double-add dream" dream dream &&
175 test_must_fail git revert HEAD^ 2>actual &&
176 test_cmp expected actual
179 test_expect_subject () {
180 echo "$1" >expect &&
181 git log -1 --pretty=%s >actual &&
182 test_cmp expect actual
185 test_expect_success 'titles of fresh reverts' '
186 test_commit --no-tag A file1 &&
187 test_commit --no-tag B file1 &&
188 git revert --no-edit HEAD &&
189 test_expect_subject "Revert \"B\"" &&
190 git revert --no-edit HEAD &&
191 test_expect_subject "Reapply \"B\"" &&
192 git revert --no-edit HEAD &&
193 test_expect_subject "Revert \"Reapply \"B\"\""
196 test_expect_success 'title of legacy double revert' '
197 test_commit --no-tag "Revert \"Revert \"B\"\"" file1 &&
198 git revert --no-edit HEAD &&
199 test_expect_subject "Revert \"Revert \"Revert \"B\"\"\""
202 test_expect_success 'identification of reverted commit (default)' '
203 test_commit to-ident &&
204 test_when_finished "git reset --hard to-ident" &&
205 git checkout --detach to-ident &&
206 git revert --no-edit HEAD &&
207 git cat-file commit HEAD >actual.raw &&
208 grep "^This reverts " actual.raw >actual &&
209 echo "This reverts commit $(git rev-parse HEAD^)." >expect &&
210 test_cmp expect actual
213 test_expect_success 'identification of reverted commit (--reference)' '
214 git checkout --detach to-ident &&
215 git revert --reference --no-edit HEAD &&
216 git cat-file commit HEAD >actual.raw &&
217 grep "^This reverts " actual.raw >actual &&
218 echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect &&
219 test_cmp expect actual
222 test_expect_success 'identification of reverted commit (revert.reference)' '
223 git checkout --detach to-ident &&
224 git -c revert.reference=true revert --no-edit HEAD &&
225 git cat-file commit HEAD >actual.raw &&
226 grep "^This reverts " actual.raw >actual &&
227 echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect &&
228 test_cmp expect actual
231 test_expect_success 'cherry-pick is unaware of --reference (for now)' '
232 test_when_finished "git reset --hard" &&
233 test_must_fail git cherry-pick --reference HEAD 2>actual &&
234 grep "^usage: git cherry-pick" actual
237 test_done