comparison tests/test_single_dir_clone.py @ 1047:3092b3c109a8

tests: split single directory tests that push & clone in two modules
author Dan Villiom Podlaski Christiansen <danchr@gmail.com>
date Thu, 08 Aug 2013 09:22:10 +0200
parents d741f536f23a
children 2668785264d7
comparison
equal deleted inserted replaced
1046:36fe4b316a6b 1047:3092b3c109a8
8 from mercurial import context 8 from mercurial import context
9 from mercurial import hg 9 from mercurial import hg
10 from mercurial import node 10 from mercurial import node
11 from mercurial import ui 11 from mercurial import ui
12 12
13 class TestSingleDir(test_util.TestBase): 13 class TestSingleDirClone(test_util.TestBase):
14 def test_clone_single_dir_simple(self): 14 def test_clone_single_dir_simple(self):
15 repo = self._load_fixture_and_fetch('branch_from_tag.svndump', 15 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
16 stupid=False, 16 stupid=False,
17 layout='single', 17 layout='single',
18 subdir='') 18 subdir='')
84 assert '[.]' not in extdata 84 assert '[.]' not in extdata
85 print extdata 85 print extdata
86 expect = '' # Not honestly sure what this should be... 86 expect = '' # Not honestly sure what this should be...
87 test = 4 87 test = 4
88 self.assertEqual(self.repo[test]['.hgsvnexternals'].data(), expect) 88 self.assertEqual(self.repo[test]['.hgsvnexternals'].data(), expect)
89
90 def test_push_single_dir(self):
91 # Tests simple pushing from default branch to a single dir repo
92 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
93 stupid=False,
94 layout='single',
95 subdir='')
96 def file_callback(repo, memctx, path):
97 if path == 'adding_file':
98 return context.memfilectx(path=path,
99 data='foo',
100 islink=False,
101 isexec=False,
102 copied=False)
103 elif path == 'adding_binary':
104 return context.memfilectx(path=path,
105 data='\0binary',
106 islink=False,
107 isexec=False,
108 copied=False)
109 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
110 ctx = context.memctx(repo,
111 (repo['tip'].node(), node.nullid),
112 'automated test',
113 ['adding_file', 'adding_binary'],
114 file_callback,
115 'an_author',
116 '2009-10-19 18:49:30 -0500',
117 {'branch': 'default', })
118 repo.commitctx(ctx)
119 hg.update(repo, repo['tip'].node())
120 self.pushrevisions()
121 self.assertTrue('adding_file' in test_util.svnls(repo_path, ''))
122 self.assertEqual('application/octet-stream',
123 test_util.svnpropget(repo_path, 'adding_binary',
124 'svn:mime-type'))
125 # Now add another commit and test mime-type being reset
126 changes = [('adding_binary', 'adding_binary', 'no longer binary')]
127 self.commitchanges(changes)
128 self.pushrevisions()
129 self.assertEqual('', test_util.svnpropget(repo_path, 'adding_binary',
130 'svn:mime-type'))
131
132 def test_push_single_dir_at_subdir(self):
133 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
134 stupid=False,
135 layout='single',
136 subdir='trunk')
137 def filectxfn(repo, memctx, path):
138 return context.memfilectx(path=path,
139 data='contents of %s' % path,
140 islink=False,
141 isexec=False,
142 copied=False)
143 ctx = context.memctx(repo,
144 (repo['tip'].node(), node.nullid),
145 'automated test',
146 ['bogus'],
147 filectxfn,
148 'an_author',
149 '2009-10-19 18:49:30 -0500',
150 {'branch': 'localhacking', })
151 n = repo.commitctx(ctx)
152 self.assertEqual(self.repo['tip']['bogus'].data(),
153 'contents of bogus')
154 before = repo['tip'].hex()
155 hg.update(repo, self.repo['tip'].hex())
156 self.pushrevisions()
157 self.assertNotEqual(before, self.repo['tip'].hex())
158 self.assertEqual(self.repo['tip']['bogus'].data(),
159 'contents of bogus')
160
161 def test_push_single_dir_one_incoming_and_two_outgoing(self):
162 # Tests simple pushing from default branch to a single dir repo
163 # Pushes two outgoing over one incoming svn rev
164 # (used to cause an "unknown revision")
165 # This can happen if someone committed to svn since our last pull (race).
166 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
167 stupid=False,
168 layout='single',
169 subdir='trunk')
170 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
171 def file_callback(repo, memctx, path):
172 return context.memfilectx(path=path,
173 data='data of %s' % path,
174 islink=False,
175 isexec=False,
176 copied=False)
177 for fn in ['one', 'two']:
178 ctx = context.memctx(repo,
179 (repo['tip'].node(), node.nullid),
180 'automated test',
181 [fn],
182 file_callback,
183 'an_author',
184 '2009-10-19 18:49:30 -0500',
185 {'branch': 'default', })
186 repo.commitctx(ctx)
187 hg.update(repo, repo['tip'].node())
188 self.pushrevisions(expected_extra_back=1)
189 self.assertTrue('trunk/one' in test_util.svnls(repo_path, ''))
190 self.assertTrue('trunk/two' in test_util.svnls(repo_path, ''))
191
192 def test_push_single_dir_branch(self):
193 # Tests local branches pushing to a single dir repo. Creates a fork at
194 # tip. The default branch adds a file called default, while branch foo
195 # adds a file called foo, then tries to push the foo branch and default
196 # branch in that order.
197 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
198 stupid=False,
199 layout='single',
200 subdir='')
201 def file_callback(data):
202 def cb(repo, memctx, path):
203 if path == data:
204 return context.memfilectx(path=path,
205 data=data,
206 islink=False,
207 isexec=False,
208 copied=False)
209 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
210 return cb
211
212 def commit_to_branch(name, parent):
213 repo.commitctx(context.memctx(repo,
214 (parent, node.nullid),
215 'automated test (%s)' % name,
216 [name],
217 file_callback(name),
218 'an_author',
219 '2009-10-19 18:49:30 -0500',
220 {'branch': name, }))
221
222 parent = repo['tip'].node()
223 commit_to_branch('default', parent)
224 commit_to_branch('foo', parent)
225 hg.update(repo, repo['foo'].node())
226 self.pushrevisions()
227 repo = self.repo # repo is outdated after the rebase happens, refresh
228 self.assertTrue('foo' in test_util.svnls(repo_path, ''))
229 self.assertEqual(repo.branchtags().keys(), ['default'])
230 # Have to cross to another branch head, so hg.update doesn't work
231 commands.update(ui.ui(),
232 self.repo,
233 self.repo.branchheads('default')[1],
234 clean=True)
235 self.pushrevisions()
236 self.assertTrue('default' in test_util.svnls(repo_path, ''))
237 self.assertEquals(len(self.repo.branchheads('default')), 1)
238
239 @test_util.requiresoption('branch')
240 def test_push_single_dir_renamed_branch(self, stupid=False):
241 # Tests pulling and pushing with a renamed branch
242 # Based on test_push_single_dir
243 repo_path = self.load_svndump('branch_from_tag.svndump')
244 cmd = ['clone', '--layout=single', '--branch=flaf']
245 if stupid:
246 cmd.append('--stupid')
247 cmd += [test_util.fileurl(repo_path), self.wc_path]
248 test_util.dispatch(cmd)
249
250 def file_callback(repo, memctx, path):
251 if path == 'adding_file':
252 return context.memfilectx(path=path,
253 data='foo',
254 islink=False,
255 isexec=False,
256 copied=False)
257 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
258 ctx = context.memctx(self.repo,
259 (self.repo['tip'].node(), node.nullid),
260 'automated test',
261 ['adding_file'],
262 file_callback,
263 'an_author',
264 '2009-10-19 18:49:30 -0500',
265 {'branch': 'default', })
266 self.repo.commitctx(ctx)
267 hg.update(self.repo, self.repo['tip'].node())
268 self.pushrevisions()
269 self.assertTrue('adding_file' in test_util.svnls(repo_path, ''))
270
271 self.assertEquals(set(['flaf']),
272 set(self.repo[i].branch() for i in self.repo))
273
274 @test_util.requiresoption('branch')
275 def test_push_single_dir_renamed_branch_stupid(self):
276 self.test_push_single_dir_renamed_branch(True)