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
|
2010-07-14 17:39:18 +04:00
|
|
|
|
2008-11-29 20:25:01 +03:00
|
|
|
import unittest
|
|
|
|
|
2013-08-05 22:49:53 +04:00
|
|
|
from mercurial import error
|
2009-04-27 18:39:39 +04:00
|
|
|
from mercurial import hg
|
2008-12-10 23:29:05 +03:00
|
|
|
|
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 TestFetchBranches(test_hgsubversion_util.TestBase):
|
2013-08-10 01:45:54 +04:00
|
|
|
stupid_mode_tests = True
|
|
|
|
|
2009-04-27 18:39:39 +04:00
|
|
|
def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor):
|
2012-04-19 20:29:28 +04:00
|
|
|
repo_path = self.load_svndump(fixture_name)
|
2018-01-17 14:23:44 +03:00
|
|
|
source = '%s#%s' % (test_hgsubversion_util.fileurl(repo_path), anchor)
|
|
|
|
test_hgsubversion_util.hgclone(self.ui(), source, self.wc_path)
|
2010-02-26 16:50:22 +03:00
|
|
|
return hg.repository(self.ui(), self.wc_path)
|
2009-04-27 18:39:39 +04:00
|
|
|
|
2011-06-15 16:44:14 +04:00
|
|
|
def branches(self, repo):
|
2009-06-15 21:26:19 +04:00
|
|
|
hctxs = [repo[hn] for hn in repo.heads()]
|
2011-06-15 16:44:14 +04:00
|
|
|
openbranches = set(ctx.branch() for ctx in hctxs if
|
|
|
|
ctx.extra().get('close', None) != '1')
|
|
|
|
closedbranches = set(ctx.branch() for ctx in hctxs if
|
|
|
|
ctx.extra().get('close', None) == '1')
|
|
|
|
return sorted(openbranches), sorted(closedbranches)
|
|
|
|
|
|
|
|
def openbranches(self, repo):
|
|
|
|
return self.branches(repo)[0]
|
2009-05-29 15:41:28 +04:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_rename_branch_parent(self):
|
|
|
|
repo = self._load_fixture_and_fetch('rename_branch_parent_dir.svndump')
|
2010-02-06 22:01:35 +03:00
|
|
|
heads = [repo[n] for n in repo.heads()]
|
|
|
|
heads = dict([(ctx.branch(), ctx) for ctx in heads])
|
|
|
|
# Let these tests disabled yet as the fix is not obvious
|
|
|
|
self.assertEqual(['dev_branch'], self.openbranches(repo))
|
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_unrelatedbranch(self):
|
|
|
|
repo = self._load_fixture_and_fetch('unrelatedbranch.svndump')
|
2008-11-29 20:25:01 +03:00
|
|
|
heads = [repo[n] for n in repo.heads()]
|
|
|
|
heads = dict([(ctx.branch(), ctx) for ctx in heads])
|
|
|
|
# Let these tests disabled yet as the fix is not obvious
|
2008-11-29 20:25:01 +03:00
|
|
|
self.assertEqual(heads['branch1'].manifest().keys(), ['b'])
|
2016-06-27 00:02:12 +03:00
|
|
|
self.assertEqual(sorted(heads['branch2'].manifest().keys()),
|
|
|
|
['a', 'b'])
|
2008-11-29 20:25:01 +03:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_unorderedbranch(self):
|
|
|
|
repo = self._load_fixture_and_fetch('unorderedbranch.svndump')
|
2008-12-10 20:03:22 +03:00
|
|
|
r = repo['branch']
|
|
|
|
self.assertEqual(0, r.parents()[0].rev())
|
|
|
|
self.assertEqual(['a', 'c', 'z'], sorted(r.manifest()))
|
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_renamed_branch_to_trunk(self):
|
2013-11-17 21:57:00 +04:00
|
|
|
repo = self._load_fixture_and_fetch('branch_rename_to_trunk.svndump')
|
2009-03-03 08:54:14 +03:00
|
|
|
self.assertEqual(repo['default'].parents()[0].branch(), 'dev_branch')
|
2011-06-15 16:44:14 +04:00
|
|
|
self.assert_('iota' in repo['default'])
|
2008-12-10 23:29:05 +03:00
|
|
|
self.assertEqual(repo['old_trunk'].parents()[0].branch(), 'default')
|
2011-06-15 16:44:14 +04:00
|
|
|
self.assert_('iota' not in repo['old_trunk'])
|
2009-05-29 15:41:28 +04:00
|
|
|
expected = ['default', 'old_trunk']
|
|
|
|
self.assertEqual(self.openbranches(repo), expected)
|
2008-12-10 23:29:05 +03:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_replace_trunk_with_branch(self):
|
|
|
|
repo = self._load_fixture_and_fetch('replace_trunk_with_branch.svndump')
|
2008-12-21 04:04:59 +03:00
|
|
|
self.assertEqual(repo['default'].parents()[0].branch(), 'test')
|
2009-05-29 17:24:12 +04:00
|
|
|
self.assertEqual(repo['tip'].branch(), 'default')
|
|
|
|
self.assertEqual(repo['tip'].extra().get('close'), '1')
|
2009-05-29 15:41:28 +04:00
|
|
|
self.assertEqual(self.openbranches(repo), ['default'])
|
2008-12-21 04:04:59 +03:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_copybeforeclose(self):
|
|
|
|
repo = self._load_fixture_and_fetch('copybeforeclose.svndump')
|
2009-06-11 20:00:58 +04:00
|
|
|
self.assertEqual(repo['tip'].branch(), 'test')
|
|
|
|
self.assertEqual(repo['test'].extra().get('close'), '1')
|
|
|
|
self.assertEqual(repo['test']['b'].data(), 'a\n')
|
|
|
|
|
2013-11-17 21:57:00 +04:00
|
|
|
def test_copyafterclose(self):
|
|
|
|
repo = self._load_fixture_and_fetch('copyafterclose.svndump')
|
|
|
|
self.assertEqual(repo['tip'].branch(), 'test')
|
|
|
|
self.assert_('file' in repo['test'])
|
|
|
|
self.assertEqual(repo['test']['file'].data(), 'trunk2\n')
|
|
|
|
self.assert_('dir/file' in repo['test'])
|
|
|
|
self.assertEqual(repo['test']['dir/file'].data(), 'trunk2\n')
|
|
|
|
|
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_branch_create_with_dir_delete_works(self):
|
|
|
|
repo = self._load_fixture_and_fetch('branch_create_with_dir_delete.svndump')
|
2015-03-28 02:44:05 +03:00
|
|
|
self.assertEqual(sorted(repo['tip'].manifest().keys()),
|
|
|
|
['alpha', 'beta', 'gamma', 'iota', ])
|
2009-04-08 02:38:13 +04:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_branch_tip_update_to_default(self):
|
2009-04-25 05:36:38 +04:00
|
|
|
repo = self._load_fixture_and_fetch('unorderedbranch.svndump',
|
2013-08-10 01:45:54 +04:00
|
|
|
noupdate=False)
|
2009-04-25 05:36:38 +04:00
|
|
|
self.assertEqual(repo[None].branch(), 'default')
|
|
|
|
self.assertTrue('tip' not in repo[None].tags())
|
2009-05-14 06:39:39 +04:00
|
|
|
|
2009-05-20 23:15:47 +04:00
|
|
|
def test_branch_pull_anchor(self):
|
2013-08-05 22:49:53 +04:00
|
|
|
self.assertRaises(error.RepoLookupError,
|
2009-05-20 23:15:47 +04:00
|
|
|
self._load_fixture_and_fetch_with_anchor,
|
|
|
|
'unorderedbranch.svndump', 'NaN')
|
2009-04-27 18:39:39 +04:00
|
|
|
repo = self._load_fixture_and_fetch_with_anchor(
|
2009-05-20 23:15:47 +04:00
|
|
|
'unorderedbranch.svndump', '4')
|
2014-02-03 10:55:56 +04:00
|
|
|
self.assertTrue('c' not in compathacks.branchset(repo))
|
2009-04-25 05:36:38 +04:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_branches_weird_moves(self):
|
2012-04-19 20:29:25 +04:00
|
|
|
repo = self._load_fixture_and_fetch('renamedproject.svndump',
|
2009-05-04 06:42:42 +04:00
|
|
|
subdir='project')
|
|
|
|
heads = [repo[n] for n in repo.heads()]
|
|
|
|
heads = dict((ctx.branch(), ctx) for ctx in heads)
|
|
|
|
mdefault = sorted(heads['default'].manifest().keys())
|
|
|
|
mbranch = sorted(heads['branch'].manifest().keys())
|
|
|
|
self.assertEqual(mdefault, ['a', 'b', 'd/a'])
|
|
|
|
self.assertEqual(mbranch, ['a'])
|
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_branch_delete_parent_dir(self):
|
|
|
|
repo = self._load_fixture_and_fetch('branch_delete_parent_dir.svndump')
|
2011-06-15 16:44:14 +04:00
|
|
|
openb, closedb = self.branches(repo)
|
|
|
|
self.assertEqual(openb, [])
|
|
|
|
self.assertEqual(closedb, ['dev_branch'])
|
|
|
|
self.assertEqual(list(repo['dev_branch']), ['foo'])
|
2009-07-04 21:12:18 +04:00
|
|
|
|
2013-08-10 01:45:54 +04:00
|
|
|
def test_replace_branch_with_branch(self):
|
|
|
|
repo = self._load_fixture_and_fetch('replace_branch_with_branch.svndump')
|
2018-01-17 14:23:44 +03:00
|
|
|
self.assertEqual(7, test_hgsubversion_util.repolen(repo))
|
2010-03-02 19:06:06 +03:00
|
|
|
# tip is former topological branch1 being closed
|
|
|
|
ctx = repo['tip']
|
|
|
|
self.assertEqual('1', ctx.extra().get('close', '0'))
|
|
|
|
self.assertEqual('branch1', ctx.branch())
|
|
|
|
# r5 is where the replacement takes place
|
|
|
|
ctx = repo[5]
|
2010-03-02 19:06:06 +03:00
|
|
|
self.assertEqual(set(['a', 'c', 'dir/e', 'dir2/e', 'f', 'g']), set(ctx))
|
2010-03-02 19:06:06 +03:00
|
|
|
self.assertEqual('0', ctx.extra().get('close', '0'))
|
|
|
|
self.assertEqual('branch1', ctx.branch())
|
|
|
|
self.assertEqual('c\n', ctx['c'].data())
|
2010-03-02 19:06:06 +03:00
|
|
|
self.assertEqual('d\n', ctx['a'].data())
|
2010-03-02 19:06:06 +03:00
|
|
|
self.assertEqual('e\n', ctx['dir/e'].data())
|
|
|
|
self.assertEqual('e\n', ctx['dir2/e'].data())
|
2010-03-02 19:06:06 +03:00
|
|
|
self.assertEqual('f\n', ctx['f'].data())
|
|
|
|
self.assertEqual('g\n', ctx['g'].data())
|
|
|
|
for f in ctx:
|
|
|
|
self.assertTrue(not ctx[f].renamed())
|
2010-03-02 19:06:06 +03:00
|
|
|
|
2013-06-12 04:53:31 +04:00
|
|
|
def test_misspelled_branches_tags(self):
|
|
|
|
config = {
|
|
|
|
'hgsubversion.branchdir': 'branchez',
|
|
|
|
'hgsubversion.tagpaths': 'tagz',
|
|
|
|
}
|
|
|
|
'''Tests using the tags dir for branches and the branches dir for tags'''
|
|
|
|
repo = self._load_fixture_and_fetch('misspelled_branches_tags.svndump',
|
|
|
|
layout='standard',
|
|
|
|
config=config)
|
|
|
|
|
|
|
|
heads = set([repo[n].branch() for n in repo.heads()])
|
|
|
|
expected_heads = set(['default', 'branch'])
|
|
|
|
|
|
|
|
self.assertEqual(heads, expected_heads)
|
|
|
|
|
|
|
|
tags = set(repo.tags())
|
|
|
|
expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch'])
|
|
|
|
self.assertEqual(tags, expected_tags)
|
|
|
|
|
|
|
|
def test_subdir_branches_tags(self):
|
|
|
|
'''Tests using the tags dir for branches and the branches dir for tags'''
|
|
|
|
config = {
|
|
|
|
'hgsubversion.branchdir': 'bran/ches',
|
|
|
|
'hgsubversion.tagpaths': 'ta/gs',
|
|
|
|
}
|
|
|
|
repo = self._load_fixture_and_fetch('subdir_branches_tags.svndump',
|
|
|
|
layout='standard',
|
|
|
|
config=config)
|
|
|
|
|
|
|
|
heads = set([repo[n].branch() for n in repo.heads()])
|
|
|
|
expected_heads = set(['default', 'branch'])
|
|
|
|
|
|
|
|
self.assertEqual(heads, expected_heads)
|
|
|
|
|
|
|
|
tags = set(repo.tags())
|
|
|
|
expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch'])
|
|
|
|
self.assertEqual(tags, expected_tags)
|
|
|
|
|
2013-09-11 21:55:01 +04:00
|
|
|
def test_subproject_fetch(self):
|
|
|
|
config = {
|
|
|
|
'hgsubversion.infix': 'project',
|
|
|
|
}
|
|
|
|
repo = self._load_fixture_and_fetch('subprojects.svndump',
|
|
|
|
layout='standard',
|
|
|
|
config=config)
|
|
|
|
|
|
|
|
heads = set([repo[n].branch() for n in repo.heads()])
|
|
|
|
expected_heads = set(['default', 'branch'])
|
|
|
|
self.assertEqual(heads, expected_heads)
|
|
|
|
|
|
|
|
tags = set(repo.tags())
|
|
|
|
expected_tags = set(['tip', 'tag_from_trunk', 'tag_from_branch'])
|
|
|
|
self.assertEqual(tags, expected_tags)
|
|
|
|
|
|
|
|
for head in repo.heads():
|
|
|
|
ctx = repo[head]
|
|
|
|
self.assertFalse('project/file' in ctx, 'failed to strip infix')
|
|
|
|
self.assertTrue('file' in ctx, 'failed to track a simple file')
|
|
|
|
self.assertFalse('other/phile' in ctx, 'pulled in other project')
|
|
|
|
self.assertFalse('phile' in ctx, 'merged other project in repo')
|
|
|
|
|
|
|
|
|
2013-06-12 04:53:31 +04:00
|
|
|
def suite():
|
|
|
|
all_tests = [unittest.TestLoader().loadTestsFromTestCase(TestFetchBranches),
|
|
|
|
]
|
|
|
|
return unittest.TestSuite(all_tests)
|
2018-01-17 14:23:44 +03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
import silenttestrunner
|
|
|
|
silenttestrunner.main(__name__)
|
|
|
|
|