0

The following sequence of commands requires that the Mercurial Queues exension be enabled, and also the Evolve extension (for hg amend, alias hg refresh).

This combination of commands messes up the existing Mercurial queue, making the commit corresponding to the pushed patch obsolete, and creating a new commit with exactly the same contents.

This error is in theory quite easy to make: just type hg ref instead of hg qref, but I just made it recently after using Mercurial Queues for years. Regardless, I haven't figured out a clean way to fix this and get back the original state.

Note that a simple hg rollback does work in my example, but I'm not sure it will work in my case, because I've tried other things trying to fix this. In any case, hg rollback isn't something one should rely on. In summary, how do I undo the hg amend and get back my applied MQ patch?

#!/bin/sh                                                                                                                                                                

hg init test
cd test
echo "This is foo" >> foo
hg add
hg ci -m "Add foo"
hg init --mq
echo "Line 2 of foo" >> foo
hg qnew p
hg ci --mq -m "Add patch p"
hg ref


hg log -vG --hidden
@  changeset:   2:f7f038d3aab5
|  tag:         tip
|  parent:      0:9d3a95922194
|  user:        Faheem Mitha <faheem@faheem.info>
|  date:        Sun Mar 11 16:38:51 2018 +0530
|  files:       foo
|  description:
|  [mq]: p
|
|
| x  changeset:   1:e467a2433c7f
|/   tag:         p
|    tag:         qbase
|    tag:         qtip
|    user:        Faheem Mitha <faheem@faheem.info>
|    date:        Sun Mar 11 16:38:50 2018 +0530
|    obsolete:    rewritten using amend as 2:f7f038d3aab5 by Faheem Mitha <faheem@faheem.info> (at 2018-03-11 16:38 +0530)
|    obsolete:    rewritten by Faheem Mitha <faheem@faheem.info> as f7f038d3aab5 (at 2018-03-11 16:38 +0530)
|    files:       foo
|    description:
|    [mq]: p
|
|
o  changeset:   0:9d3a95922194
   tag:         qparent
   user:        Faheem Mitha <faheem@faheem.info>
   date:        Sun Mar 11 16:38:50 2018 +0530
   files:       foo
   description:
   Add foo
Faheem Mitha
  • 6,096
  • 7
  • 48
  • 83

1 Answers1

1

That's not what I get with your test case. I need an additional

echo "Line 3" >> foo

before the hg ref. Also, versioning your mq seems irrelevant here; I think you can remove the hg init --mq and hg ci --mq lines.

hg amend really ought to block that. But if you wanted to manually fix things up, edit .hg/patches/series and replace the obsolete hash with the successor's hash. (Just make sure to use the 20-byte hash, as is given by eg hg log -T '{node}\n').

Warning: when I tried that with your test case and qpopped, something mysteriously un-obsoleted the old head, and it gives a strange warning about the current directory not being a head (despite hg log -r 'head()' listing it.) But at least you have your queue back in a working state.

sfink
  • 1,726
  • 1
  • 17
  • 22
  • Thank you for the answer. Some comments... First I don't understand why you need an additional line in "foo". Can you doublecheck that? – Faheem Mitha Mar 15 '18 at 08:46
  • because if I don't, then `hg refresh` just says "nothing changed" (correctly). – sfink Mar 16 '18 at 16:44
  • To be specific, my reproduction case is `hg init test; cd test; echo line1 > foo; hg add foo; hg commit -m init; echo line2 >> foo; hg qnew mypatch; echo line3 >> foo; hg amend; hg qpop` – sfink Mar 16 '18 at 16:46
  • (and the corresponding fix would be to replace the last line of .hg/patches/status with the output of `hg log -r . -T '{node}:mypatch\n'`) – sfink Mar 16 '18 at 16:48