def test_branch(self): ''' Test 'clone --branch' ''' ui = self.ui() dispatch._dispatch(ui, ['init', self.wc_path]) repo = self.repo repo.ui.setconfig('ui', 'username', 'anonymous') fpath = os.path.join(self.wc_path, 'it') f = file(fpath, 'w') f.write('C1') f.flush() commands.add(ui, repo) commands.branch(ui, repo, label="B1") commands.commit(ui, repo, message="C1") f.write('C2') f.flush() commands.branch(ui, repo, label="default") commands.commit(ui, repo, message="C2") f.write('C3') f.flush() commands.branch(ui, repo, label="B2") commands.commit(ui, repo, message="C3") self.assertEqual(len(repo), 3) branch = 'B1' dispatch._dispatch(ui, ['clone', self.wc_path, self.wc_path + '2', '--branch', branch]) repo2 = hg.repository(ui, self.wc_path + '2') self.assertEqual(repo[branch].hex(), repo2['.'].hex())
def test_update(self): ''' Test 'clone --updaterev' ''' ui = self.ui() dispatch._dispatch(ui, ['init', self.wc_path]) repo = self.repo repo.ui.setconfig('ui', 'username', 'anonymous') fpath = os.path.join(self.wc_path, 'it') f = file(fpath, 'w') f.write('C1') f.flush() commands.add(ui, repo) commands.commit(ui, repo, message="C1") f.write('C2') f.flush() commands.commit(ui, repo, message="C2") f.write('C3') f.flush() commands.commit(ui, repo, message="C3") self.assertEqual(len(repo), 3) updaterev = 1 dispatch._dispatch(ui, ['clone', self.wc_path, self.wc_path + '2', '--updaterev=%s' % updaterev]) repo2 = hg.repository(ui, self.wc_path + '2') self.assertEqual(str(repo[updaterev]), str(repo2['.']))
def dispatch(ui, args): if hasattr(hgdispatch, 'request'): # hg >= 1.9, see mercurial changes 08bfec2ef031, 80c599eee3f3 req = hgdispatch.request(args, ui) return hgdispatch._dispatch(req) else: # hg <= 1.8 return hgdispatch._dispatch(ui, args)
def extstatushook(ui, repo, **kwargs): from mercurial.dispatch import _dispatch from mercurial import error import shlex args = shlex.split(kwargs.get('args', ''))[1:] try: _dispatch(ui, ['extstatus'] + args) except error.ParseError, e: ui.warn("hgexternals status: %s\n" % e[1])
def _dispatch(ui, cmd): assert '--quiet' in cmd try: req = dispatch.request(cmd, ui=ui) req.earlyoptions = { 'config': [], 'cwd': '', 'debugger': None, 'profile': False, 'repository': '', 'verbose': False, 'quiet': False, 'debug': False, 'traceback': False, } dispatch._dispatch(req) except AttributeError: dispatch._dispatch(ui, cmd)
def _dispatch(self, args): # TODO: use hglib in order to avoid pollution of global space? origwd = os.getcwd() ui = uimod.ui() ui.setconfig('ui', 'strict', True) ui.fout = StringIO.StringIO() ui.ferr = StringIO.StringIO() req = dispatch.request(list(args), ui=ui) try: result = dispatch._dispatch(req) or 0 return result, ui.fout.getvalue(), ui.ferr.getvalue() finally: os.chdir(origwd)
def _dispatch(ui, cmd): try: req = dispatch.request(cmd, ui=ui) dispatch._dispatch(req) except AttributeError: dispatch._dispatch(ui, cmd)
def dispatch(ui, args): req = hgdispatch.request(args, ui) return hgdispatch._dispatch(req)