test-revert-interactive.t 9.14 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Revert interactive tests
1 add and commit file f
2 add commit file folder1/g
3 add and commit file folder2/h
4 add and commit file folder1/i
5 commit change to file f
6 commit changes to files folder1/g folder2/h
7 commit changes to files folder1/g folder2/h
8 revert interactive to commit id 2 (line 3 above), check that folder1/i is removed and
9 make workdir match 7
10 run the same test than 8 from within folder1 and check same expectations

  $ cat <<EOF >> $HGRCPATH
  > [ui]
  > interactive = true
  > [extensions]
  > record =
18
  > purge = 
19 20 21
  > EOF


22
  $ mkdir -p a/folder1 a/folder2
23 24
  $ cd a
  $ hg init
25
  >>> open('f', 'wb').write(b"1\n2\n3\n4\n5\n") and None
26
  $ hg add f ; hg commit -m "adding f"
27 28 29
  $ cat f > folder1/g ; hg add folder1/g ; hg commit -m "adding folder1/g"
  $ cat f > folder2/h ; hg add folder2/h ; hg commit -m "adding folder2/h"
  $ cat f > folder1/i ; hg add folder1/i ; hg commit -m "adding folder1/i"
30
  >>> open('f', 'wb').write(b"a\n1\n2\n3\n4\n5\nb\n") and None
31
  $ hg commit -m "modifying f"
32
  >>> open('folder1/g', 'wb').write(b"c\n1\n2\n3\n4\n5\nd\n") and None
33
  $ hg commit -m "modifying folder1/g"
34
  >>> open('folder2/h', 'wb').write(b"e\n1\n2\n3\n4\n5\nf\n") and None
35
  $ hg commit -m "modifying folder2/h"
36 37 38 39 40 41 42 43 44 45 46 47 48
  $ hg tip
  changeset:   6:59dd6e4ab63a
  tag:         tip
  user:        test
  date:        Thu Jan 01 00:00:00 1970 +0000
  summary:     modifying folder2/h
  
  $ hg revert -i -r 2 --all -- << EOF
  > y
  > y
  > y
  > y
  > y
49
  > ?
50
  > y
51 52 53
  > n
  > n
  > EOF
54
  remove added file folder1/i (Yn)? y
55
  removing folder1/i
56
  diff --git a/f b/f
57
  2 hunks, 2 lines changed
58 59
  examine changes to 'f'?
  (enter ? for help) [Ynesfdaq?] y
60
  
61 62
  @@ -1,6 +1,5 @@
  -a
63 64 65 66 67
   1
   2
   3
   4
   5
68 69
  apply change 1/6 to 'f'?
  (enter ? for help) [Ynesfdaq?] y
70
  
71
  @@ -2,6 +1,5 @@
72 73 74 75 76
   1
   2
   3
   4
   5
77
  -b
78 79
  apply change 2/6 to 'f'?
  (enter ? for help) [Ynesfdaq?] y
80
  
81
  diff --git a/folder1/g b/folder1/g
82
  2 hunks, 2 lines changed
83 84
  examine changes to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] y
85
  
86 87
  @@ -1,6 +1,5 @@
  -c
88 89 90 91 92
   1
   2
   3
   4
   5
93 94
  apply change 3/6 to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] ?
95
  
96
  y - yes, apply this change
97 98 99
  n - no, skip this change
  e - edit this change manually
  s - skip remaining changes to this file
100
  f - apply remaining changes to this file
101
  d - done, skip remaining changes and files
102 103
  a - apply all changes to all remaining files
  q - quit, applying no changes
104
  ? - ? (display help)
105 106
  apply change 3/6 to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] y
107
  
108
  @@ -2,6 +1,5 @@
109 110 111 112 113
   1
   2
   3
   4
   5
114
  -d
115 116
  apply change 4/6 to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] n
117
  
118
  diff --git a/folder2/h b/folder2/h
119
  2 hunks, 2 lines changed
120 121
  examine changes to 'folder2/h'?
  (enter ? for help) [Ynesfdaq?] n
122
  
123
  reverting f
124
  reverting folder1/g
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
  $ cat f
  1
  2
  3
  4
  5
  $ cat folder1/g
  1
  2
  3
  4
  5
  d
  $ cat folder2/h
  e
  1
  2
  3
  4
  5
  f
146 147 148 149

Test that --interactive lift the need for --all

  $ echo q | hg revert -i -r 2
150
  diff --git a/folder1/g b/folder1/g
151
  1 hunks, 1 lines changed
152 153
  examine changes to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] q
154 155 156
  
  abort: user quit
  [255]
157 158 159
  $ ls folder1/
  g

160
Test that a noop revert doesn't do an unnecessary backup
161
  $ (echo n) | hg revert -i -r 2 folder1/g
162 163
  diff --git a/folder1/g b/folder1/g
  1 hunks, 1 lines changed
164
  @@ -3,4 +3,3 @@
165 166 167
   3
   4
   5
168
  -d
169 170
  apply this change to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] n
171 172 173 174 175
  
  $ ls folder1/
  g

Test --no-backup
176
  $ (echo y) | hg revert -i -C -r 2 folder1/g
177 178
  diff --git a/folder1/g b/folder1/g
  1 hunks, 1 lines changed
179
  @@ -3,4 +3,3 @@
180 181 182
   3
   4
   5
183
  -d
184 185
  apply this change to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] y
186 187 188
  
  $ ls folder1/
  g
189
  >>> open('folder1/g', 'wb').write(b"1\n2\n3\n4\n5\nd\n") and None
190 191


192 193 194
  $ hg update -C 6
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg revert -i -r 2 --all -- << EOF
195
  > n
196 197 198 199 200 201 202 203
  > y
  > y
  > y
  > y
  > y
  > n
  > n
  > EOF
204
  remove added file folder1/i (Yn)? n
205
  diff --git a/f b/f
206
  2 hunks, 2 lines changed
207 208
  examine changes to 'f'?
  (enter ? for help) [Ynesfdaq?] y
209
  
210 211
  @@ -1,6 +1,5 @@
  -a
212 213 214 215 216
   1
   2
   3
   4
   5
217 218
  apply change 1/6 to 'f'?
  (enter ? for help) [Ynesfdaq?] y
219
  
220
  @@ -2,6 +1,5 @@
221 222 223 224 225
   1
   2
   3
   4
   5
226
  -b
227 228
  apply change 2/6 to 'f'?
  (enter ? for help) [Ynesfdaq?] y
229
  
230
  diff --git a/folder1/g b/folder1/g
231
  2 hunks, 2 lines changed
232 233
  examine changes to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] y
234
  
235 236
  @@ -1,6 +1,5 @@
  -c
237 238 239 240 241
   1
   2
   3
   4
   5
242 243
  apply change 3/6 to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] y
244
  
245
  @@ -2,6 +1,5 @@
246 247 248 249 250
   1
   2
   3
   4
   5
251
  -d
252 253
  apply change 4/6 to 'folder1/g'?
  (enter ? for help) [Ynesfdaq?] n
254
  
255
  diff --git a/folder2/h b/folder2/h
256
  2 hunks, 2 lines changed
257 258
  examine changes to 'folder2/h'?
  (enter ? for help) [Ynesfdaq?] n
259
  
260
  reverting f
261
  reverting folder1/g
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
  $ cat f
  1
  2
  3
  4
  5
  $ cat folder1/g
  1
  2
  3
  4
  5
  d
  $ cat folder2/h
  e
  1
  2
  3
  4
  5
  f
283 284 285 286
  $ hg st
  M f
  M folder1/g
  $ hg revert --interactive f << EOF
287
  > ?
288 289 290 291
  > y
  > n
  > n
  > EOF
292
  diff --git a/f b/f
293
  2 hunks, 2 lines changed
294 295
  @@ -1,6 +1,5 @@
  -a
296 297 298 299 300
   1
   2
   3
   4
   5
301 302
  discard change 1/2 to 'f'?
  (enter ? for help) [Ynesfdaq?] ?
303 304 305 306 307 308 309 310 311 312
  
  y - yes, discard this change
  n - no, skip this change
  e - edit this change manually
  s - skip remaining changes to this file
  f - discard remaining changes to this file
  d - done, skip remaining changes and files
  a - discard all changes to all remaining files
  q - quit, discarding no changes
  ? - ? (display help)
313 314
  discard change 1/2 to 'f'?
  (enter ? for help) [Ynesfdaq?] y
315
  
316
  @@ -2,6 +1,5 @@
317 318 319 320 321
   1
   2
   3
   4
   5
322
  -b
323 324
  discard change 2/2 to 'f'?
  (enter ? for help) [Ynesfdaq?] n
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
  
  $ hg st
  M f
  M folder1/g
  ? f.orig
  $ cat f
  a
  1
  2
  3
  4
  5
  $ cat f.orig
  1
  2
  3
  4
  5
343
  $ rm f.orig
344 345 346 347 348 349 350 351 352

Patterns

  $ hg revert -i 'glob:f*' << EOF
  > y
  > n
  > EOF
  diff --git a/f b/f
  1 hunks, 1 lines changed
353 354
  examine changes to 'f'?
  (enter ? for help) [Ynesfdaq?] y
355 356 357 358 359 360
  
  @@ -4,4 +4,3 @@
   3
   4
   5
  -b
361 362
  discard this change to 'f'?
  (enter ? for help) [Ynesfdaq?] n
363 364
  

365
  $ hg update -C .
366
  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
367 368 369 370 371 372 373 374 375

Check editing files newly added by a revert

1) Create a dummy editor changing 1 to 42
  $ cat > $TESTTMP/editor.sh << '__EOF__'
  > cat "$1"  | sed "s/1/42/g"  > tt
  > mv tt  "$1"
  > __EOF__

376 377 378
2) Add k
  $ printf "1\n" > k
  $ hg add k
379 380
  $ hg commit -m "add k"

381 382 383
3) Use interactive revert with editing (replacing +1 with +42):
  $ printf "0\n2\n" > k
  $ HGEDITOR="\"sh\" \"${TESTTMP}/editor.sh\"" hg revert -i  <<EOF
384 385 386
  > y
  > e
  > EOF
387 388
  diff --git a/k b/k
  1 hunks, 2 lines changed
389 390
  examine changes to 'k'?
  (enter ? for help) [Ynesfdaq?] y
391
  
392 393 394 395
  @@ -1,1 +1,2 @@
  -1
  +0
  +2
396 397
  discard this change to 'k'?
  (enter ? for help) [Ynesfdaq?] e
398
  
399
  reverting k
400
  $ cat k
401
  42
402

403 404 405 406 407 408 409 410 411 412
  $ hg update -C .
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg purge
  $ touch newfile
  $ hg add newfile
  $ hg status
  A newfile
  $ hg revert -i <<EOF
  > n
  > EOF
413
  forget added file newfile (Yn)? n
414 415 416 417 418
  $ hg status
  A newfile
  $ hg revert -i <<EOF
  > y
  > EOF
419
  forget added file newfile (Yn)? y
420
  forgetting newfile
421 422
  $ hg status
  ? newfile
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441

When a line without EOL is selected during "revert -i" (issue5651)

  $ hg init $TESTTMP/revert-i-eol
  $ cd $TESTTMP/revert-i-eol
  $ echo 0 > a
  $ hg ci -qAm 0
  $ printf 1 >> a
  $ hg ci -qAm 1
  $ cat a
  0
  1 (no-eol)

  $ hg revert -ir'.^' <<EOF
  > y
  > y
  > EOF
  diff --git a/a b/a
  1 hunks, 1 lines changed
442 443
  examine changes to 'a'?
  (enter ? for help) [Ynesfdaq?] y
444
  
445
  @@ -1,2 +1,1 @@
446
   0
447
  -1
448
  \ No newline at end of file
449 450
  apply this change to 'a'?
  (enter ? for help) [Ynesfdaq?] y
451
  
452
  reverting a
453 454 455
  $ cat a
  0

456 457 458 459 460 461 462 463 464
When specified pattern does not exist, we should exit early (issue5789).

  $ hg files
  a
  $ hg rev b
  b: no such file in rev b40d1912accf
  $ hg rev -i b
  b: no such file in rev b40d1912accf

465
  $ cd ..
466 467 468 469 470 471 472 473 474 475 476 477

Prompt before undeleting file(issue6008)
  $ hg init repo
  $ cd repo
  $ echo a > a
  $ hg ci -qAm a
  $ hg rm a
  $ hg revert -i<<EOF
  > y
  > EOF
  add back removed file a (Yn)? y
  undeleting a
478 479
  $ ls -A
  .hg
480 481 482 483 484 485
  a
  $ hg rm a
  $ hg revert -i<<EOF
  > n
  > EOF
  add back removed file a (Yn)? n
486 487
  $ ls -A
  .hg
488 489
  $ hg revert -a
  undeleting a
490
  $ cd ..
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519

Test "keep" mode

  $ cat <<EOF >> $HGRCPATH
  > [experimental]
  > revert.interactive.select-to-keep = true
  > EOF

  $ cd repo
  $ printf "x\na\ny\n" > a
  $ hg diff
  diff -r cb9a9f314b8b a
  --- a/a	Thu Jan 01 00:00:00 1970 +0000
  +++ b/a	Thu Jan 01 00:00:00 1970 +0000
  @@ -1,1 +1,3 @@
  +x
   a
  +y
  $ cat > $TESTTMP/editor.sh << '__EOF__'
  > echo "+new line" >> "$1"
  > __EOF__

  $ HGEDITOR="\"sh\" \"${TESTTMP}/editor.sh\"" hg revert -i  <<EOF
  > y
  > n
  > e
  > EOF
  diff --git a/a b/a
  2 hunks, 2 lines changed
520 521
  examine changes to 'a'?
  (enter ? for help) [Ynesfdaq?] y
522 523 524 525
  
  @@ -1,1 +1,2 @@
  +x
   a
526 527
  keep change 1/2 to 'a'?
  (enter ? for help) [Ynesfdaq?] n
528 529 530 531
  
  @@ -1,1 +2,2 @@
   a
  +y
532 533
  keep change 2/2 to 'a'?
  (enter ? for help) [Ynesfdaq?] e
534 535 536 537 538 539
  
  reverting a
  $ cat a
  a
  y
  new line