rebase: cherry-pick: add copyright
[git] / t / t3420-rebase-autostash.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2013 Ramkumar Ramachandra
4 #
5
6 test_description='git rebase --autostash tests'
7 . ./test-lib.sh
8
9 test_expect_success setup '
10         echo hello-world >file0 &&
11         git add . &&
12         test_tick &&
13         git commit -m "initial commit" &&
14         git checkout -b feature-branch &&
15         echo another-hello >file1 &&
16         echo goodbye >file2 &&
17         git add . &&
18         test_tick &&
19         git commit -m "second commit" &&
20         echo final-goodbye >file3 &&
21         git add . &&
22         test_tick &&
23         git commit -m "third commit" &&
24         git checkout -b unrelated-onto-branch master &&
25         echo unrelated >file4 &&
26         git add . &&
27         test_tick &&
28         git commit -m "unrelated commit" &&
29         git checkout -b related-onto-branch master &&
30         echo conflicting-change >file2 &&
31         git add . &&
32         test_tick &&
33         git commit -m "related commit"
34 '
35
36 setup_tmp () {
37         git clone . tmp &&
38         cd tmp &&
39         git fetch -u origin "refs/heads/*:refs/heads/*" &&
40         test_config rebase.autostash true &&
41         git checkout -b rebased-feature-branch feature-branch
42 }
43
44 testrebase() {
45         type=$1
46         dotest=$2
47
48         test_expect_success "rebase$type: dirty worktree, non-conflicting rebase" '
49                 test_when_finished "rm -rf tmp" &&
50                 (
51                 setup_tmp &&
52                 echo dirty >>file3 &&
53                 git rebase$type unrelated-onto-branch &&
54                 grep unrelated file4 &&
55                 grep dirty file3
56                 )
57         '
58
59         test_expect_success "rebase$type: dirty index, non-conflicting rebase" '
60                 test_when_finished "rm -rf tmp" &&
61                 (
62                 setup_tmp &&
63                 echo dirty >>file3 &&
64                 git add file3 &&
65                 git rebase$type unrelated-onto-branch &&
66                 grep unrelated file4 &&
67                 grep dirty file3
68                 )
69         '
70
71         test_expect_success "rebase$type: conflicting rebase" '
72                 test_when_finished "rm -rf tmp" &&
73                 (
74                 setup_tmp &&
75                 echo dirty >>file3 &&
76                 test_must_fail git rebase$type related-onto-branch &&
77                 test_path_is_file $dotest/autostash &&
78                 ! grep dirty file3
79                 )
80         '
81
82         test_expect_success "rebase$type: --continue" '
83                 test_when_finished "rm -rf tmp" &&
84                 (
85                 setup_tmp &&
86                 echo dirty >>file3 &&
87                 test_must_fail git rebase$type related-onto-branch &&
88                 test_path_is_file $dotest/autostash &&
89                 ! grep dirty file3 &&
90                 echo "conflicting-plus-goodbye" >file2 &&
91                 git add file2 &&
92                 git rebase --continue &&
93                 test_path_is_missing $dotest/autostash &&
94                 grep dirty file3
95                 )
96         '
97
98         test_expect_success "rebase$type: --skip" '
99                 test_when_finished "rm -rf tmp" &&
100                 (
101                 setup_tmp &&
102                 git reset --hard &&
103                 echo dirty >>file3 &&
104                 test_must_fail git rebase$type related-onto-branch &&
105                 test_path_is_file $dotest/autostash &&
106                 ! grep dirty file3 &&
107                 git rebase --skip &&
108                 test_path_is_missing $dotest/autostash &&
109                 grep dirty file3
110                 )
111         '
112
113         test_expect_success "rebase$type: --abort" '
114                 test_when_finished "rm -rf tmp" &&
115                 (
116                 setup_tmp &&
117                 echo dirty >>file3 &&
118                 test_must_fail git rebase$type related-onto-branch &&
119                 test_path_is_file $dotest/autostash &&
120                 ! grep dirty file3 &&
121                 git rebase --abort &&
122                 test_path_is_missing $dotest/autostash &&
123                 grep dirty file3
124                 )
125         '
126
127         test_expect_success "rebase$type: non-conflicting rebase, conflicting stash" '
128                 test_when_finished "rm -rf tmp" &&
129                 (
130                 setup_tmp &&
131                 echo dirty >file4 &&
132                 git add file4 &&
133                 git rebase$type unrelated-onto-branch &&
134                 test_path_is_missing $dotest &&
135                 git reset --hard &&
136                 grep unrelated file4 &&
137                 ! grep dirty file4 &&
138                 git checkout feature-branch &&
139                 git stash pop &&
140                 grep dirty file4
141                 )
142         '
143 }
144
145 test_expect_success "rebase: fast-forward rebase" '
146         test_when_finished "rm -rf tmp" &&
147         (
148         setup_tmp &&
149         echo dirty >>file1 &&
150         git rebase feature-branch &&
151         grep dirty file1
152         )
153 '
154
155 test_expect_success "rebase: noop rebase" '
156         test_when_finished "rm -rf tmp" &&
157         (
158         setup_tmp &&
159         echo dirty >>file1 &&
160         git rebase feature-branch &&
161         grep dirty file1
162         )
163 '
164
165 testrebase "" .git/rebase-merge
166 testrebase " --merge" .git/rebase-merge
167 testrebase " --interactive" .git/rebase-merge
168
169 test_done