Debian Codegraph @

tests/test-removeemptydirs.t

raw
1 Tests for experimental.removeemptydirs
2
3 $ cat >> pwd.py << EOF
4 > import os
5 > try:
6 > print(os.getcwd())
7 > except OSError:
8 > print("<directory is no longer accessible>")
9 > EOF
10
11 $ NO_RM=--config=experimental.removeemptydirs=0
12 $ DO_RM=--config=experimental.removeemptydirs=1
13 $ isdir() { if [ -d $1 ]; then echo yes; else echo no; fi }
14 $ isfile() { if [ -f $1 ]; then echo yes; else echo no; fi }
15
16 `hg rm` of the last file in a directory:
17 $ hg init hgrm
18 $ cd hgrm
19 $ mkdir somedir
20 $ echo hi > somedir/foo
21 $ hg ci -qAm foo
22 $ isdir somedir
23 yes
24 $ hg rm somedir/foo
25 $ isdir somedir
26 no
27 $ hg revert -qa
28 $ isdir somedir
29 yes
30 $ hg $NO_RM rm somedir/foo
31 $ isdir somedir
32 yes
33 $ ls somedir
34 $ cd $TESTTMP
35
36 `hg mv` of the last file in a directory:
37 $ hg init hgmv
38 $ cd hgmv
39 $ mkdir somedir
40 $ mkdir destdir
41 $ echo hi > somedir/foo
42 $ hg ci -qAm foo
43 $ isdir somedir
44 yes
45 $ hg mv somedir/foo destdir/foo
46 $ isdir somedir
47 no
48 $ hg revert -qa
49 (revert doesn't get rid of destdir/foo?)
50 $ rm destdir/foo
51 $ isdir somedir
52 yes
53 $ hg $NO_RM mv somedir/foo destdir/foo
54 $ isdir somedir
55 yes
56 $ ls somedir
57 $ cd $TESTTMP
58
59 Updating to a commit that doesn't have the directory:
60 $ hg init hgupdate
61 $ cd hgupdate
62 $ echo hi > r0
63 $ hg ci -qAm r0
64 $ mkdir somedir
65 $ echo hi > somedir/foo
66 $ hg ci -qAm r1
67 $ isdir somedir
68 yes
69 $ hg co -q -r ".^"
70 $ isdir somedir
71 no
72 $ hg co -q tip
73 $ isdir somedir
74 yes
75 $ hg $NO_RM co -q -r ".^"
76 $ isdir somedir
77 yes
78 $ ls somedir
79 $ cd $TESTTMP
80
81 Rebasing across a commit that doesn't have the directory, from inside the
82 directory:
83 $ hg init hgrebase
84 $ cd hgrebase
85 $ echo hi > r0
86 $ hg ci -qAm r0
87 $ mkdir somedir
88 $ echo hi > somedir/foo
89 $ hg ci -qAm first_rebase_source
90 $ hg $NO_RM co -q -r ".^"
91 $ echo hi > somedir/bar
92 $ hg ci -qAm first_rebase_dest
93 $ hg $NO_RM co -q -r ".^"
94 $ echo hi > somedir/baz
95 $ hg ci -qAm second_rebase_dest
96 $ hg co -qr 'desc(first_rebase_source)'
97 $ cd $TESTTMP/hgrebase/somedir
98 $ hg --config extensions.rebase= rebase -qr . -d 'desc(first_rebase_dest)'
99 current directory was removed (rmcwd !)
100 (consider changing to repo root: $TESTTMP/hgrebase) (rmcwd !)
101 $ cd $TESTTMP/hgrebase/somedir
102 (The current node is the rebased first_rebase_source on top of
103 first_rebase_dest)
104 This should not output anything about current directory being removed:
105 $ hg $NO_RM --config extensions.rebase= rebase -qr . -d 'desc(second_rebase_dest)'
106 $ cd $TESTTMP
107
108 Histediting across a commit that doesn't have the directory, from inside the
109 directory (reordering nodes):
110
111 A directory with the right pass exists at the end of the run, but it is a
112 different directory than the current one.
113
114 Windows and Solaris is not affected
115
116 $ hg init hghistedit
117 $ cd hghistedit
118 $ echo hi > r0
119 $ hg ci -qAm r0
120 $ echo hi > r1
121 $ hg ci -qAm r1
122 $ echo hi > r2
123 $ hg ci -qAm r2
124 $ mkdir somedir
125 $ echo hi > somedir/foo
126 $ hg ci -qAm migrating_revision
127 $ cat > histedit_commands <<EOF
128 > pick 89079fab8aee 0 r0
129 > pick e6d271df3142 1 r1
130 > pick 89e25aa83f0f 3 migrating_revision
131 > pick b550aa12d873 2 r2
132 > EOF
133 $ cd $TESTTMP/hghistedit/somedir
134 $ hg $DO_RM --config extensions.histedit= histedit -q --commands ../histedit_commands
135 current directory was removed (rmcwd !)
136 (consider changing to repo root: $TESTTMP/hghistedit) (rmcwd !)
137 $ ls -A $TESTTMP/hghistedit/
138 .hg
139 histedit_commands
140 r0
141 r1
142 r2
143 somedir
144 #if no-rmcwd
145 $ "$PYTHON" "$TESTTMP/pwd.py"
146 $TESTTMP/hghistedit/somedir
147 $ ls -A $TESTTMP/hghistedit/somedir
148 foo
149 $ ls -A
150 foo
151 #else
152 $ echo ${PWD} # no-pwd-check
153 $TESTTMP/hghistedit/somedir
154 $ "$PYTHON" "$TESTTMP/pwd.py"
155 <directory is no longer accessible>
156 $ ls -A $TESTTMP/hghistedit/somedir
157 foo
158 $ ls -A || true
159 ls: .: $ENOENT$ (?)
160 #endif
161
162 Get out of the doomed directory
163
164 $ cd $TESTTMP/hghistedit
165 chdir: error retrieving current directory: getcwd: cannot access parent directories: $ENOENT$ (?)
166 $ hg files --rev . | grep somedir/
167 somedir/foo
168
169
170 $ cat > histedit_commands <<EOF
171 > pick 89079fab8aee 0 r0
172 > pick 7c7a22c6009f 3 migrating_revision
173 > pick e6d271df3142 1 r1
174 > pick 40a53c2d4276 2 r2
175 > EOF
176 $ cd $TESTTMP/hghistedit/somedir
177 $ hg $NO_RM --config extensions.histedit= histedit -q --commands ../histedit_commands
178 Regardless of system, we should always get a 'yes' here.
179 $ isfile foo
180 yes
181 $ cd $TESTTMP
182
183 This is essentially the exact test from issue5826, just cleaned up a little:
184
185 $ hg init issue5826_withrm
186 $ cd issue5826_withrm
187
188 Let's only turn this on for this repo so that we don't contaminate later tests.
189 $ cat >> .hg/hgrc <<EOF
190 > [extensions]
191 > histedit =
192 > EOF
193 Commit three revisions that each create a directory:
194
195 $ mkdir foo
196 $ touch foo/bar
197 $ hg commit -qAm "add foo"
198
199 $ mkdir bar
200 $ touch bar/bar
201 $ hg commit -qAm "add bar"
202
203 $ mkdir baz
204 $ touch baz/bar
205 $ hg commit -qAm "add baz"
206
207 Enter the first directory:
208
209 $ cd foo
210
211 Histedit doing 'pick, pick, fold':
212
213 #if rmcwd
214
215 $ hg histedit --commands - <<EOF
216 > pick 6274c77c93c3 1 add bar
217 > pick ff70a87b588f 0 add foo
218 > fold 9992bb0ac0db 2 add baz
219 > EOF
220 current directory was removed
221 (consider changing to repo root: $TESTTMP/issue5826_withrm)
222 abort: $ENOENT$
223 [255]
224
225 Go back to the repo root after losing it as part of that operation:
226 $ cd $TESTTMP/issue5826_withrm
227
228 Note the lack of a non-zero exit code from this function - it exits
229 successfully, but doesn't really do anything.
230 $ hg histedit --continue
231 9992bb0ac0db: cannot fold - working copy is not a descendant of previous commit 5c806432464a
232 saved backup bundle to $TESTTMP/issue5826_withrm/.hg/strip-backup/ff70a87b588f-e94f9789-histedit.hg
233
234 $ hg log -T '{rev}:{node|short} {desc}\n'
235 2:94e3f9fae1d6 fold-temp-revision 9992bb0ac0db
236 1:5c806432464a add foo
237 0:d17db4b0303a add bar
238
239 #else
240
241 $ cd $TESTTMP/issue5826_withrm
242
243 $ hg histedit --commands - <<EOF
244 > pick 6274c77c93c3 1 add bar
245 > pick ff70a87b588f 0 add foo
246 > fold 9992bb0ac0db 2 add baz
247 > EOF
248 saved backup bundle to $TESTTMP/issue5826_withrm/.hg/strip-backup/5c806432464a-cd4c8d86-histedit.hg
249
250 $ hg log -T '{rev}:{node|short} {desc}\n'
251 1:b9eddaa97cbc add foo
252 ***
253 add baz
254 0:d17db4b0303a add bar
255
256 #endif
257
258 Now test that again with experimental.removeemptydirs=false:
259 $ hg init issue5826_norm
260 $ cd issue5826_norm
261
262 Let's only turn this on for this repo so that we don't contaminate later tests.
263 $ cat >> .hg/hgrc <<EOF
264 > [extensions]
265 > histedit =
266 > [experimental]
267 > removeemptydirs = false
268 > EOF
269 Commit three revisions that each create a directory:
270
271 $ mkdir foo
272 $ touch foo/bar
273 $ hg commit -qAm "add foo"
274
275 $ mkdir bar
276 $ touch bar/bar
277 $ hg commit -qAm "add bar"
278
279 $ mkdir baz
280 $ touch baz/bar
281 $ hg commit -qAm "add baz"
282
283 Enter the first directory:
284
285 $ cd foo
286
287 Histedit doing 'pick, pick, fold':
288
289 $ hg histedit --commands - <<EOF
290 > pick 6274c77c93c3 1 add bar
291 > pick ff70a87b588f 0 add foo
292 > fold 9992bb0ac0db 2 add baz
293 > EOF
294 saved backup bundle to $TESTTMP/issue5826_withrm/issue5826_norm/.hg/strip-backup/5c806432464a-cd4c8d86-histedit.hg
295
296 Note the lack of a 'cd' being necessary here, and we don't need to 'histedit
297 --continue'
298
299 $ hg log -T '{rev}:{node|short} {desc}\n'
300 1:b9eddaa97cbc add foo
301 ***
302 add baz
303 0:d17db4b0303a add bar
304
305 $ cd $TESTTMP