tests/test-evolve-interrupted.t
author Kyle Lippincott <spectral@google.com>
Mon, 16 Sep 2019 12:44:38 -0700
changeset 4848 535ab2609e45
child 4865 31c481934138
child 5141 591a0afd2ef3
permissions -rw-r--r--
cmdstate: introduce a "saver" contextmanager and use it in place of save() Previously, the state was only saved in some paths out of these functions. This can be problematic, if the user ctrl-c's (or `kill -9`'s) the process, or we exit out of `relocate` for anything besides the "expected" reason, we won't record that we were in the middle of an evolve. One of our users has discovered that this leaves hg in a weird state; the user did something like this: ``` $ hg evolve <something goes wrong with the merge tool, hits ctrl-c> <deals with the merge conflicts> $ hg evolve --continue abort: no interrupted evolve to continue $ hg evolve abort: uncommitted changes # Note: commands.status.verbose=True is set. $ hg status M foo # The repository is in an unfinished *update* state. # No unresolved merge conflicts # To continue: hg update ``` The user did an `hg update`, but it didn't actually do anything besides take it out of the unfinished update state (the files were still dirty in the working directory).

Quitting an evolve in the middle (via ctrl-c or something) can leave things in a
weird intermediate state where hg thinks we're in the middle of an update
operation (or even just leave the 'merge' directory around without actually
indicating we're in the middle of *any* operation).

  $ . $TESTDIR/testlib/common.sh

  $ cat << EOF >> $HGRCPATH
  > [extensions]
  > rebase =
  > evolve =
  > [alias]
  > l = log -G -T'{rev} {desc}'
  > EOF

  $ hg init interrupted-orphan
  $ cd interrupted-orphan

  $ echo apricot > a
  $ hg ci -qAm apricot

  $ echo banana > b
  $ hg ci -qAm banana

Let's go back to amend 0 and make an orphan out of 1 (and a merge conflict to
test with)

  $ hg up -q 0
  $ echo blueberry > b
  $ hg l
  o  1 banana
  |
  @  0 apricot
  
  $ hg ci --amend -qAm 'apricot and blueberry'
  1 new orphan changesets
  $ hg l
  @  2 apricot and blueberry
  
  *  1 banana
  |
  x  0 apricot
  

  $ hg evolve --update --config hooks.precommit=false --config ui.merge=:other
  move:[1] banana
  atop:[2] apricot and blueberry
  transaction abort!
  rollback completed
  abort: precommit hook exited with status 1
  [255]
  $ hg l
  @  2 apricot and blueberry
  
  *  1 banana
  |
  x  0 apricot
  
  $ cat b
  banana

  $ hg status --config commands.status.verbose=True
  M b
  # The repository is in an unfinished *evolve* state.
  
  # No unresolved merge conflicts.
  
  # To continue:    hg evolve --continue
  # To abort:       hg evolve --abort
  # To stop:        hg evolve --stop
  # (also see `hg help evolve.interrupted`)
  

  $ ls .hg/evolvestate
  .hg/evolvestate

  $ cat b
  banana

  $ hg l
  @  2 apricot and blueberry
  
  *  1 banana
  |
  x  0 apricot
  

Test various methods of handling that unfinished state
  $ hg evolve --abort
  evolve aborted
  working directory is now at e1989e4b1526
  $ ls .hg/evolvestate
  ls: cannot access '?.hg/evolvestate'?: No such file or directory (re)
  [2]
  $ cat b
  blueberry
  $ hg l
  @  2 apricot and blueberry
  
  *  1 banana
  |
  x  0 apricot
  

  $ hg evolve --update --config hooks.precommit=false --config ui.merge=:other
  move:[1] banana
  atop:[2] apricot and blueberry
  transaction abort!
  rollback completed
  abort: precommit hook exited with status 1
  [255]
  $ cat b
  banana
  $ hg evolve --stop
  stopped the interrupted evolve
  working directory is now at e1989e4b1526
  $ cat .hg/evolvestate
  cat: .hg/evolvestate: No such file or directory
  [1]
  $ cat b
  blueberry
  $ hg l
  @  2 apricot and blueberry
  
  *  1 banana
  |
  x  0 apricot
  

  $ hg evolve --update --config hooks.precommit=false --config ui.merge=:other
  move:[1] banana
  atop:[2] apricot and blueberry
  transaction abort!
  rollback completed
  abort: precommit hook exited with status 1
  [255]
  $ hg evolve --continue
  evolving 1:e0486f65907d "banana"
  working directory is now at bd5ec7dfc2af
  $ cat .hg/evolvestate
  cat: .hg/evolvestate: No such file or directory
  [1]
  $ cat b
  banana
  $ hg l
  @  3 banana
  |
  o  2 apricot and blueberry