# HG changeset patch # User Jeff Hammel # Date 1368788481 25200 # Node ID 44ec940c86a64aa49237cca0faaec60eaa0c0d55 # Parent b878f4ce93fc71e0e68cd30f3d7bc188ee204aca pull works, i think diff -r b878f4ce93fc -r 44ec940c86a6 hq/main.py --- a/hq/main.py Fri May 17 03:19:28 2013 -0700 +++ b/hq/main.py Fri May 17 04:01:21 2013 -0700 @@ -4,8 +4,6 @@ mercurial queue extension front-end """ -# TODO: migrate to http://k0s.org/hg/CommandParser/ - import os import subprocess import sys @@ -23,7 +21,6 @@ """initialize global options""" # TODO: look at hgrc file # for [defaults] repository_host - # XXX ??? # check for network self.network = network @@ -77,21 +74,29 @@ if mq is true, update the patch queue, if versioned """ # check for outstanding changes - import pdb; pdb.set_trace() - output = self._call(['st']).strip() - lines = [line for line in output.splitlines() - if not line.startswith('?')] - if lines: + output = self._status(self.root) + if output: print "Outstanding changes:" print output raise AssertionError applied, unapplied = self._series() - self._call(['qpop', '--all']) - self._call(['pull'] + (repo and [repo] or [])) + self._call('qpop', '--all') + self._call(*(['pull'] + (repo and [repo] or []))) # TODO: pull queue repo + if self._versioned(): + if self.incoming(): + print >> sys.stderr, "Incoming changes, cannot pull" + # TODO: yes you can if they're compatible + else: + output = self._status(self.directory()) + if output: + print >> sys.stderr, "Cannot pull %s; outstanding changes" % (self.directory()) + print output + else: + self._call('pull', '--mq') for patch in applied: - self._call(['qpush']) + self._call('qpush') def goto(self, patch): """ @@ -154,12 +159,18 @@ def _series(self): """returns a 2-tuple of applied, unapplied""" - lines = self._command(['qseries']).strip() + lines = [line.strip() + for line in self._call('qseries').strip().splitlines()] applied = [] unapplied = [] for line in lines: - line.strip() - index, status, name = line.split() + + try: + index, status, name = line.split() + except: + print line + raise + if status == 'A': applied.append(name) else: @@ -167,6 +178,18 @@ unapplied.append(name) return applied, unapplied + def _status(self, repo): + """get the status of a repo; if clean, return None, else + return the output of hg st""" + + output = call([self.binary, 'st'], cwd=repo).strip() + lines = [line for line in output.splitlines() + if not line.startswith('?')] + if lines: + return output + + + def main(args=sys.argv[1:]): parser = CommandParser(HQ) options, args = parser.parse_args(args)