Mercurial > hg > gut
comparison gut/main.py @ 8:0c0ade65b9f9
fix errors
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Wed, 21 Jul 2010 16:37:23 -0700 |
parents | 67ec22ce347c |
children | b344537797de |
comparison
equal
deleted
inserted
replaced
7:67ec22ce347c | 8:0c0ade65b9f9 |
---|---|
47 - remote: name of the remote repository in .git/config | 47 - remote: name of the remote repository in .git/config |
48 - simulate: print what calls will be used but don't run them | 48 - simulate: print what calls will be used but don't run them |
49 - branches: branches to apply to | 49 - branches: branches to apply to |
50 """ | 50 """ |
51 | 51 |
52 self.simulate = simulate | |
53 | |
52 # sanity check | 54 # sanity check |
53 try: | 55 try: |
54 self.root() | 56 self.root() |
55 except SystemExit: | 57 except SystemExit: |
56 print "Not in a git repository" | 58 print "Not in a git repository" |
57 sys.exit(1) | 59 sys.exit(1) |
58 | 60 |
59 self.remote = remote | 61 self.remote = remote |
60 self.simulate = simulate | |
61 self.branches = branches | 62 self.branches = branches |
62 if simulate: | 63 if simulate: |
63 globals()['call'] = fake_call | 64 globals()['call'] = fake_call |
64 | 65 |
65 | 66 |
140 apply the existing feature branch to master as a patch | 141 apply the existing feature branch to master as a patch |
141 """ | 142 """ |
142 | 143 |
143 # sanity check | 144 # sanity check |
144 branch = self.branch() | 145 branch = self.branch() |
146 if self.simulate: | |
147 branch = '<branch>' | |
145 assert branch != 'master', "Can't apply master to itself!" | 148 assert branch != 'master', "Can't apply master to itself!" |
146 assert self.branches, "No branches defined!" | 149 assert self.branches, "No branches defined!" |
147 | 150 |
148 # get the patch | 151 # get the patch |
149 self.patch(branch + '.diff', branch + '.log') | 152 self.patch(branch + '.diff', branch + '.log') |
150 diff = os.path.abspath(branch + '.diff') | 153 diff = os.path.abspath(branch + '.diff') |
151 log = os.path.abspath(branch + '.log') | 154 log = os.path.abspath(branch + '.log') |
152 | 155 |
153 # apply the patch | 156 # apply the patch |
154 cwd = os.getcwd() | 157 if not self.simulate: |
155 os.chdir(self.root()) | 158 cwd = os.getcwd() |
159 os.chdir(self.root()) | |
156 for b in self.branches: | 160 for b in self.branches: |
157 call(['git', 'checkout', b]) | 161 call(['git', 'checkout', b]) |
158 call(['patch -p1 < %s' % diff]) | 162 call(['patch -p1 < %s' % diff]) |
159 call(['git', 'commit', '-a', '-F', log]) | 163 call(['git', 'commit', '-a', '-F', log]) |
160 call(['git', 'push', 'origin', b]) | 164 call(['git', 'push', 'origin', b]) |
161 if self.remote: | 165 if self.remote: |
162 call(['git', 'push', self.remote, b]) | 166 call(['git', 'push', self.remote, b]) |
163 | 167 |
164 # cleanup | 168 # cleanup |
165 call(['git', 'checkout', branch]) | 169 call(['git', 'checkout', branch]) |
166 os.chdir(cwd) | 170 if not self.simulate: |
171 os.chdir(cwd) | |
167 | 172 |
168 def delete(self): | 173 def delete(self): |
169 """delete the current feature branch""" | 174 """delete the current feature branch""" |
170 # sanity check | 175 # sanity check |
171 branch = self.branch() | 176 branch = self.branch() |
182 if line.startswith('*'): | 187 if line.startswith('*'): |
183 return line[1:].strip() | 188 return line[1:].strip() |
184 | 189 |
185 def root(self): | 190 def root(self): |
186 """return (relative) root location of repository""" | 191 """return (relative) root location of repository""" |
187 | 192 |
193 if self.simulate: | |
194 return '<root>' | |
188 output = call(['git', 'rev-parse', '--show-cdup'], output=False, pipe=True) | 195 output = call(['git', 'rev-parse', '--show-cdup'], output=False, pipe=True) |
189 location = output['stdout'].strip() | 196 location = output['stdout'].strip() |
190 if not location: | 197 if not location: |
191 return '.' | 198 return '.' |
192 return location | 199 return location |