blob: 595d2ff990ad3305f47977431c0b7d102ca3866b [file] [log] [blame]
Junio C Hamanoacb44412007-01-14 22:00:02 -08001#!/bin/sh
2
3test_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
13. ./test-lib.sh
14
15test_expect_success setup '
16
17 for l in a b c d e f g h i j k l m n o
18 do
19 echo $l$l$l$l$l$l$l$l$l
20 done >oops &&
21
22 test_tick &&
23 git add oops &&
24 git commit -m initial &&
25 git tag initial &&
26
27 test_tick &&
28 echo "Add extra line at the end" >>oops &&
29 git commit -a -m added &&
30 git tag added &&
31
32 test_tick &&
33 git mv oops spoo &&
34 git commit -m rename1 &&
35 git tag rename1 &&
36
37 test_tick &&
38 git checkout -b side initial &&
39 git mv oops opos &&
40 git commit -m rename2 &&
41 git tag rename2
42'
43
Jonathan Niedere0ef8492010-06-14 00:32:09 -050044test_expect_success 'cherry-pick --nonsense' '
45
46 pos=$(git rev-parse HEAD) &&
47 git diff --exit-code HEAD &&
48 test_must_fail git cherry-pick --nonsense 2>msg &&
49 git diff --exit-code HEAD "$pos" &&
50 grep '[Uu]sage:' msg
51'
52
53test_expect_success 'revert --nonsense' '
54
55 pos=$(git rev-parse HEAD) &&
56 git diff --exit-code HEAD &&
57 test_must_fail git revert --nonsense 2>msg &&
58 git diff --exit-code HEAD "$pos" &&
59 grep '[Uu]sage:' msg
60'
61
Junio C Hamanoacb44412007-01-14 22:00:02 -080062test_expect_success 'cherry-pick after renaming branch' '
63
64 git checkout rename2 &&
Kristian Høgsberg9e54dc62007-11-02 11:33:07 -040065 git cherry-pick added &&
Stephan Beyer944019c2009-01-15 14:03:17 +010066 test $(git rev-parse HEAD^) = $(git rev-parse rename2) &&
Junio C Hamanoacb44412007-01-14 22:00:02 -080067 test -f opos &&
Christian Couder643cb5f2010-06-12 18:05:12 +020068 grep "Add extra line at the end" opos &&
69 git reflog -1 | grep cherry-pick
Junio C Hamanoacb44412007-01-14 22:00:02 -080070
71'
72
73test_expect_success 'revert after renaming branch' '
74
75 git checkout rename1 &&
Kristian Høgsberg9e54dc62007-11-02 11:33:07 -040076 git revert added &&
Stephan Beyer944019c2009-01-15 14:03:17 +010077 test $(git rev-parse HEAD^) = $(git rev-parse rename1) &&
Junio C Hamanoacb44412007-01-14 22:00:02 -080078 test -f spoo &&
Christian Couder643cb5f2010-06-12 18:05:12 +020079 ! grep "Add extra line at the end" spoo &&
80 git reflog -1 | grep revert
Junio C Hamanoacb44412007-01-14 22:00:02 -080081
82'
83
Jonathan Niederf6ce1f22010-10-31 14:59:33 -050084test_expect_success 'cherry-pick on stat-dirty working tree' '
85 git clone . copy &&
86 (
87 cd copy &&
88 git checkout initial &&
89 test-chmtime +40 oops &&
90 git cherry-pick added
91 )
92'
93
Junio C Hamanofff1bb32011-04-12 16:23:01 -070094test_expect_success 'revert forbidden on dirty working tree' '
Jeff King0f2d4472008-03-03 01:30:56 -050095
96 echo content >extra_file &&
97 git add extra_file &&
98 test_must_fail git revert HEAD 2>errors &&
Junio C Hamanofff1bb32011-04-12 16:23:01 -070099 test_i18ngrep "Your local changes would be overwritten by " errors
Jeff King0f2d4472008-03-03 01:30:56 -0500100
101'
102
Junio C Hamanoacb44412007-01-14 22:00:02 -0800103test_done