annotate tests/test-commit-multiple.t @ 17007:21e18c608b68

scmutil: change canonpath to use util.samefile (issue2167) Fixes (on Windows in cmd.exe): $ hg -R v:\x\a status V:\x\a\bar abort: V:\x\a\bar not under root where v:\x\a is a valid repository with a checked-out file "bar" (Note the difference in casing: "v:\" versus "V:\")
author Adrian Buehlmann <adrian@cadifra.com>
date Thu, 14 Jun 2012 11:43:48 +0200
parents f2719b387380
children aa9385f983fa
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
1 # reproduce issue2264, issue2516
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
2
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
3 create test repo
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
4 $ cat <<EOF >> $HGRCPATH
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
5 > [extensions]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
6 > transplant =
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
7 > graphlog =
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
8 > EOF
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
9 $ hg init repo
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
10 $ cd repo
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
11 $ template="{rev} {desc|firstline} [{branch}]\n"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
12
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
13 # we need to start out with two changesets on the default branch
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
14 # in order to avoid the cute little optimization where transplant
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
15 # pulls rather than transplants
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
16 add initial changesets
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
17 $ echo feature1 > file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
18 $ hg ci -Am"feature 1"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
19 adding file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
20 $ echo feature2 >> file2
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
21 $ hg ci -Am"feature 2"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
22 adding file2
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
23
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
24 # The changes to 'bugfix' are enough to show the bug: in fact, with only
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
25 # those changes, it's a very noisy crash ("RuntimeError: nothing
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
26 # committed after transplant"). But if we modify a second file in the
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
27 # transplanted changesets, the bug is much more subtle: transplant
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
28 # silently drops the second change to 'bugfix' on the floor, and we only
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
29 # see it when we run 'hg status' after transplanting. Subtle data loss
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
30 # bugs are worse than crashes, so reproduce the subtle case here.
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
31 commit bug fixes on bug fix branch
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
32 $ hg branch fixes
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
33 marked working directory as branch fixes
15615
41885892796e branch: warn on branching
Matt Mackall <mpm@selenic.com>
parents: 13749
diff changeset
34 (branches are permanent and global, did you want a bookmark?)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
35 $ echo fix1 > bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
36 $ echo fix1 >> file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
37 $ hg ci -Am"fix 1"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
38 adding bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
39 $ echo fix2 > bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
40 $ echo fix2 >> file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
41 $ hg ci -Am"fix 2"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
42 $ hg glog --template="$template"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
43 @ 3 fix 2 [fixes]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
44 |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
45 o 2 fix 1 [fixes]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
46 |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
47 o 1 feature 2 [default]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
48 |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
49 o 0 feature 1 [default]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
50
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
51 transplant bug fixes onto release branch
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
52 $ hg update 0
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
53 1 files updated, 0 files merged, 2 files removed, 0 files unresolved
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
54 $ hg branch release
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
55 marked working directory as branch release
15615
41885892796e branch: warn on branching
Matt Mackall <mpm@selenic.com>
parents: 13749
diff changeset
56 (branches are permanent and global, did you want a bookmark?)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
57 $ hg transplant 2 3
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
58 applying [0-9a-f]{12} (re)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
59 [0-9a-f]{12} transplanted to [0-9a-f]{12} (re)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
60 applying [0-9a-f]{12} (re)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
61 [0-9a-f]{12} transplanted to [0-9a-f]{12} (re)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
62 $ hg glog --template="$template"
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
63 @ 5 fix 2 [release]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
64 |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
65 o 4 fix 1 [release]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
66 |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
67 | o 3 fix 2 [fixes]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
68 | |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
69 | o 2 fix 1 [fixes]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
70 | |
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
71 | o 1 feature 2 [default]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
72 |/
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
73 o 0 feature 1 [default]
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
74
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
75 $ hg status
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
76 $ hg status --rev 0:4
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
77 M file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
78 A bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
79 $ hg status --rev 4:5
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
80 M bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
81 M file1
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
82
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
83 now test that we fixed the bug for all scripts/extensions
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
84 $ cat > $TESTTMP/committwice.py <<__EOF__
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
85 > from mercurial import ui, hg, match, node
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
86 > from time import sleep
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
87 >
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
88 > def replacebyte(fn, b):
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
89 > f = open(fn, "rb+")
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
90 > f.seek(0, 0)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
91 > f.write(b)
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
92 > f.close()
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
93 >
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
94 > def printfiles(repo, rev):
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
95 > print "revision %s files: %s" % (rev, repo[rev].files())
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
96 >
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
97 > repo = hg.repository(ui.ui(), '.')
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
98 > assert len(repo) == 6, \
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
99 > "initial: len(repo): %d, expected: 6" % len(repo)
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
100 >
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
101 > replacebyte("bugfix", "u")
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
102 > sleep(2)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
103 > try:
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
104 > print "PRE: len(repo): %d" % len(repo)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
105 > wlock = repo.wlock()
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
106 > lock = repo.lock()
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
107 > replacebyte("file1", "x")
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
108 > repo.commit(text="x", user="test", date=(0, 0))
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
109 > replacebyte("file1", "y")
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
110 > repo.commit(text="y", user="test", date=(0, 0))
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
111 > print "POST: len(repo): %d" % len(repo)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
112 > finally:
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
113 > lock.release()
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
114 > wlock.release()
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
115 > printfiles(repo, 6)
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
116 > printfiles(repo, 7)
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
117 > __EOF__
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
118 $ $PYTHON $TESTTMP/committwice.py
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
119 PRE: len(repo): 6
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
120 POST: len(repo): 8
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
121 revision 6 files: ['bugfix', 'file1']
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
122 revision 7 files: ['file1']
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
123
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
124 Do a size-preserving modification outside of that process
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
125 $ echo abcd > bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
126 $ hg status
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
127 M bugfix
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
128 $ hg log --template "{rev} {desc} {files}\n" -r5:
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
129 5 fix 2 bugfix file1
13749
8bb03283e9b9 test-commit-multiple.t: improve committwice.py
Adrian Buehlmann <adrian@cadifra.com>
parents: 13704
diff changeset
130 6 x bugfix file1
13704
a464763e99f1 dirstate: avoid a race with multiple commits in the same process
Greg Ward <greg@gerg.ca>
parents:
diff changeset
131 7 y file1
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 15615
diff changeset
132
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 15615
diff changeset
133 $ cd ..