comparison tests/test-absorb.t @ 38917:5111d11b8719

absorb: import extension from Facebook's hg-experimental absorb is a wicked-fast command to use blame information to automatically amend edits to the correct draft revision. Originally written by Jun Wu, this import is hgext3rd/absorb/__init__.py with: * the `testedwith` value changed * the linelog import updated * some missing configitems registered * some imports reordered per check-code.py * some missing __future__ imports added per check-code.py Differential Revision: https://phab.mercurial-scm.org/D3991
author Augie Fackler <augie@google.com>
date Mon, 30 Jul 2018 14:05:56 -0400
parents
children 8460c3cbca7e
comparison
equal deleted inserted replaced
38916:49b51f41fb46 38917:5111d11b8719
1 $ cat >> $HGRCPATH << EOF
2 > [extensions]
3 > absorb=
4 > EOF
5
6 $ sedi() { # workaround check-code
7 > pattern="$1"
8 > shift
9 > for i in "$@"; do
10 > sed "$pattern" "$i" > "$i".tmp
11 > mv "$i".tmp "$i"
12 > done
13 > }
14
15 $ hg init repo1
16 $ cd repo1
17
18 Do not crash with empty repo:
19
20 $ hg absorb
21 abort: no changeset to change
22 [255]
23
24 Make some commits:
25
26 $ for i in 1 2 3 4 5; do
27 > echo $i >> a
28 > hg commit -A a -m "commit $i" -q
29 > done
30
31 $ hg annotate a
32 0: 1
33 1: 2
34 2: 3
35 3: 4
36 4: 5
37
38 Change a few lines:
39
40 $ cat > a <<EOF
41 > 1a
42 > 2b
43 > 3
44 > 4d
45 > 5e
46 > EOF
47
48 Preview absorb changes:
49
50 $ hg absorb --print-changes --dry-run
51 showing changes for a
52 @@ -0,2 +0,2 @@
53 4ec16f8 -1
54 5c5f952 -2
55 4ec16f8 +1a
56 5c5f952 +2b
57 @@ -3,2 +3,2 @@
58 ad8b8b7 -4
59 4f55fa6 -5
60 ad8b8b7 +4d
61 4f55fa6 +5e
62
63 Run absorb:
64
65 $ hg absorb
66 saved backup bundle to * (glob)
67 2 of 2 chunk(s) applied
68 $ hg annotate a
69 0: 1a
70 1: 2b
71 2: 3
72 3: 4d
73 4: 5e
74
75 Delete a few lines and related commits will be removed if they will be empty:
76
77 $ cat > a <<EOF
78 > 2b
79 > 4d
80 > EOF
81 $ hg absorb
82 saved backup bundle to * (glob)
83 3 of 3 chunk(s) applied
84 $ hg annotate a
85 1: 2b
86 2: 4d
87 $ hg log -T '{rev} {desc}\n' -Gp
88 @ 2 commit 4
89 | diff -r 1cae118c7ed8 -r 58a62bade1c6 a
90 | --- a/a Thu Jan 01 00:00:00 1970 +0000
91 | +++ b/a Thu Jan 01 00:00:00 1970 +0000
92 | @@ -1,1 +1,2 @@
93 | 2b
94 | +4d
95 |
96 o 1 commit 2
97 | diff -r 84add69aeac0 -r 1cae118c7ed8 a
98 | --- a/a Thu Jan 01 00:00:00 1970 +0000
99 | +++ b/a Thu Jan 01 00:00:00 1970 +0000
100 | @@ -0,0 +1,1 @@
101 | +2b
102 |
103 o 0 commit 1
104
105
106 Non 1:1 map changes will be ignored:
107
108 $ echo 1 > a
109 $ hg absorb
110 nothing applied
111 [1]
112
113 Insertaions:
114
115 $ cat > a << EOF
116 > insert before 2b
117 > 2b
118 > 4d
119 > insert aftert 4d
120 > EOF
121 $ hg absorb -q
122 $ hg status
123 $ hg annotate a
124 1: insert before 2b
125 1: 2b
126 2: 4d
127 2: insert aftert 4d
128
129 Bookmarks are moved:
130
131 $ hg bookmark -r 1 b1
132 $ hg bookmark -r 2 b2
133 $ hg bookmark ba
134 $ hg bookmarks
135 b1 1:b35060a57a50
136 b2 2:946e4bc87915
137 * ba 2:946e4bc87915
138 $ sedi 's/insert/INSERT/' a
139 $ hg absorb -q
140 $ hg status
141 $ hg bookmarks
142 b1 1:a4183e9b3d31
143 b2 2:c9b20c925790
144 * ba 2:c9b20c925790
145
146 Non-mofified files are ignored:
147
148 $ touch b
149 $ hg commit -A b -m b
150 $ touch c
151 $ hg add c
152 $ hg rm b
153 $ hg absorb
154 nothing applied
155 [1]
156 $ sedi 's/INSERT/Insert/' a
157 $ hg absorb
158 saved backup bundle to * (glob)
159 2 of 2 chunk(s) applied
160 $ hg status
161 A c
162 R b
163
164 Public commits will not be changed:
165
166 $ hg phase -p 1
167 $ sedi 's/Insert/insert/' a
168 $ hg absorb -pn
169 showing changes for a
170 @@ -0,1 +0,1 @@
171 -Insert before 2b
172 +insert before 2b
173 @@ -3,1 +3,1 @@
174 85b4e0e -Insert aftert 4d
175 85b4e0e +insert aftert 4d
176 $ hg absorb
177 saved backup bundle to * (glob)
178 1 of 2 chunk(s) applied
179 $ hg diff -U 0
180 diff -r 1c8eadede62a a
181 --- a/a Thu Jan 01 00:00:00 1970 +0000
182 +++ b/a * (glob)
183 @@ -1,1 +1,1 @@
184 -Insert before 2b
185 +insert before 2b
186 $ hg annotate a
187 1: Insert before 2b
188 1: 2b
189 2: 4d
190 2: insert aftert 4d
191
192 Make working copy clean:
193
194 $ hg revert -q -C a b
195 $ hg forget c
196 $ rm c
197 $ hg status
198
199 Merge commit will not be changed:
200
201 $ echo 1 > m1
202 $ hg commit -A m1 -m m1
203 $ hg bookmark -q -i m1
204 $ hg update -q '.^'
205 $ echo 2 > m2
206 $ hg commit -q -A m2 -m m2
207 $ hg merge -q m1
208 $ hg commit -m merge
209 $ hg bookmark -d m1
210 $ hg log -G -T '{rev} {desc} {phase}\n'
211 @ 6 merge draft
212 |\
213 | o 5 m2 draft
214 | |
215 o | 4 m1 draft
216 |/
217 o 3 b draft
218 |
219 o 2 commit 4 draft
220 |
221 o 1 commit 2 public
222 |
223 o 0 commit 1 public
224
225 $ echo 2 >> m1
226 $ echo 2 >> m2
227 $ hg absorb
228 abort: no changeset to change
229 [255]
230 $ hg revert -q -C m1 m2
231
232 Use a new repo:
233
234 $ cd ..
235 $ hg init repo2
236 $ cd repo2
237
238 Make some commits to multiple files:
239
240 $ for f in a b; do
241 > for i in 1 2; do
242 > echo $f line $i >> $f
243 > hg commit -A $f -m "commit $f $i" -q
244 > done
245 > done
246
247 Use pattern to select files to be fixed up:
248
249 $ sedi 's/line/Line/' a b
250 $ hg status
251 M a
252 M b
253 $ hg absorb a
254 saved backup bundle to * (glob)
255 1 of 1 chunk(s) applied
256 $ hg status
257 M b
258 $ hg absorb --exclude b
259 nothing applied
260 [1]
261 $ hg absorb b
262 saved backup bundle to * (glob)
263 1 of 1 chunk(s) applied
264 $ hg status
265 $ cat a b
266 a Line 1
267 a Line 2
268 b Line 1
269 b Line 2
270
271 Test config option absorb.maxstacksize:
272
273 $ sedi 's/Line/line/' a b
274 $ hg log -T '{rev}:{node} {desc}\n'
275 3:712d16a8f445834e36145408eabc1d29df05ec09 commit b 2
276 2:74cfa6294160149d60adbf7582b99ce37a4597ec commit b 1
277 1:28f10dcf96158f84985358a2e5d5b3505ca69c22 commit a 2
278 0:f9a81da8dc53380ed91902e5b82c1b36255a4bd0 commit a 1
279 $ hg --config absorb.maxstacksize=1 absorb -pn
280 absorb: only the recent 1 changesets will be analysed
281 showing changes for a
282 @@ -0,2 +0,2 @@
283 -a Line 1
284 -a Line 2
285 +a line 1
286 +a line 2
287 showing changes for b
288 @@ -0,2 +0,2 @@
289 -b Line 1
290 712d16a -b Line 2
291 +b line 1
292 712d16a +b line 2
293
294 Test obsolete markers creation:
295
296 $ cat >> $HGRCPATH << EOF
297 > [experimental]
298 > evolution=createmarkers
299 > [absorb]
300 > addnoise=1
301 > EOF
302
303 $ hg --config absorb.maxstacksize=3 sf
304 absorb: only the recent 3 changesets will be analysed
305 2 of 2 chunk(s) applied
306 $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
307 6:3dfde4199b46 commit b 2 712d16a8f445834e36145408eabc1d29df05ec09
308 5:99cfab7da5ff commit b 1 74cfa6294160149d60adbf7582b99ce37a4597ec
309 4:fec2b3bd9e08 commit a 2 28f10dcf96158f84985358a2e5d5b3505ca69c22
310 0:f9a81da8dc53 commit a 1
311 $ hg absorb
312 1 of 1 chunk(s) applied
313 $ hg log -T '{rev}:{node|short} {desc} {get(extras, "absorb_source")}\n'
314 10:e1c8c1e030a4 commit b 2 3dfde4199b4610ea6e3c6fa9f5bdad8939d69524
315 9:816c30955758 commit b 1 99cfab7da5ffdaf3b9fc6643b14333e194d87f46
316 8:5867d584106b commit a 2 fec2b3bd9e0834b7cb6a564348a0058171aed811
317 7:8c76602baf10 commit a 1 f9a81da8dc53380ed91902e5b82c1b36255a4bd0
318
319 Test config option absorb.amendflags and running as a sub command of amend:
320
321 $ cat >> $TESTTMP/dummyamend.py << EOF
322 > from mercurial import commands, registrar
323 > cmdtable = {}
324 > command = registrar.command(cmdtable)
325 > @command('amend', [], '')
326 > def amend(ui, repo, *pats, **opts):
327 > return 3
328 > EOF
329 $ cat >> $HGRCPATH << EOF
330 > [extensions]
331 > fbamend=$TESTTMP/dummyamend.py
332 > [absorb]
333 > amendflag = correlated
334 > EOF
335
336 $ hg amend -h
337 hg amend
338
339 (no help text available)
340
341 options:
342
343 --correlated incorporate corrections into stack. see 'hg help absorb' for
344 details
345
346 (some details hidden, use --verbose to show complete help)
347
348 $ $PYTHON -c 'print("".join(map(chr, range(0,3))))' > c
349 $ hg commit -A c -m 'c is a binary file'
350 $ echo c >> c
351 $ sedi $'2i\\\nINS\n' b
352 $ echo END >> b
353 $ hg rm a
354 $ hg amend --correlated
355 1 of 2 chunk(s) applied
356
357 # changes not applied and left in working directory:
358 # M b : 1 modified chunks were ignored
359 # M c : unsupported file type (ex. binary or link)
360 # R a : removed files were ignored
361
362 Executable files:
363
364 $ cat >> $HGRCPATH << EOF
365 > [diff]
366 > git=True
367 > EOF
368 $ cd ..
369 $ hg init repo3
370 $ cd repo3
371 $ echo > foo.py
372 $ chmod +x foo.py
373 $ hg add foo.py
374 $ hg commit -mfoo
375
376 $ echo bla > foo.py
377 $ hg absorb --dry-run --print-changes
378 showing changes for foo.py
379 @@ -0,1 +0,1 @@
380 99b4ae7 -
381 99b4ae7 +bla
382 $ hg absorb
383 1 of 1 chunk(s) applied
384 $ hg diff -c .
385 diff --git a/foo.py b/foo.py
386 new file mode 100755
387 --- /dev/null
388 +++ b/foo.py
389 @@ -0,0 +1,1 @@
390 +bla
391 $ hg diff
392
393 Remove lines may delete changesets:
394
395 $ cd ..
396 $ hg init repo4
397 $ cd repo4
398 $ cat > a <<EOF
399 > 1
400 > 2
401 > EOF
402 $ hg commit -m a12 -A a
403 $ cat > b <<EOF
404 > 1
405 > 2
406 > EOF
407 $ hg commit -m b12 -A b
408 $ echo 3 >> b
409 $ hg commit -m b3
410 $ echo 4 >> b
411 $ hg commit -m b4
412 $ echo 1 > b
413 $ echo 3 >> a
414 $ hg absorb -pn
415 showing changes for a
416 @@ -2,0 +2,1 @@
417 bfafb49 +3
418 showing changes for b
419 @@ -1,3 +1,0 @@
420 1154859 -2
421 30970db -3
422 a393a58 -4
423 $ hg absorb -v | grep became
424 bfafb49242db: 1 file(s) changed, became 1a2de97fc652
425 115485984805: 2 file(s) changed, became 0c930dfab74c
426 30970dbf7b40: became empty and was dropped
427 a393a58b9a85: became empty and was dropped
428 $ hg log -T '{rev} {desc}\n' -Gp
429 @ 5 b12
430 | diff --git a/b b/b
431 | new file mode 100644
432 | --- /dev/null
433 | +++ b/b
434 | @@ -0,0 +1,1 @@
435 | +1
436 |
437 o 4 a12
438 diff --git a/a b/a
439 new file mode 100644
440 --- /dev/null
441 +++ b/a
442 @@ -0,0 +1,3 @@
443 +1
444 +2
445 +3
446
447
448 Use revert to make the current change and its parent disappear.
449 This should move us to the non-obsolete ancestor.
450
451 $ cd ..
452 $ hg init repo5
453 $ cd repo5
454 $ cat > a <<EOF
455 > 1
456 > 2
457 > EOF
458 $ hg commit -m a12 -A a
459 $ hg id
460 bfafb49242db tip
461 $ echo 3 >> a
462 $ hg commit -m a123 a
463 $ echo 4 >> a
464 $ hg commit -m a1234 a
465 $ hg id
466 82dbe7fd19f0 tip
467 $ hg revert -r 0 a
468 $ hg absorb -pn
469 showing changes for a
470 @@ -2,2 +2,0 @@
471 f1c23dd -3
472 82dbe7f -4
473 $ hg absorb --verbose
474 f1c23dd5d08d: became empty and was dropped
475 82dbe7fd19f0: became empty and was dropped
476 a: 1 of 1 chunk(s) applied
477 $ hg id
478 bfafb49242db tip