def test_updatemetahook(self): repo, repo_path = self._loadupdate('single_rev.svndump') state = repo[None].parents() self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'}) commands.pull(self.repo.ui, self.repo) # Clone to a new repository and add a hook new_wc_path = "%s-2" % self.wc_path commands.clone(self.repo.ui, self.wc_path, new_wc_path) newrepo = hg.repository(test_util.testui(), new_wc_path) newrepo.ui.setconfig('hooks', 'changegroup.meta', 'python:hgsubversion.hooks.updatemeta.hook') # Commit a rev that should trigger svn meta update self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed Again'}) commands.pull(self.repo.ui, self.repo) self.called = False import hgsubversion.svncommands oldupdatemeta = hgsubversion.svncommands.updatemeta def _updatemeta(ui, repo, args=[]): self.called = True hgsubversion.svncommands.updatemeta = _updatemeta # Pull and make sure our updatemeta function gets called commands.pull(newrepo.ui, newrepo) hgsubversion.svncommands.updatemeta = oldupdatemeta self.assertTrue(self.called)
def test_updatemetahook(self): repo, repo_path = self._loadupdate('single_rev.svndump') state = repo.parents() self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed'}) commands.pull(self.repo.ui, self.repo) # Clone to a new repository and add a hook new_wc_path = "%s-2" % self.wc_path commands.clone(self.repo.ui, self.wc_path, new_wc_path) newrepo = hg.repository(test_util.testui(), new_wc_path) newrepo.ui.setconfig('hooks', 'changegroup.meta', 'python:hgsubversion.hooks.updatemeta.hook') # Commit a rev that should trigger svn meta update self.add_svn_rev(repo_path, {'trunk/alpha': 'Changed Again'}) commands.pull(self.repo.ui, self.repo) self.called = False import hgsubversion.svncommands oldupdatemeta = hgsubversion.svncommands.updatemeta def _updatemeta(ui, repo, args=[]): self.called = True hgsubversion.svncommands.updatemeta = _updatemeta # Pull and make sure our updatemeta function gets called commands.pull(newrepo.ui, newrepo) hgsubversion.svncommands.updatemeta = oldupdatemeta self.assertTrue(self.called)
def _do_case(self, name, layout): subdir = test_util.subdir.get(name, '') config = {} for branch, path in test_util.custom.get(name, {}).iteritems(): config['hgsubversionbranch.%s' % branch] = path repo, svnpath = self.load_and_fetch(name, subdir=subdir, layout=layout, config=config) assert test_util.repolen(self.repo) > 0 for i in repo: ctx = repo[i] self.assertEqual( verify.verify(repo.ui, repo, rev=ctx.node(), stupid=True), 0) self.assertEqual( verify.verify(repo.ui, repo, rev=ctx.node(), stupid=False), 0) # check a startrev clone if layout == 'single' and name not in _skipshallow: self.wc_path += '_shallow' shallowrepo = self.fetch(svnpath, subdir=subdir, layout='single', startrev='HEAD') self.assertEqual( test_util.repolen(shallowrepo), 1, "shallow clone should have just one revision, not %d" % test_util.repolen(shallowrepo)) fulltip = repo['tip'] shallowtip = shallowrepo['tip'] repo.ui.pushbuffer() self.assertEqual( 0, verify.verify(repo.ui, shallowrepo, rev=shallowtip.node(), stupid=True)) self.assertEqual( 0, verify.verify(repo.ui, shallowrepo, rev=shallowtip.node(), stupid=False)) stupidui = test_util.testui(stupid=True) self.assertEqual( verify.verify(stupidui, repo, rev=ctx.node(), stupid=True), 0) self.assertEqual( verify.verify(stupidui, repo, rev=ctx.node(), stupid=False), 0) # viewing diff's of lists of files is easier on the eyes self.assertMultiLineEqual('\n'.join(fulltip), '\n'.join(shallowtip), repo.ui.popbuffer()) for f in fulltip: self.assertMultiLineEqual(fulltip[f].data(), shallowtip[f].data())
def test_diff_output(self): self._load_fixture_and_fetch('two_revs.svndump') self.commitchanges([ ('foo', 'foo', 'This is missing a newline.'), ('alpha', 'alpha', 'alpha\n\nadded line\n'), ]) u = test_util.testui() u.pushbuffer() wrappers.diff(lambda x, y, z: None, u, self.repo, svn=True) self.assertEqual(u.popbuffer(), expected_diff_output)
def test_url_rewriting(self): ui = test_util.testui() ui.setconfig('hgsubversion', 'username', 'bob') repo = svnrepo.svnremoterepo(ui, 'svn+ssh://joe@foo/bar') self.assertEqual('svn+ssh://bob@foo/bar', repo.svnauth[0]) self.assertEqual('svn+ssh://bob@foo/bar', repo.svnurl) repo = svnrepo.svnremoterepo(ui, 'svn+http://joe@foo/bar') self.assertEqual(('http://foo/bar', 'bob', None), repo.svnauth) self.assertEqual('http://foo/bar', repo.svnurl) repo = svnrepo.svnremoterepo(ui, 'svn+https://joe@foo/bar') self.assertEqual(('https://foo/bar', 'bob', None), repo.svnauth) self.assertEqual('https://foo/bar', repo.svnurl)
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 _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, 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 = 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)