| 1 |
# reproduce issue2264, issue2516 |
| 2 |
|
| 3 |
create test repo |
| 4 |
$ cat <<EOF >> $HGRCPATH |
| 5 |
> [extensions] |
| 6 |
> transplant = |
| 7 |
> EOF |
| 8 |
$ hg init repo |
| 9 |
$ cd repo |
| 10 |
$ template="{rev} {desc|firstline} [{branch}]\n" |
| 11 |
|
| 12 |
# we need to start out with two changesets on the default branch |
| 13 |
# in order to avoid the cute little optimization where transplant |
| 14 |
# pulls rather than transplants |
| 15 |
add initial changesets |
| 16 |
$ echo feature1 > file1 |
| 17 |
$ hg ci -Am"feature 1" |
| 18 |
adding file1 |
| 19 |
$ echo feature2 >> file2 |
| 20 |
$ hg ci -Am"feature 2" |
| 21 |
adding file2 |
| 22 |
|
| 23 |
# The changes to 'bugfix' are enough to show the bug: in fact, with only |
| 24 |
# those changes, it's a very noisy crash ("RuntimeError: nothing |
| 25 |
# committed after transplant"). But if we modify a second file in the |
| 26 |
# transplanted changesets, the bug is much more subtle: transplant |
| 27 |
# silently drops the second change to 'bugfix' on the floor, and we only |
| 28 |
# see it when we run 'hg status' after transplanting. Subtle data loss |
| 29 |
# bugs are worse than crashes, so reproduce the subtle case here. |
| 30 |
commit bug fixes on bug fix branch |
| 31 |
$ hg branch fixes |
| 32 |
marked working directory as branch fixes |
| 33 |
(branches are permanent and global, did you want a bookmark?) |
| 34 |
$ echo fix1 > bugfix |
| 35 |
$ echo fix1 >> file1 |
| 36 |
$ hg ci -Am"fix 1" |
| 37 |
adding bugfix |
| 38 |
$ echo fix2 > bugfix |
| 39 |
$ echo fix2 >> file1 |
| 40 |
$ hg ci -Am"fix 2" |
| 41 |
$ hg log -G --template="$template" |
| 42 |
@ 3 fix 2 [fixes] |
| 43 |
| |
| 44 |
o 2 fix 1 [fixes] |
| 45 |
| |
| 46 |
o 1 feature 2 [default] |
| 47 |
| |
| 48 |
o 0 feature 1 [default] |
| 49 |
|
| 50 |
transplant bug fixes onto release branch |
| 51 |
$ hg update 0 |
| 52 |
1 files updated, 0 files merged, 2 files removed, 0 files unresolved |
| 53 |
$ hg branch release |
| 54 |
marked working directory as branch release |
| 55 |
$ hg transplant 2 3 |
| 56 |
applying [0-9a-f]{12} (re) |
| 57 |
[0-9a-f]{12} transplanted to [0-9a-f]{12} (re) |
| 58 |
applying [0-9a-f]{12} (re) |
| 59 |
[0-9a-f]{12} transplanted to [0-9a-f]{12} (re) |
| 60 |
$ hg log -G --template="$template" |
| 61 |
@ 5 fix 2 [release] |
| 62 |
| |
| 63 |
o 4 fix 1 [release] |
| 64 |
| |
| 65 |
| o 3 fix 2 [fixes] |
| 66 |
| | |
| 67 |
| o 2 fix 1 [fixes] |
| 68 |
| | |
| 69 |
| o 1 feature 2 [default] |
| 70 |
|/ |
| 71 |
o 0 feature 1 [default] |
| 72 |
|
| 73 |
$ hg status |
| 74 |
$ hg status --rev 0:4 |
| 75 |
M file1 |
| 76 |
A bugfix |
| 77 |
$ hg status --rev 4:5 |
| 78 |
M bugfix |
| 79 |
M file1 |
| 80 |
|
| 81 |
now test that we fixed the bug for all scripts/extensions |
| 82 |
$ cat > $TESTTMP/committwice.py <<__EOF__ |
| 83 |
> import time |
| 84 |
> from mercurial import match, node, ui as uimod |
| 85 |
> from mercurial.repo import factory |
| 86 |
> |
| 87 |
> def replacebyte(fn, b): |
| 88 |
> f = open(fn, "rb+") |
| 89 |
> f.seek(0, 0) |
| 90 |
> f.write(b) |
| 91 |
> f.close() |
| 92 |
> |
| 93 |
> def printfiles(repo, rev): |
| 94 |
> repo.ui.status(b"revision %d files: [%s]\n" |
| 95 |
> % (rev, b', '.join(b"'%s'" % f |
| 96 |
> for f in repo[rev].files()))) |
| 97 |
> |
| 98 |
> repo = factory.repository(uimod.ui.load(), b'.') |
| 99 |
> assert len(repo) == 6, "initial: len(repo): %d, expected: 6" % len(repo) |
| 100 |
> |
| 101 |
> replacebyte(b"bugfix", b"u") |
| 102 |
> time.sleep(2) |
| 103 |
> try: |
| 104 |
> repo.ui.status(b"PRE: len(repo): %d\n" % len(repo)) |
| 105 |
> wlock = repo.wlock() |
| 106 |
> lock = repo.lock() |
| 107 |
> replacebyte(b"file1", b"x") |
| 108 |
> repo.commit(text=b"x", user=b"test", date=(0, 0)) |
| 109 |
> replacebyte(b"file1", b"y") |
| 110 |
> repo.commit(text=b"y", user=b"test", date=(0, 0)) |
| 111 |
> repo.ui.status(b"POST: len(repo): %d\n" % len(repo)) |
| 112 |
> finally: |
| 113 |
> lock.release() |
| 114 |
> wlock.release() |
| 115 |
> printfiles(repo, 6) |
| 116 |
> printfiles(repo, 7) |
| 117 |
> __EOF__ |
| 118 |
$ "$PYTHON" $TESTTMP/committwice.py |
| 119 |
PRE: len(repo): 6 |
| 120 |
POST: len(repo): 8 |
| 121 |
revision 6 files: ['bugfix', 'file1'] |
| 122 |
revision 7 files: ['file1'] |
| 123 |
|
| 124 |
Do a size-preserving modification outside of that process |
| 125 |
$ echo abcd > bugfix |
| 126 |
$ hg status |
| 127 |
M bugfix |
| 128 |
$ hg log --template "{rev} {desc} {files}\n" -r5: |
| 129 |
5 fix 2 bugfix file1 |
| 130 |
6 x bugfix file1 |
| 131 |
7 y file1 |
| 132 |
|
| 133 |
$ cd .. |