Repair Run.run_background()
[stgit.git] / t / t1209-pop-spill.sh
blobe047dc418126fb4dfc0995932534678b43f3abeb
1 #!/bin/sh
3 test_description='Test "stg pop --spill"'
5 . ./test-lib.sh
7 stg init
9 reset_test () {
10 stg reset --hard
11 stg push -a
14 test_expect_success 'Create a few patches' '
15 for i in 0 1 2; do
16 stg new p$i -m p$i &&
17 echo "patch$i" >> p.txt &&
18 stg add p.txt &&
19 stg refresh
20 done &&
21 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
22 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
25 test_expect_success 'Attempt to spill non-topmost patch' '
26 command_error stg pop --spill p0 2>&1 |
27 grep -e "Can only spill topmost applied patches"
30 test_expect_success 'Pop a patch, keeping its modifications in the tree' '
31 stg pop --spill &&
32 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
33 [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
34 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
37 test_expect_success 'Pop another patch, keeping this patch modifications in the tree' '
38 stg pop --spill &&
39 [ "$(echo $(stg series --applied --noprefix))" = "p0" ] &&
40 [ "$(echo $(stg series --unapplied --noprefix))" = "p1 p2" ] &&
41 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
44 test_expect_success 'Pop last patch, keeping its modifications in the tree' '
45 stg pop --spill &&
46 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
47 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
48 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
51 test_expect_success 'Try to pop from an empty stack' '
52 test_when_finished reset_test &&
53 test_expect_code 2 stg pop --spill
56 test_expect_success 'Pop all patches, keeping modifications in the tree' '
57 test_when_finished reset_test &&
58 stg pop --spill --all &&
59 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
60 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
61 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
64 test_expect_success 'Pop zero patch, keeping modifications in the tree' '
65 # No need to reset, nothing popped
66 # test_when_finished reset_test
67 stg pop --spill -n 0 &&
68 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
69 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
70 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
73 test_expect_success 'Pop one single patch, keeping modifications in the tree' '
74 test_when_finished reset_test &&
75 stg pop --spill -n 1 &&
76 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
77 [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
78 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
81 test_expect_success 'Pop all but one patch, keeping modifications in the tree' '
82 test_when_finished reset_test &&
83 stg pop --spill -n -1 &&
84 [ "$(echo $(stg series --applied --noprefix))" = "p0" ] &&
85 [ "$(echo $(stg series --unapplied --noprefix))" = "p1 p2" ] &&
86 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
89 test_expect_success 'Pop more than stack length, keeping modifications in the tree' '
90 test_when_finished reset_test &&
91 stg pop --spill -n 3 &&
92 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
93 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
94 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
97 test_expect_success 'Pop more than stack length, keeping modifications in the tree' '
98 test_when_finished reset_test &&
99 stg pop --spill -n 4 &&
100 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
101 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
102 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
105 test_expect_success 'Pop all but more than stack length, keeping modifications in the tree' '
106 # test_when_finished reset_test &&
107 test_expect_code 2 stg pop --spill -n -4 &&
108 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
109 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
110 [ "$(echo $(cat p.txt))" = "patch0 patch1 patch2" ]
113 test_expect_success 'Create a few patches that touch separate files' '
114 stg delete .. &&
115 for i in 0 1 2; do
116 stg new p$i -m p$i &&
117 echo "patch$i" >> p$i.txt &&
118 stg add p$i.txt &&
119 stg refresh
120 done &&
121 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
122 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
123 [ "$(echo $(cat p?.txt))" = "patch0 patch1 patch2" ]
126 test_expect_success 'Pop patches that touch separate files' '
127 stg pop --spill &&
128 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
129 [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
130 [ "$(echo $(cat p?.txt))" = "patch0 patch1 patch2" ] &&
131 stg pop --spill &&
132 [ "$(echo $(stg series --applied --noprefix))" = "p0" ] &&
133 [ "$(echo $(stg series --unapplied --noprefix))" = "p1 p2" ] &&
134 [ "$(echo $(cat p?.txt))" = "patch0 patch1 patch2" ] &&
135 stg pop --spill &&
136 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
137 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
138 [ "$(echo $(cat p?.txt))" = "patch0 patch1 patch2" ]
141 test_expect_success 'Create a few patches that touch the same lines in a file' '
142 stg delete .. &&
143 for i in 0 1 2; do
144 stg new p$i -m p$i &&
145 echo "patch$i" > p.txt &&
146 stg add p.txt &&
147 stg refresh
148 done &&
149 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
150 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
151 [ "$(echo $(cat p.txt))" = "patch2" ]
154 test_expect_success 'Pop patches that all touch the same lines in a file' '
155 stg pop --spill &&
156 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
157 [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
158 [ "$(echo $(cat p.txt))" = "patch2" ] &&
159 stg pop --spill &&
160 [ "$(echo $(stg series --applied --noprefix))" = "p0" ] &&
161 [ "$(echo $(stg series --unapplied --noprefix))" = "p1 p2" ] &&
162 [ "$(echo $(cat p.txt))" = "patch2" ] &&
163 stg pop --spill &&
164 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
165 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
166 [ "$(echo $(cat p.txt))" = "patch2" ]
169 test_expect_success 'Pop an empty patch' '
170 stg delete .. &&
171 echo "spillemptypatch" > p.txt &&
172 git add p.txt &&
173 git commit -m spillempty p.txt &&
174 stg new spillempty -m spillempty &&
175 stg refresh &&
176 [ "$(echo $(stg series --applied --noprefix))" = "spillempty" ] &&
177 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
178 [ "$(echo $(cat p.txt))" = "spillemptypatch" ] &&
179 stg pop --spill &&
180 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
181 [ "$(echo $(stg series --unapplied --noprefix))" = "spillempty" ] &&
182 [ "$(echo $(cat p.txt))" = "spillemptypatch" ]
185 # Spill with uncommitted modifs
186 # Tests adapted from t1204-pop-keep.sh
188 test_expect_success 'Create a few patches & make some non-conflicting local changes' '
189 git reset --hard &&
190 stg delete .. &&
191 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
192 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
193 for i in 0 1 2; do
194 stg new p$i -m p$i &&
195 echo "patch$i" >> patch$i.txt &&
196 stg add patch$i.txt &&
197 stg refresh
198 done &&
199 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
200 [ "$(echo $(stg series --unapplied --noprefix))" = "" ]
201 echo "local" >> patch0.txt
204 test_expect_success 'Pop two patches, keeping local changes' '
205 stg pop -n 2 --keep --spill &&
206 [ "$(echo $(stg series --applied --noprefix))" = "p0" ] &&
207 [ "$(echo $(stg series --unapplied --noprefix))" = "p1 p2" ] &&
208 [ "$(echo $(ls patch?.txt))" = "patch0.txt patch1.txt patch2.txt" ] &&
209 [ "$(echo $(cat patch0.txt))" = "patch0 local" ] &&
210 [ "$(echo $(cat patch?.txt))" = "patch0 local patch1 patch2" ]
213 test_expect_success 'Pop remaining patch, keeping local changes' '
214 stg pop --keep --spill &&
215 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
216 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
217 [ "$(echo $(ls patch?.txt))" = "patch0.txt patch1.txt patch2.txt" ] &&
218 [ "$(echo $(cat patch0.txt))" = "patch0 local" ] &&
219 [ "$(echo $(cat patch?.txt))" = "patch0 local patch1 patch2" ]
222 test_expect_success 'Reset repository' '
223 git reset --hard &&
224 [ "$(echo $(stg series --applied --noprefix))" = "" ] &&
225 [ "$(echo $(stg series --unapplied --noprefix))" = "p0 p1 p2" ] &&
226 [ "$(echo $(ls patch?.txt 2> /dev/null))" = "" ]
229 test_expect_success 'Push patches again' '
230 stg push -a &&
231 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1 p2" ] &&
232 [ "$(echo $(stg series --unapplied --noprefix))" = "" ] &&
233 [ "$(echo $(ls patch?.txt))" = "patch0.txt patch1.txt patch2.txt" ] &&
234 [ "$(echo $(cat patch0.txt))" = "patch0" ] &&
235 [ "$(echo $(cat patch?.txt))" = "patch0 patch1 patch2" ]
238 test_expect_success 'Pop a patch without local changes' '
239 stg pop --keep --spill &&
240 [ "$(echo $(stg series --applied --noprefix))" = "p0 p1" ] &&
241 [ "$(echo $(stg series --unapplied --noprefix))" = "p2" ] &&
242 [ "$(echo $(ls patch?.txt))" = "patch0.txt patch1.txt patch2.txt" ] &&
243 [ "$(echo $(cat patch0.txt))" = "patch0" ] &&
244 [ "$(echo $(cat patch?.txt))" = "patch0 patch1 patch2" ]
247 test_done