# HG changeset patch # User Jeff Hammel # Date 1279316833 25200 # Node ID 54b30e8f6f82332cb8f85f526692ee40e0b930a3 # Parent 6cf716c40bb645c3f9fbbfe152415006d8cab722 * add a simulate mode * remove hello test * remove broken invokation from main fucntion diff -r 6cf716c40bb6 -r 54b30e8f6f82 gut/main.py --- a/gut/main.py Fri Jul 16 14:28:21 2010 -0700 +++ b/gut/main.py Fri Jul 16 14:47:13 2010 -0700 @@ -31,16 +31,26 @@ print stderr return dict(stdout=stdout, stderr=stderr, code=code) +def fake_call(command, **kw): + if isinstance(command, basestring): + print command + else: + print ' '.join(command) + class gut(object): """ a workflow for git """ - def __init__(self, remote=None): - self.remote = remote - - def hello(self, name='world'): - print 'hello %s' % name + def __init__(self, remote=None, simulate=False): + """ + - remote: name of the remote repository in .git/config + - simulate: print what calls will be used but don't run them + """ + self.remote = remote + self.simulate = simulate + if simulate: + globals()['call'] = fake_call def update(self): """update the master and the branch you're on""" @@ -57,11 +67,13 @@ def patch(self, output=None): """generate a patch for review""" + diff = call(['git', 'diff', 'master'], pipe=True, output=False) + log = call(['git', 'log', 'master..'], pipe=True, output=False) + if self.simulate: + return if not output: output = self.branch() + '.diff' - diff = call(['git', 'diff', 'master'], pipe=True, output=False) diff = diff['stdout'] - log = call(['git', 'log', 'master..'], pipe=True, output=False) log = log['stdout'] f = file(output) # write the output to a patch file return log @@ -69,13 +81,14 @@ def branch(self): """print what branch you're on""" output = call(['git', 'branch'], output=False) + if self.simulate: + return for line in output['stdout'].splitlines(): if line.startswith('*'): return line[1:].strip() def main(args=sys.argv[1:]): parser = CommandParser(gut) - options, args = parser.parse_args(args) parser.invoke(args) if __name__ == '__main__':