2018-01-03 22:51:20 +03:00
|
|
|
# no-check-code -- see T24862348
|
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
import test_hgsubversion_util
|
2013-08-08 11:22:10 +04:00
|
|
|
|
|
|
|
import errno
|
|
|
|
|
|
|
|
from mercurial import commands
|
|
|
|
from mercurial import context
|
|
|
|
from mercurial import hg
|
|
|
|
from mercurial import node
|
|
|
|
|
2018-01-11 03:20:54 +03:00
|
|
|
from hgext.hgsubversion import compathacks
|
2014-02-03 10:55:56 +04:00
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
class TestSingleDirPush(test_hgsubversion_util.TestBase):
|
2013-08-10 01:46:01 +04:00
|
|
|
stupid_mode_tests = True
|
2013-08-09 21:30:25 +04:00
|
|
|
obsolete_mode_tests = True
|
|
|
|
|
2013-08-08 11:22:10 +04:00
|
|
|
def test_push_single_dir(self):
|
|
|
|
# Tests simple pushing from default branch to a single dir repo
|
|
|
|
repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
|
|
|
|
layout='single',
|
|
|
|
subdir='')
|
|
|
|
def file_callback(repo, memctx, path):
|
|
|
|
if path == 'adding_file':
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data='foo',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
elif path == 'adding_binary':
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data='\0binary',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
|
|
|
|
ctx = context.memctx(repo,
|
|
|
|
(repo['tip'].node(), node.nullid),
|
|
|
|
'automated test',
|
|
|
|
['adding_file', 'adding_binary'],
|
|
|
|
file_callback,
|
|
|
|
'an_author',
|
|
|
|
'2009-10-19 18:49:30 -0500',
|
|
|
|
{'branch': 'default', })
|
|
|
|
repo.commitctx(ctx)
|
|
|
|
hg.update(repo, repo['tip'].node())
|
|
|
|
self.pushrevisions()
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertTrue('adding_file' in test_hgsubversion_util.svnls(repo_path, ''))
|
2013-08-08 11:22:10 +04:00
|
|
|
self.assertEqual('application/octet-stream',
|
2018-01-17 14:23:44 +03:00
|
|
|
test_hgsubversion_util.svnpropget(repo_path, 'adding_binary',
|
2013-08-08 11:22:10 +04:00
|
|
|
'svn:mime-type'))
|
|
|
|
# Now add another commit and test mime-type being reset
|
|
|
|
changes = [('adding_binary', 'adding_binary', 'no longer binary')]
|
|
|
|
self.commitchanges(changes)
|
|
|
|
self.pushrevisions()
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertEqual('', test_hgsubversion_util.svnpropget(repo_path, 'adding_binary',
|
2013-08-08 11:22:10 +04:00
|
|
|
'svn:mime-type'))
|
|
|
|
|
|
|
|
def test_push_single_dir_at_subdir(self):
|
|
|
|
repo = self._load_fixture_and_fetch('branch_from_tag.svndump',
|
|
|
|
layout='single',
|
|
|
|
subdir='trunk')
|
|
|
|
def filectxfn(repo, memctx, path):
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data='contents of %s' % path,
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
ctx = context.memctx(repo,
|
|
|
|
(repo['tip'].node(), node.nullid),
|
|
|
|
'automated test',
|
|
|
|
['bogus'],
|
|
|
|
filectxfn,
|
|
|
|
'an_author',
|
|
|
|
'2009-10-19 18:49:30 -0500',
|
|
|
|
{'branch': 'localhacking', })
|
2018-01-03 22:51:00 +03:00
|
|
|
# Why is this here? Revisit! T24862348
|
|
|
|
repo.commitctx(ctx)
|
2013-08-08 11:22:10 +04:00
|
|
|
self.assertEqual(self.repo['tip']['bogus'].data(),
|
|
|
|
'contents of bogus')
|
|
|
|
before = repo['tip'].hex()
|
|
|
|
hg.update(repo, self.repo['tip'].hex())
|
|
|
|
self.pushrevisions()
|
|
|
|
self.assertNotEqual(before, self.repo['tip'].hex())
|
|
|
|
self.assertEqual(self.repo['tip']['bogus'].data(),
|
|
|
|
'contents of bogus')
|
|
|
|
|
|
|
|
def test_push_single_dir_one_incoming_and_two_outgoing(self):
|
|
|
|
# Tests simple pushing from default branch to a single dir repo
|
|
|
|
# Pushes two outgoing over one incoming svn rev
|
|
|
|
# (used to cause an "unknown revision")
|
|
|
|
# This can happen if someone committed to svn since our last pull (race).
|
|
|
|
repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
|
|
|
|
layout='single',
|
|
|
|
subdir='trunk')
|
|
|
|
self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'})
|
|
|
|
def file_callback(repo, memctx, path):
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data='data of %s' % path,
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
for fn in ['one', 'two']:
|
|
|
|
ctx = context.memctx(repo,
|
|
|
|
(repo['tip'].node(), node.nullid),
|
|
|
|
'automated test',
|
|
|
|
[fn],
|
|
|
|
file_callback,
|
|
|
|
'an_author',
|
|
|
|
'2009-10-19 18:49:30 -0500',
|
|
|
|
{'branch': 'default', })
|
|
|
|
repo.commitctx(ctx)
|
|
|
|
hg.update(repo, repo['tip'].node())
|
|
|
|
self.pushrevisions(expected_extra_back=1)
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertTrue('trunk/one' in test_hgsubversion_util.svnls(repo_path, ''))
|
|
|
|
self.assertTrue('trunk/two' in test_hgsubversion_util.svnls(repo_path, ''))
|
2013-08-08 11:22:10 +04:00
|
|
|
|
|
|
|
def test_push_single_dir_branch(self):
|
|
|
|
# Tests local branches pushing to a single dir repo. Creates a fork at
|
|
|
|
# tip. The default branch adds a file called default, while branch foo
|
|
|
|
# adds a file called foo, then tries to push the foo branch and default
|
|
|
|
# branch in that order.
|
|
|
|
repo, repo_path = self.load_and_fetch('branch_from_tag.svndump',
|
|
|
|
layout='single',
|
|
|
|
subdir='')
|
|
|
|
def file_callback(data):
|
|
|
|
def cb(repo, memctx, path):
|
|
|
|
if path == data:
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data=data,
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
|
|
|
|
return cb
|
|
|
|
|
|
|
|
def commit_to_branch(name, parent):
|
|
|
|
repo.commitctx(context.memctx(repo,
|
|
|
|
(parent, node.nullid),
|
|
|
|
'automated test (%s)' % name,
|
|
|
|
[name],
|
|
|
|
file_callback(name),
|
|
|
|
'an_author',
|
|
|
|
'2009-10-19 18:49:30 -0500',
|
|
|
|
{'branch': name, }))
|
|
|
|
|
|
|
|
parent = repo['tip'].node()
|
|
|
|
commit_to_branch('default', parent)
|
|
|
|
commit_to_branch('foo', parent)
|
|
|
|
hg.update(repo, repo['foo'].node())
|
|
|
|
self.pushrevisions()
|
|
|
|
repo = self.repo # repo is outdated after the rebase happens, refresh
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertTrue('foo' in test_hgsubversion_util.svnls(repo_path, ''))
|
2014-02-03 10:55:56 +04:00
|
|
|
self.assertEqual(compathacks.branchset(repo), set(['default']))
|
2013-08-08 11:22:10 +04:00
|
|
|
# Have to cross to another branch head, so hg.update doesn't work
|
2015-07-09 02:45:04 +03:00
|
|
|
commands.update(self.ui(),
|
2013-08-08 11:22:10 +04:00
|
|
|
self.repo,
|
|
|
|
self.repo.branchheads('default')[1],
|
|
|
|
clean=True)
|
|
|
|
self.pushrevisions()
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertTrue('default' in test_hgsubversion_util.svnls(repo_path, ''))
|
2013-08-08 11:22:10 +04:00
|
|
|
self.assertEquals(len(self.repo.branchheads('default')), 1)
|
|
|
|
|
2018-01-17 14:23:44 +03:00
|
|
|
@test_hgsubversion_util.requiresoption('branch')
|
2013-08-10 01:46:01 +04:00
|
|
|
def test_push_single_dir_renamed_branch(self):
|
2013-08-08 11:22:10 +04:00
|
|
|
# Tests pulling and pushing with a renamed branch
|
|
|
|
# Based on test_push_single_dir
|
|
|
|
repo_path = self.load_svndump('branch_from_tag.svndump')
|
2015-08-11 23:56:37 +03:00
|
|
|
cmd = ['clone', '--quiet', '--layout=single', '--branch=flaf']
|
2013-08-10 01:46:01 +04:00
|
|
|
if self.stupid:
|
2013-08-08 11:22:10 +04:00
|
|
|
cmd.append('--stupid')
|
2018-01-17 14:23:44 +03:00
|
|
|
cmd += [test_hgsubversion_util.fileurl(repo_path), self.wc_path]
|
|
|
|
test_hgsubversion_util.dispatch(cmd)
|
2013-08-08 11:22:10 +04:00
|
|
|
|
|
|
|
def file_callback(repo, memctx, path):
|
|
|
|
if path == 'adding_file':
|
2014-06-03 04:57:07 +04:00
|
|
|
return compathacks.makememfilectx(repo,
|
2017-12-20 01:29:55 +03:00
|
|
|
memctx=memctx,
|
2014-06-03 04:57:07 +04:00
|
|
|
path=path,
|
|
|
|
data='foo',
|
|
|
|
islink=False,
|
|
|
|
isexec=False,
|
|
|
|
copied=False)
|
2013-08-08 11:22:10 +04:00
|
|
|
raise IOError(errno.EINVAL, 'Invalid operation: ' + path)
|
2017-10-29 04:34:52 +03:00
|
|
|
lr = self.repo
|
|
|
|
ctx = context.memctx(lr,
|
|
|
|
(lr['tip'].node(), node.nullid),
|
2013-08-08 11:22:10 +04:00
|
|
|
'automated test',
|
|
|
|
['adding_file'],
|
|
|
|
file_callback,
|
|
|
|
'an_author',
|
|
|
|
'2009-10-19 18:49:30 -0500',
|
|
|
|
{'branch': 'default', })
|
2017-10-29 04:34:52 +03:00
|
|
|
lr.commitctx(ctx)
|
2013-08-08 11:22:10 +04:00
|
|
|
hg.update(self.repo, self.repo['tip'].node())
|
|
|
|
self.pushrevisions()
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertTrue('adding_file' in test_hgsubversion_util.svnls(repo_path, ''))
|
2013-08-08 11:22:10 +04:00
|
|
|
|
|
|
|
self.assertEquals(set(['flaf']),
|
|
|
|
set(self.repo[i].branch() for i in self.repo))
|
2018-01-17 14:23:44 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import silenttestrunner
|
|
|
|
silenttestrunner.main(__name__)
|
|
|
|
|