comparison tests/test_single_dir_push.py @ 1106:5cb6c95e0283 stable

Merge default and stable so I can do stable releases again.
author Augie Fackler <raf@durin42.com>
date Tue, 11 Feb 2014 12:48:49 -0500
parents 6e1dbf6cbc92
children f1dd304be8aa
comparison
equal deleted inserted replaced
1020:b5b1fce26f1f 1106:5cb6c95e0283
1 import test_util
2
3 import errno
4 import shutil
5 import unittest
6
7 from mercurial import commands
8 from mercurial import context
9 from mercurial import hg
10 from mercurial import node
11 from mercurial import ui
12
13 from hgsubversion import compathacks
14
15 class TestSingleDirPush(test_util.TestBase):
16 stupid_mode_tests = True
17 obsolete_mode_tests = True
18
19 def test_push_single_dir(self):
20 # Tests simple pushing from default branch to a single dir repo
21 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
22 layout='single',
23 subdir='')
24 def file_callback(repo, memctx, path):
25 if path == 'adding_file':
26 return context.memfilectx(path=path,
27 data='foo',
28 islink=False,
29 isexec=False,
30 copied=False)
31 elif path == 'adding_binary':
32 return context.memfilectx(path=path,
33 data='\0binary',
34 islink=False,
35 isexec=False,
36 copied=False)
37 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
38 ctx = context.memctx(repo,
39 (repo['tip'].node(), node.nullid),
40 'automated test',
41 ['adding_file', 'adding_binary'],
42 file_callback,
43 'an_author',
44 '2009-10-19 18:49:30 -0500',
45 {'branch': 'default', })
46 repo.commitctx(ctx)
47 hg.update(repo, repo['tip'].node())
48 self.pushrevisions()
49 self.assertTrue('adding_file' in test_util.svnls(repo_path, ''))
50 self.assertEqual('application/octet-stream',
51 test_util.svnpropget(repo_path, 'adding_binary',
52 'svn:mime-type'))
53 # Now add another commit and test mime-type being reset
54 changes = [('adding_binary', 'adding_binary', 'no longer binary')]
55 self.commitchanges(changes)
56 self.pushrevisions()
57 self.assertEqual('', test_util.svnpropget(repo_path, 'adding_binary',
58 'svn:mime-type'))
59
60 def test_push_single_dir_at_subdir(self):
61 repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
62 layout='single',
63 subdir='trunk')
64 def filectxfn(repo, memctx, path):
65 return context.memfilectx(path=path,
66 data='contents of %s' % path,
67 islink=False,
68 isexec=False,
69 copied=False)
70 ctx = context.memctx(repo,
71 (repo['tip'].node(), node.nullid),
72 'automated test',
73 ['bogus'],
74 filectxfn,
75 'an_author',
76 '2009-10-19 18:49:30 -0500',
77 {'branch': 'localhacking', })
78 n = repo.commitctx(ctx)
79 self.assertEqual(self.repo['tip']['bogus'].data(),
80 'contents of bogus')
81 before = repo['tip'].hex()
82 hg.update(repo, self.repo['tip'].hex())
83 self.pushrevisions()
84 self.assertNotEqual(before, self.repo['tip'].hex())
85 self.assertEqual(self.repo['tip']['bogus'].data(),
86 'contents of bogus')
87
88 def test_push_single_dir_one_incoming_and_two_outgoing(self):
89 # Tests simple pushing from default branch to a single dir repo
90 # Pushes two outgoing over one incoming svn rev
91 # (used to cause an "unknown revision")
92 # This can happen if someone committed to svn since our last pull (race).
93 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
94 layout='single',
95 subdir='trunk')
96 self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
97 def file_callback(repo, memctx, path):
98 return context.memfilectx(path=path,
99 data='data of %s' % path,
100 islink=False,
101 isexec=False,
102 copied=False)
103 for fn in ['one', 'two']:
104 ctx = context.memctx(repo,
105 (repo['tip'].node(), node.nullid),
106 'automated test',
107 [fn],
108 file_callback,
109 'an_author',
110 '2009-10-19 18:49:30 -0500',
111 {'branch': 'default', })
112 repo.commitctx(ctx)
113 hg.update(repo, repo['tip'].node())
114 self.pushrevisions(expected_extra_back=1)
115 self.assertTrue('trunk/one' in test_util.svnls(repo_path, ''))
116 self.assertTrue('trunk/two' in test_util.svnls(repo_path, ''))
117
118 def test_push_single_dir_branch(self):
119 # Tests local branches pushing to a single dir repo. Creates a fork at
120 # tip. The default branch adds a file called default, while branch foo
121 # adds a file called foo, then tries to push the foo branch and default
122 # branch in that order.
123 repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
124 layout='single',
125 subdir='')
126 def file_callback(data):
127 def cb(repo, memctx, path):
128 if path == data:
129 return context.memfilectx(path=path,
130 data=data,
131 islink=False,
132 isexec=False,
133 copied=False)
134 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
135 return cb
136
137 def commit_to_branch(name, parent):
138 repo.commitctx(context.memctx(repo,
139 (parent, node.nullid),
140 'automated test (%s)' % name,
141 [name],
142 file_callback(name),
143 'an_author',
144 '2009-10-19 18:49:30 -0500',
145 {'branch': name, }))
146
147 parent = repo['tip'].node()
148 commit_to_branch('default', parent)
149 commit_to_branch('foo', parent)
150 hg.update(repo, repo['foo'].node())
151 self.pushrevisions()
152 repo = self.repo # repo is outdated after the rebase happens, refresh
153 self.assertTrue('foo' in test_util.svnls(repo_path, ''))
154 self.assertEqual(compathacks.branchset(repo), set(['default']))
155 # Have to cross to another branch head, so hg.update doesn't work
156 commands.update(ui.ui(),
157 self.repo,
158 self.repo.branchheads('default')[1],
159 clean=True)
160 self.pushrevisions()
161 self.assertTrue('default' in test_util.svnls(repo_path, ''))
162 self.assertEquals(len(self.repo.branchheads('default')), 1)
163
164 @test_util.requiresoption('branch')
165 def test_push_single_dir_renamed_branch(self):
166 # Tests pulling and pushing with a renamed branch
167 # Based on test_push_single_dir
168 repo_path = self.load_svndump('branch_from_tag.svndump')
169 cmd = ['clone', '--layout=single', '--branch=flaf']
170 if self.stupid:
171 cmd.append('--stupid')
172 cmd += [test_util.fileurl(repo_path), self.wc_path]
173 test_util.dispatch(cmd)
174
175 def file_callback(repo, memctx, path):
176 if path == 'adding_file':
177 return context.memfilectx(path=path,
178 data='foo',
179 islink=False,
180 isexec=False,
181 copied=False)
182 raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
183 ctx = context.memctx(self.repo,
184 (self.repo['tip'].node(), node.nullid),
185 'automated test',
186 ['adding_file'],
187 file_callback,
188 'an_author',
189 '2009-10-19 18:49:30 -0500',
190 {'branch': 'default', })
191 self.repo.commitctx(ctx)
192 hg.update(self.repo, self.repo['tip'].node())
193 self.pushrevisions()
194 self.assertTrue('adding_file' in test_util.svnls(repo_path, ''))
195
196 self.assertEquals(set(['flaf']),
197 set(self.repo[i].branch() for i in self.repo))