def test_info_output(self, custom=False): if custom: config = { 'hgsubversionbranch.default': 'trunk', 'hgsubversionbranch.the_branch': 'branches/the_branch', } else: config = {} repo, repo_path = self.load_and_fetch('two_heads.svndump', config=config) hg.update(self.repo, 'the_branch') u = self.ui() u.pushbuffer() svncommands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'branches/the_branch', 'rev': 5, }) self.assertMultiLineEqual(actual, expected) hg.update(self.repo, 'default') u.pushbuffer() svncommands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'trunk', 'rev': 6, }) self.assertMultiLineEqual(actual, expected) hg.update(self.repo, 'default') u.pushbuffer() svncommands.info(u, self.repo, rev=3) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'branches/the_branch', 'rev': 5, }) self.assertMultiLineEqual(actual, expected) destpath = self.wc_path + '_clone' test_util.hgclone(u, self.repo, destpath) repo2 = hg.repository(u, destpath) repo2.ui.setconfig('paths', 'default-push', self.repo.ui.config('paths', 'default')) hg.update(repo2, 'default') svncommands.rebuildmeta(u, repo2, []) u.pushbuffer() svncommands.info(u, repo2) actual = u.popbuffer() expected = (expected_info_output % {'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'trunk', 'rev': 6, }) self.assertMultiLineEqual(actual, expected)
def test_push_to_non_tip(self): self.test_push_to_branch(push=False) wc2path = self.wc_path + '_clone' u = self.repo.ui test_util.hgclone(self.repo.ui, self.wc_path, wc2path, update=False) res = self.pushrevisions() self.assertEqual(0, res) oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc')) hgrc = oldf.read() oldf.close() shutil.rmtree(self.wc_path) test_util.hgclone(u, wc2path, self.wc_path, update=False) oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'), 'w') oldf.write(hgrc) oldf.close() # do a commit here self.commitchanges([('foobaz', 'foobaz', 'This file is added on default.',), ], parent='default', message='commit to default') from hgsubversion import svncommands svncommands.rebuildmeta(u, self.repo, args=[test_util.fileurl(self.repo_path)]) hg.update(self.repo, self.repo['tip'].node()) oldnode = self.repo['tip'].hex() self.pushrevisions(expected_extra_back=1) self.assertNotEqual(oldnode, self.repo['tip'].hex(), 'Revision was not pushed.')
def test_branchmap_rebuildmeta(self): '''test rebuildmeta on a branchmapped clone''' repo_path = self.load_svndump('branchmap.svndump') branchmap = open(self.branchmap, 'w') branchmap.write("badname = dit\n") branchmap.write("feature = dah\n") branchmap.close() ui = self.ui() ui.setconfig('hgsubversion', 'branchmap', self.branchmap) commands.clone(ui, test_util.fileurl(repo_path), self.wc_path, branchmap=self.branchmap) originfo = self.repo.svnmeta().branches # clone & rebuild ui = self.ui() src, dest = test_util.hgclone(ui, self.wc_path, self.wc_path + '_clone', update=False) src = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) svncommands.rebuildmeta(ui, dest, args=[test_util.fileurl(repo_path)]) # just check the keys; assume the contents are unaffected by the branch # map and thus properly tested by other tests self.assertEquals(sorted(src.svnmeta().branches), sorted(dest.svnmeta().branches))
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') self._load_fixture_and_fetch(name, subdir=subdir, stupid=False, layout=layout) assert len(self.repo) > 0, 'Repo had no changes, maybe you need to add a subdir entry in test_util?' wc2_path = self.wc_path + '_stupid' u = ui.ui() checkout_path = self.repo_path if subdir: checkout_path += '/' + subdir u.setconfig('hgsubversion', 'stupid', '1') u.setconfig('hgsubversion', 'layout', layout) test_util.hgclone(u, test_util.fileurl(checkout_path), wc2_path, update=False) if layout == 'single': self.assertEqual(len(self.repo.heads()), 1) self.repo2 = hg.repository(ui.ui(), wc2_path) self.assertEqual(self.repo.heads(), self.repo2.heads())
def test_push_to_non_tip(self): self.test_push_to_branch(push=False) wc2path = self.wc_path + '_clone' u = self.repo.ui test_util.hgclone(self.repo.ui, self.wc_path, wc2path, update=False) res = self.pushrevisions() self.assertEqual(0, res) oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc')) hgrc = oldf.read() oldf.close() shutil.rmtree(self.wc_path) test_util.hgclone(u, wc2path, self.wc_path, update=False) oldf = open(os.path.join(self.wc_path, '.hg', 'hgrc'), 'w') oldf.write(hgrc) oldf.close() # do a commit here self.commitchanges([ ( 'foobaz', 'foobaz', 'This file is added on default.', ), ], parent='default', message='commit to default') from hgsubversion import svncommands svncommands.rebuildmeta(u, self.repo, args=[test_util.fileurl(self.repo_path)]) hg.update(self.repo, revsymbol(self.repo, 'tip').node()) oldnode = revsymbol(self.repo, 'tip').hex() self.pushrevisions(expected_extra_back=1) self.assertNotEqual(oldnode, revsymbol(self.repo, 'tip').hex(), 'Revision was not pushed.')
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') config = {} u = test_util.testui() for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path u.setconfig('hgsubversionbranch', branch, path) repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout, config=config) assert test_util.repolen(self.repo) > 0, \ 'Repo had no changes, maybe you need to add a subdir entry in test_util?' wc2_path = self.wc_path + '_stupid' checkout_path = repo_path if subdir: checkout_path += '/' + subdir u.setconfig('hgsubversion', 'stupid', '1') u.setconfig('hgsubversion', 'layout', layout) test_util.hgclone(u, test_util.fileurl(checkout_path), wc2_path, update=False) if layout == 'single': self.assertEqual(len(self.repo.heads()), 1) self.repo2 = hg.repository(test_util.testui(), wc2_path) self.assertEqual(self.repo.heads(), self.repo2.heads())
def _do_case(self, name, stupid): subdir = test_util.subdir.get(name, '') config = { 'hgsubversion.stupid': stupid and '1' or '0', } repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout='auto', config=config) assert test_util.repolen(self.repo) > 0, \ 'Repo had no changes, maybe you need to add a subdir entry in test_util?' wc2_path = self.wc_path + '_custom' checkout_path = repo_path if subdir: checkout_path += '/' + subdir u = test_util.testui(stupid=stupid, layout='custom') for branch, path in test_util.custom.get(name, {}).iteritems(): u.setconfig('hgsubversionbranch', branch, path) test_util.hgclone(u, test_util.fileurl(checkout_path), wc2_path, update=False) self.repo2 = hg.repository(test_util.testui(), wc2_path) self.assertEqual(self.repo.heads(), self.repo2.heads())
def test_most_recent_is_edited(self): repo, repo_path = self.load_and_fetch('most-recent-is-edit-tag.svndump') self.repo.ui.status( "Note: this test failing may be because of a rebuildmeta failure.\n" "You should check that before assuming issues with this test.\n") wc2_path = self.wc_path + '2' src, dest = test_util.hgclone(repo.ui, self.wc_path, wc2_path, update=False) dest = test_util.getlocalpeer(dest) svncommands.rebuildmeta(repo.ui, dest, args=[test_util.fileurl(repo_path), ]) commands.pull(self.repo.ui, self.repo) dtags, srctags = dest.tags(), self.repo.tags() dtags.pop('tip') srctags.pop('tip') self.assertEqual(dtags, srctags) self.assertEqual(dest.heads(), self.repo.heads())
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') single = layout == 'single' u = test_util.testui() config = {} if layout == 'custom': config['hgsubversion.layout'] = 'custom' u.setconfig('hgsubversion', 'layout', 'custom') for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path u.setconfig('hgsubversionbranch', branch, path) repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout, config=config) assert test_util.repolen(self.repo) > 0 wc2_path = self.wc_path + '_clone' src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) src = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() def failfn(orig, ctx): self.fail('calling %s is forbidden; it can cause massive slowdowns ' 'when rebuilding large repositories' % orig) origchildren = getattr(context.changectx, 'children') extensions.wrapfunction(context.changectx, 'children', failfn) # test updatemeta on an empty repo try: svncommands.updatemeta(u, dest, args=[ test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, src, dest, u)
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') single = layout == 'single' u = ui.ui() config = {} if layout == 'custom': config['hgsubversion.layout'] = 'custom' u.setconfig('hgsubversion', 'layout', 'custom') for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path u.setconfig('hgsubversionbranch', branch, path) repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout, config=config) assert test_util.repolen(self.repo) > 0 wc2_path = self.wc_path + '_clone' src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) src = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() def failfn(orig, ctx): self.fail('calling %s is forbidden; it can cause massive slowdowns ' 'when rebuilding large repositories' % orig) origchildren = getattr(context.changectx, 'children') extensions.wrapfunction(context.changectx, 'children', failfn) # test updatemeta on an empty repo try: svncommands.updatemeta(u, dest, args=[test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, src, dest, u)
def test_most_recent_is_edited(self): repo, repo_path = self.load_and_fetch( 'most-recent-is-edit-tag.svndump') self.repo.ui.status( "Note: this test failing may be because of a rebuildmeta failure.\n" "You should check that before assuming issues with this test.\n") wc2_path = self.wc_path + '2' src, dest = test_util.hgclone(repo.ui, self.wc_path, wc2_path, update=False) dest = test_util.getlocalpeer(dest) svncommands.rebuildmeta(repo.ui, dest, args=[ test_util.fileurl(repo_path), ]) commands.pull(self.repo.ui, self.repo) dtags, srctags = dest.tags(), self.repo.tags() dtags.pop('tip') srctags.pop('tip') self.assertEqual(dtags, srctags) self.assertEqual(dest.heads(), self.repo.heads())
def test_info_output(self, custom=False): if custom: config = { 'hgsubversionbranch.default': 'trunk', 'hgsubversionbranch.the_branch': 'branches/the_branch', } else: config = {} repo, repo_path = self.load_and_fetch('two_heads.svndump', config=config) hg.update(self.repo, revsymbol(self.repo, 'the_branch')) u = self.ui() u.pushbuffer() svncommands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % { 'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'branches/the_branch', 'rev': 5, }) self.assertMultiLineEqual(actual, expected) hg.update(self.repo, revsymbol(self.repo, 'default')) u.pushbuffer() svncommands.info(u, self.repo) actual = u.popbuffer() expected = (expected_info_output % { 'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'trunk', 'rev': 6, }) self.assertMultiLineEqual(actual, expected) hg.update(self.repo, revsymbol(self.repo, 'default')) u.pushbuffer() svncommands.info(u, self.repo, rev=3) actual = u.popbuffer() expected = (expected_info_output % { 'date': '2008-10-08 01:39:05 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'branches/the_branch', 'rev': 5, }) self.assertMultiLineEqual(actual, expected) destpath = self.wc_path + '_clone' test_util.hgclone(u, self.repo, destpath) repo2 = hg.repository(u, destpath) repo2.ui.setconfig('paths', 'default-push', self.repo.ui.config('paths', 'default')) hg.update(repo2, revsymbol(self.repo, 'default')) svncommands.rebuildmeta(u, repo2, []) u.pushbuffer() svncommands.info(u, repo2) actual = u.popbuffer() expected = (expected_info_output % { 'date': '2008-10-08 01:39:29 +0000 (Wed, 08 Oct 2008)', 'repourl': repourl(repo_path), 'branch': 'trunk', 'rev': 6, }) self.assertMultiLineEqual(actual, expected)
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') single = layout == 'single' u = ui.ui() config = {} if layout == 'custom': for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path u.setconfig('hgsubversionbranch', branch, path) repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout) assert test_util.repolen(self.repo) > 0 wc2_path = self.wc_path + '_clone' src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) src = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() def failfn(orig, ctx): self.fail('calling %s is forbidden; it can cause massive slowdowns ' 'when rebuilding large repositories' % orig) origchildren = getattr(context.changectx, 'children') extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.rebuildmeta(u, dest, args=[test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, src, dest, u) wc3_path = self.wc_path + '_partial' src, dest = test_util.hgclone(u, self.wc_path, wc3_path, update=False, rev=[0]) srcrepo = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.rebuildmeta(u, dest, args=[test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren if hgutil.safehasattr(localrepo.localrepository, 'pull'): dest.pull(src) else: # Mercurial >= 3.2 from mercurial import exchange exchange.pull(dest, src) # insert a wrapper that prevents calling changectx.children() extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.updatemeta(u, dest, args=[test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, srcrepo, dest, u)
def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): test_util.load_svndump_fixture(self.repo_path, fixture_name) source = '%s#%s' % (test_util.fileurl(self.repo_path), anchor) test_util.hgclone(self.ui(), source, self.wc_path) return hg.repository(self.ui(), self.wc_path)
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') single = layout == 'single' u = test_util.testui() config = {} if layout == 'custom': for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path u.setconfig('hgsubversionbranch', branch, path) repo, repo_path = self.load_and_fetch(name, subdir=subdir, layout=layout) assert test_util.repolen(self.repo) > 0 wc2_path = self.wc_path + '_clone' src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) src = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() def failfn(orig, ctx): self.fail('calling %s is forbidden; it can cause massive slowdowns ' 'when rebuilding large repositories' % orig) origchildren = getattr(context.changectx, 'children') extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.rebuildmeta(u, dest, args=[ test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, src, dest, u) wc3_path = self.wc_path + '_partial' src, dest = test_util.hgclone(u, self.wc_path, wc3_path, update=False, rev=['0']) srcrepo = test_util.getlocalpeer(src) dest = test_util.getlocalpeer(dest) # insert a wrapper that prevents calling changectx.children() extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.rebuildmeta(u, dest, args=[ test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren if hgutil.safehasattr(localrepo.localrepository, 'pull'): dest.pull(src) else: # Mercurial >= 3.2 from mercurial import exchange exchange.pull(dest, src) # insert a wrapper that prevents calling changectx.children() extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.updatemeta(u, dest, args=[ test_util.fileurl(repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self._run_assertions(name, single, srcrepo, dest, u)
def _do_case(self, name, stupid, single): subdir = test_util.subdir.get(name, '') layout = 'auto' if single: layout = 'single' self._load_fixture_and_fetch(name, subdir=subdir, stupid=stupid, layout=layout) assert len(self.repo) > 0 wc2_path = self.wc_path + '_clone' u = ui.ui() src, dest = test_util.hgclone(u, self.wc_path, wc2_path, update=False) # insert a wrapper that prevents calling changectx.children() def failfn(orig, ctx): self.fail('calling %s is forbidden; it can cause massive slowdowns ' 'when rebuilding large repositories' % orig) origchildren = getattr(context.changectx, 'children') extensions.wrapfunction(context.changectx, 'children', failfn) try: svncommands.rebuildmeta(u, dest, args=[test_util.fileurl(self.repo_path + subdir), ]) finally: # remove the wrapper context.changectx.children = origchildren self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), 'no .hg/svn directory in the source!') self.assertTrue(os.path.isdir(os.path.join(src.path, 'svn')), 'no .hg/svn directory in the destination!') dest = hg.repository(u, os.path.dirname(dest.path)) for tf in ('lastpulled', 'rev_map', 'uuid', 'tagmap', 'layout', 'subdir',): stf = os.path.join(src.path, 'svn', tf) self.assertTrue(os.path.isfile(stf), '%r is missing!' % stf) dtf = os.path.join(dest.path, 'svn', tf) self.assertTrue(os.path.isfile(dtf), '%r is missing!' % tf) old, new = open(stf).read(), open(dtf).read() if tf == 'lastpulled' and (name, stupid, single) in expect_youngest_skew: self.assertNotEqual(old, new, 'rebuildmeta unexpected match on youngest rev!') continue self.assertMultiLineEqual(old, new) self.assertEqual(src.branchtags(), dest.branchtags()) srcbi = pickle.load(open(os.path.join(src.path, 'svn', 'branch_info'))) destbi = pickle.load(open(os.path.join(dest.path, 'svn', 'branch_info'))) self.assertEqual(sorted(srcbi.keys()), sorted(destbi.keys())) revkeys = svnmeta.SVNMeta(dest).revmap.keys() for branch in destbi: srcinfo = srcbi[branch] destinfo = destbi[branch] if srcinfo[:2] == (None, 0) or destinfo[:2] == (None, 0): self.assertTrue(srcinfo[2] <= destinfo[2], 'Latest revision for %s decreased from %d to %d!' % (branch or 'default', srcinfo[2], destinfo[2])) self.assertEqual(srcinfo[0], destinfo[0]) else: pr = sorted(filter(lambda x: x[1] == srcinfo[0] and x[0] <= srcinfo[1], revkeys), reverse=True)[0][0] self.assertEqual(pr, destinfo[1]) self.assertEqual(srcinfo[2], destinfo[2])
def _load_fixture_and_fetch_with_anchor(self, fixture_name, anchor): repo_path = self.load_svndump(fixture_name) source = '%s#%s' % (test_util.fileurl(repo_path), anchor) test_util.hgclone(self.ui(), source, self.wc_path) return hg.repository(self.ui(), self.wc_path)