comparison hq/main.py @ 17:44ec940c86a6

pull works, i think
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 17 May 2013 04:01:21 -0700
parents b878f4ce93fc
children d4e5d09e007c
comparison
equal deleted inserted replaced
16:b878f4ce93fc 17:44ec940c86a6
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 2
3 """ 3 """
4 mercurial queue extension front-end 4 mercurial queue extension front-end
5 """ 5 """
6
7 # TODO: migrate to http://k0s.org/hg/CommandParser/
8 6
9 import os 7 import os
10 import subprocess 8 import subprocess
11 import sys 9 import sys
12 10
21 19
22 def __init__(self, network=True, root=None, binary='hg'): 20 def __init__(self, network=True, root=None, binary='hg'):
23 """initialize global options""" 21 """initialize global options"""
24 # TODO: look at hgrc file 22 # TODO: look at hgrc file
25 # for [defaults] repository_host 23 # for [defaults] repository_host
26 # XXX ???
27 24
28 # check for network 25 # check for network
29 self.network = network 26 self.network = network
30 27
31 # repository root 28 # repository root
75 """ 72 """
76 pull from the root repository 73 pull from the root repository
77 if mq is true, update the patch queue, if versioned 74 if mq is true, update the patch queue, if versioned
78 """ 75 """
79 # check for outstanding changes 76 # check for outstanding changes
80 import pdb; pdb.set_trace() 77 output = self._status(self.root)
81 output = self._call(['st']).strip() 78 if output:
82 lines = [line for line in output.splitlines()
83 if not line.startswith('?')]
84 if lines:
85 print "Outstanding changes:" 79 print "Outstanding changes:"
86 print output 80 print output
87 raise AssertionError 81 raise AssertionError
88 82
89 applied, unapplied = self._series() 83 applied, unapplied = self._series()
90 self._call(['qpop', '--all']) 84 self._call('qpop', '--all')
91 self._call(['pull'] + (repo and [repo] or [])) 85 self._call(*(['pull'] + (repo and [repo] or [])))
92 # TODO: pull queue repo 86 # TODO: pull queue repo
87 if self._versioned():
88 if self.incoming():
89 print >> sys.stderr, "Incoming changes, cannot pull"
90 # TODO: yes you can if they're compatible
91 else:
92 output = self._status(self.directory())
93 if output:
94 print >> sys.stderr, "Cannot pull %s; outstanding changes" % (self.directory())
95 print output
96 else:
97 self._call('pull', '--mq')
93 for patch in applied: 98 for patch in applied:
94 self._call(['qpush']) 99 self._call('qpush')
95 100
96 def goto(self, patch): 101 def goto(self, patch):
97 """ 102 """
98 go to a specific patch and apply it 103 go to a specific patch and apply it
99 - patch: name of patch to go to 104 - patch: name of patch to go to
152 """is the patch queue versioned?""" 157 """is the patch queue versioned?"""
153 return os.path.isdir(os.path.join(self.directory(), '.hg')) 158 return os.path.isdir(os.path.join(self.directory(), '.hg'))
154 159
155 def _series(self): 160 def _series(self):
156 """returns a 2-tuple of applied, unapplied""" 161 """returns a 2-tuple of applied, unapplied"""
157 lines = self._command(['qseries']).strip() 162 lines = [line.strip()
163 for line in self._call('qseries').strip().splitlines()]
158 applied = [] 164 applied = []
159 unapplied = [] 165 unapplied = []
160 for line in lines: 166 for line in lines:
161 line.strip() 167
162 index, status, name = line.split() 168 try:
169 index, status, name = line.split()
170 except:
171 print line
172 raise
173
163 if status == 'A': 174 if status == 'A':
164 applied.append(name) 175 applied.append(name)
165 else: 176 else:
166 assert status == 'U' 177 assert status == 'U'
167 unapplied.append(name) 178 unapplied.append(name)
168 return applied, unapplied 179 return applied, unapplied
169 180
181 def _status(self, repo):
182 """get the status of a repo; if clean, return None, else
183 return the output of hg st"""
184
185 output = call([self.binary, 'st'], cwd=repo).strip()
186 lines = [line for line in output.splitlines()
187 if not line.startswith('?')]
188 if lines:
189 return output
190
191
192
170 def main(args=sys.argv[1:]): 193 def main(args=sys.argv[1:]):
171 parser = CommandParser(HQ) 194 parser = CommandParser(HQ)
172 options, args = parser.parse_args(args) 195 options, args = parser.parse_args(args)
173 parser.invoke(args) 196 parser.invoke(args)
174 197