1#!/bin/sh
23
test_description='test cherry-pick and revert with renames
45
--
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
1011
'
1213
. ./test-lib.sh
1415
test_expect_success setup '
1617
for l in a b c d e f g h i j k l m n o
18do
19echo $l$l$l$l$l$l$l$l$l
20done >oops &&
2122
test_tick &&
23git add oops &&
24git commit -m initial &&
25git tag initial &&
2627
test_tick &&
28echo "Add extra line at the end" >>oops &&
29git commit -a -m added &&
30git tag added &&
3132
test_tick &&
33git mv oops spoo &&
34git commit -m rename1 &&
35git tag rename1 &&
3637
test_tick &&
38git checkout -b side initial &&
39git mv oops opos &&
40git commit -m rename2 &&
41git tag rename2
42'
4344
test_expect_success 'cherry-pick --nonsense' '
4546
pos=$(git rev-parse HEAD) &&
47git diff --exit-code HEAD &&
48test_must_fail git cherry-pick --nonsense 2>msg &&
49git diff --exit-code HEAD "$pos" &&
50test_i18ngrep '[Uu]sage:' msg
51'
5253
test_expect_success 'revert --nonsense' '
5455
pos=$(git rev-parse HEAD) &&
56git diff --exit-code HEAD &&
57test_must_fail git revert --nonsense 2>msg &&
58git diff --exit-code HEAD "$pos" &&
59test_i18ngrep '[Uu]sage:' msg
60'
6162
test_expect_success 'cherry-pick after renaming branch' '
6364
git checkout rename2 &&
65git cherry-pick added &&
66test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
67test -f opos &&
68grep "Add extra line at the end" opos &&
69git reflog -1 | grep cherry-pick
7071
'
7273
test_expect_success 'revert after renaming branch' '
7475
git checkout rename1 &&
76git revert added &&
77test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
78test -f spoo &&
79! grep "Add extra line at the end" spoo &&
80git reflog -1 | grep revert
8182
'
8384
test_expect_success 'cherry-pick on stat-dirty working tree' '
85git clone . copy &&
86(
87cd copy &&
88git checkout initial &&
89test-chmtime +40 oops &&
90git cherry-pick added
91)
92'
9394
test_expect_success 'revert forbidden on dirty working tree' '
9596
echo content >extra_file &&
97git add extra_file &&
98test_must_fail git revert HEAD 2>errors &&
99test_i18ngrep "Your local changes would be overwritten by " errors
100101
'
102103
test_expect_success 'cherry-pick on unborn branch' '
104git checkout --orphan unborn &&
105git rm --cached -r . &&
106rm -rf * &&
107git cherry-pick initial &&
108git diff --quiet initial &&
109! test_cmp_rev initial HEAD
110'
111112
test_done