Mercurial > hg > gut
comparison gut/main.py @ 2:54b30e8f6f82
* add a simulate mode
* remove hello test
* remove broken invokation from main fucntion
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 16 Jul 2010 14:47:13 -0700 |
parents | 9688c72a93c3 |
children | 4d38d14cf1d4 |
comparison
equal
deleted
inserted
replaced
1:6cf716c40bb6 | 2:54b30e8f6f82 |
---|---|
29 if output: | 29 if output: |
30 print stdout | 30 print stdout |
31 print stderr | 31 print stderr |
32 return dict(stdout=stdout, stderr=stderr, code=code) | 32 return dict(stdout=stdout, stderr=stderr, code=code) |
33 | 33 |
34 def fake_call(command, **kw): | |
35 if isinstance(command, basestring): | |
36 print command | |
37 else: | |
38 print ' '.join(command) | |
39 | |
34 class gut(object): | 40 class gut(object): |
35 """ | 41 """ |
36 a workflow for git | 42 a workflow for git |
37 """ | 43 """ |
38 | 44 |
39 def __init__(self, remote=None): | 45 def __init__(self, remote=None, simulate=False): |
40 self.remote = remote | 46 """ |
41 | 47 - remote: name of the remote repository in .git/config |
42 def hello(self, name='world'): | 48 - simulate: print what calls will be used but don't run them |
43 print 'hello %s' % name | 49 """ |
50 self.remote = remote | |
51 self.simulate = simulate | |
52 if simulate: | |
53 globals()['call'] = fake_call | |
44 | 54 |
45 def update(self): | 55 def update(self): |
46 """update the master and the branch you're on""" | 56 """update the master and the branch you're on""" |
47 call(['git', 'checkout', 'master']) | 57 call(['git', 'checkout', 'master']) |
48 call(['git', 'pull', 'origin', 'master']) | 58 call(['git', 'pull', 'origin', 'master']) |
55 call(['git', 'checkout', '-b', name]) | 65 call(['git', 'checkout', '-b', name]) |
56 call(['git', 'push', 'origin', name]) | 66 call(['git', 'push', 'origin', name]) |
57 | 67 |
58 def patch(self, output=None): | 68 def patch(self, output=None): |
59 """generate a patch for review""" | 69 """generate a patch for review""" |
70 diff = call(['git', 'diff', 'master'], pipe=True, output=False) | |
71 log = call(['git', 'log', 'master..'], pipe=True, output=False) | |
72 if self.simulate: | |
73 return | |
60 if not output: | 74 if not output: |
61 output = self.branch() + '.diff' | 75 output = self.branch() + '.diff' |
62 diff = call(['git', 'diff', 'master'], pipe=True, output=False) | |
63 diff = diff['stdout'] | 76 diff = diff['stdout'] |
64 log = call(['git', 'log', 'master..'], pipe=True, output=False) | |
65 log = log['stdout'] | 77 log = log['stdout'] |
66 f = file(output) # write the output to a patch file | 78 f = file(output) # write the output to a patch file |
67 return log | 79 return log |
68 | 80 |
69 def branch(self): | 81 def branch(self): |
70 """print what branch you're on""" | 82 """print what branch you're on""" |
71 output = call(['git', 'branch'], output=False) | 83 output = call(['git', 'branch'], output=False) |
84 if self.simulate: | |
85 return | |
72 for line in output['stdout'].splitlines(): | 86 for line in output['stdout'].splitlines(): |
73 if line.startswith('*'): | 87 if line.startswith('*'): |
74 return line[1:].strip() | 88 return line[1:].strip() |
75 | 89 |
76 def main(args=sys.argv[1:]): | 90 def main(args=sys.argv[1:]): |
77 parser = CommandParser(gut) | 91 parser = CommandParser(gut) |
78 options, args = parser.parse_args(args) | |
79 parser.invoke(args) | 92 parser.invoke(args) |
80 | 93 |
81 if __name__ == '__main__': | 94 if __name__ == '__main__': |
82 main() | 95 main() |