Merge branch 'ps/gnumake-4.4-fix'
[git/debian.git] / t / t3501-revert-cherry-pick.sh
blob1f4cfc37449186c52a36cbe19f2631df759643e3
1 #!/bin/sh
3 test_description='test cherry-pick and revert with renames
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
13 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
14 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
16 . ./test-lib.sh
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 || return 1
23 done >oops &&
25 test_tick &&
26 git add oops &&
27 git commit -m initial &&
28 git tag initial &&
30 test_tick &&
31 echo "Add extra line at the end" >>oops &&
32 git commit -a -m added &&
33 git tag added &&
35 test_tick &&
36 git mv oops spoo &&
37 git commit -m rename1 &&
38 git tag rename1 &&
40 test_tick &&
41 git checkout -b side initial &&
42 git mv oops opos &&
43 git commit -m rename2 &&
44 git tag 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_cmp_rev rename2 HEAD^ &&
70 grep "Add extra line at the end" opos &&
71 git reflog -1 | grep cherry-pick
75 test_expect_success 'revert after renaming branch' '
77 git checkout rename1 &&
78 git revert added &&
79 test_cmp_rev rename1 HEAD^ &&
80 test_path_is_file spoo &&
81 test_cmp_rev initial:oops HEAD:spoo &&
82 git reflog -1 | grep revert
86 test_expect_success 'cherry-pick on stat-dirty working tree' '
87 git clone . copy &&
89 cd copy &&
90 git checkout initial &&
91 test-tool chmtime +40 oops &&
92 git cherry-pick added
96 test_expect_success 'revert forbidden on dirty working tree' '
98 echo content >extra_file &&
99 git add extra_file &&
100 test_must_fail git revert HEAD 2>errors &&
101 test_i18ngrep "your local changes would be overwritten by " errors
105 test_expect_success 'cherry-pick on unborn branch' '
106 git checkout --orphan unborn &&
107 git rm --cached -r . &&
108 rm -rf * &&
109 git cherry-pick initial &&
110 git diff --quiet initial &&
111 test_cmp_rev ! initial HEAD
114 test_expect_success 'cherry-pick "-" to pick from previous branch' '
115 git checkout unborn &&
116 test_commit to-pick actual content &&
117 git checkout main &&
118 git cherry-pick - &&
119 echo content >expect &&
120 test_cmp expect actual
123 test_expect_success 'cherry-pick "-" is meaningless without checkout' '
124 test_create_repo afresh &&
126 cd afresh &&
127 test_commit one &&
128 test_commit two &&
129 test_commit three &&
130 test_must_fail git cherry-pick -
134 test_expect_success 'cherry-pick "-" works with arguments' '
135 git checkout -b side-branch &&
136 test_commit change actual change &&
137 git checkout main &&
138 git cherry-pick -s - &&
139 echo "Signed-off-by: C O Mitter <committer@example.com>" >expect &&
140 git cat-file commit HEAD | grep ^Signed-off-by: >signoff &&
141 test_cmp expect signoff &&
142 echo change >expect &&
143 test_cmp expect actual
146 test_expect_success 'cherry-pick works with dirty renamed file' '
147 test_commit to-rename &&
148 git checkout -b unrelated &&
149 test_commit unrelated &&
150 git checkout @{-1} &&
151 git mv to-rename.t renamed &&
152 test_tick &&
153 git commit -m renamed &&
154 echo modified >renamed &&
155 git cherry-pick refs/heads/unrelated &&
156 test $(git rev-parse :0:renamed) = $(git rev-parse HEAD~2:to-rename.t) &&
157 grep -q "^modified$" renamed
160 test_expect_success 'advice from failed revert' '
161 test_when_finished "git reset --hard" &&
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".
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
178 test_expect_success 'identification of reverted commit (default)' '
179 test_commit to-ident &&
180 test_when_finished "git reset --hard to-ident" &&
181 git checkout --detach to-ident &&
182 git revert --no-edit HEAD &&
183 git cat-file commit HEAD >actual.raw &&
184 grep "^This reverts " actual.raw >actual &&
185 echo "This reverts commit $(git rev-parse HEAD^)." >expect &&
186 test_cmp expect actual
189 test_expect_success 'identification of reverted commit (--reference)' '
190 git checkout --detach to-ident &&
191 git revert --reference --no-edit HEAD &&
192 git cat-file commit HEAD >actual.raw &&
193 grep "^This reverts " actual.raw >actual &&
194 echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect &&
195 test_cmp expect actual
198 test_expect_success 'identification of reverted commit (revert.reference)' '
199 git checkout --detach to-ident &&
200 git -c revert.reference=true revert --no-edit HEAD &&
201 git cat-file commit HEAD >actual.raw &&
202 grep "^This reverts " actual.raw >actual &&
203 echo "This reverts commit $(git show -s --pretty=reference HEAD^)." >expect &&
204 test_cmp expect actual
207 test_expect_success 'cherry-pick is unaware of --reference (for now)' '
208 test_when_finished "git reset --hard" &&
209 test_must_fail git cherry-pick --reference HEAD 2>actual &&
210 grep "^usage: git cherry-pick" actual
213 test_done