3

I ran into a situation in Mercurial at work where I would expect a file to exist, but it doesn't and I'd like to better understand why. I've put together a repro of the issue. In this repro I would expect the file foo.txt to exist on default after the final merge, since one parent of the merge does not have the file present because it was removed earlier, and the other parent is adding it back because of a commit that happened after the commit that removed the file. Instead, the file remains deleted, why?

Here's an image of the sequence of commits:

Repository with commits repro'ing the issue

And here's the actual commands to go from an empty directory, to having a Mercurial repo in this state.

hg init

echo foo > foo.txt
echo bar > bar.txt
hg add foo.txt bar.txt
hg commit -m "Add foo.txt and bar.txt"

hg branch feature
hg remove foo.txt
hg commit -m "Remove foo.txt"

echo barbar > bar.txt
hg commit -m "Modify bar.txt"

hg update default
echo baz > baz.txt
hg add baz.txt
hg commit -m "Add baz.txt"

hg update feature
hg merge default
hg commit -m "Merge default"

echo foo > foo.txt
hg add foo.txt
hg commit -m "Restore foo.txt"

hg update default
echo bazbaz > baz.txt
hg commit -m "Modify baz.txt"

hg update 0
hg merge 2
hg commit -m "Merge feature"

hg merge
hg commit -m "Merge"

hg merge feature
hg commit -m "Merge feature"   

State of the working directory after the final merge:

> ls
bar.txt  baz.txt

EDIT: This appears to affect hg versions 5.9.3 and 6.3.2 but not 5.0.2

EDIT: Based on discussion on the libera.chat #mercurial channel, modifying the sequence of commands in the repro to include an edit to the file after its creation does not change the outcome. foo.txt is still not present. https://gist.github.com/OneGeek/6fa5dcd4c2b3db6649310de1167449f9

Bjartr
  • 492
  • 3
  • 18

1 Answers1

0

I just pasted the steps from the repro into a terminal here and tried it (twice), and it doesn't reproduce the problem as described: foo.txt exists.

The end result is a working directory that has:

C:\Users\abcde\source\test>dir
...
 Directory of C:\Users\abcde\source\test

01/29/2023  04:08 PM    <DIR>          .
01/29/2023  04:07 PM    <DIR>          ..
01/29/2023  04:08 PM    <DIR>          .hg
01/29/2023  04:07 PM                 0 .hgignore
01/29/2023  04:08 PM                 9 bar.txt
01/29/2023  04:08 PM                 9 baz.txt
01/29/2023  04:08 PM                 6 foo.txt
               4 File(s)             24 bytes

The graph in THG looks the same as in the question.

I happen to be using HG 5.0.2 on Windows.

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
  • 1
    No that's strange. I've just run the sequence again in an empty directory and, copying directly out of my question, pasted into a cmd prompt (Windows 11). I've tried the HG 5.9 I had installed. I upgraded to the current HG6.3.2 and tried again. Still no foo.txt present afterwards. However, installing HG 5.0.2 and running the sequence does result in foo.txt being present. So the question is which behavior is correct and why? – Bjartr Jan 30 '23 at 14:32
  • Fascinating... I thought what 5.0.2 and what you expected seemed reasonable. Maybe the change was documented but there are an awful lot of updates since then... https://www.mercurial-scm.org/wiki/WhatsNew#Mercurial_5.0.2 I only had such an old version because it happened to be a PC I use rarely. – StayOnTarget Jan 30 '23 at 17:42
  • HG 6.2.3 on another Windows PC does the same thing as in the question. – StayOnTarget Jan 30 '23 at 17:44
  • Just to note: I even can't get (after dumb copy-paste of repro) DAG-tree from question - 2 final merges are silently missing (THG 6.3.2) – Lazy Badger Jan 31 '23 at 01:47
  • And after hand-merges I see **missing** foo.txt also – Lazy Badger Jan 31 '23 at 01:53
  • 2
    @LazyBadger , StackOverflow puts the commands into a scrollable text box but doesn't make it apparent, the merges you missed are only visible if you scroll it down. – Bjartr Jan 31 '23 at 16:48
  • @Bjartr - ACK, re-played the game fully with the same as hand-made result - no foo.txt – Lazy Badger Feb 02 '23 at 17:05