Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(457)

Side by Side Diff: trychange.py

Issue 10836180: Make git try warn on a dirty index. (Closed) Base URL: http://src.chromium.org/svn/trunk/tools/depot_tools/
Patch Set: minimize unittest diff a bit... Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Client-side script to send a try job to the try server. It communicates to 6 """Client-side script to send a try job to the try server. It communicates to
7 the try server by either writting to a svn repository or by directly connecting 7 the try server by either writting to a svn repository or by directly connecting
8 to the server by HTTP. 8 to the server by HTTP.
9 """ 9 """
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 premade diff file on the local drive: 58 premade diff file on the local drive:
59 %(prog)s --email user@example.com 59 %(prog)s --email user@example.com
60 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff 60 --svn_repo svn://svn.chromium.org/chrome-try/try --diff foo.diff
61 61
62 Running only on a 'mac' slave with revision 123 and clobber first; specify 62 Running only on a 'mac' slave with revision 123 and clobber first; specify
63 manually the 3 source files to use for the try job: 63 manually the 3 source files to use for the try job:
64 %(prog)s --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h 64 %(prog)s --bot mac --revision 123 --clobber -f src/a.cc -f src/a.h
65 -f include/b.h 65 -f include/b.h
66 """ 66 """
67 67
68
69 def DieWithError(message):
70 print >> sys.stderr, message
71 sys.exit(1)
72
73
74 def RunCommand(args, error_ok=False, error_message=None, **kwargs):
75 try:
76 return subprocess2.check_output(args, shell=False, **kwargs)
77 except subprocess2.CalledProcessError, e:
78 if not error_ok:
79 DieWithError(
80 'Command "%s" failed.\n%s' % (
81 ' '.join(args), error_message or e.stdout or ''))
82 return e.stdout
83
84
85 def RunGit(args, **kwargs):
86 """Returns stdout."""
87 return RunCommand(['git'] + args, **kwargs)
88
89
68 class InvalidScript(Exception): 90 class InvalidScript(Exception):
69 def __str__(self): 91 def __str__(self):
70 return self.args[0] + '\n' + HELP_STRING 92 return self.args[0] + '\n' + HELP_STRING
71 93
72 94
73 class NoTryServerAccess(Exception): 95 class NoTryServerAccess(Exception):
74 def __str__(self): 96 def __str__(self):
75 return self.args[0] + '\n' + HELP_STRING 97 return self.args[0] + '\n' + HELP_STRING
76 98
77 99
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 "(via the --track argument to \"git checkout -b ...\"") 287 "(via the --track argument to \"git checkout -b ...\"")
266 logging.info("GIT(%s)" % self.checkout_root) 288 logging.info("GIT(%s)" % self.checkout_root)
267 289
268 def CaptureStatus(self): 290 def CaptureStatus(self):
269 return scm.GIT.CaptureStatus( 291 return scm.GIT.CaptureStatus(
270 [], 292 [],
271 self.checkout_root.replace(os.sep, '/'), 293 self.checkout_root.replace(os.sep, '/'),
272 self.diff_against) 294 self.diff_against)
273 295
274 def GenerateDiff(self): 296 def GenerateDiff(self):
297 if RunGit(['diff-index', 'HEAD']):
298 print 'Cannot try with a dirty tree. You must commit locally first.'
299 return None
275 return scm.GIT.GenerateDiff( 300 return scm.GIT.GenerateDiff(
276 self.checkout_root, 301 self.checkout_root,
277 files=self.files, 302 files=self.files,
278 full_move=True, 303 full_move=True,
279 branch=self.diff_against) 304 branch=self.diff_against)
280 305
281 306
282 def _ParseSendChangeOptions(options): 307 def _ParseSendChangeOptions(options):
283 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN.""" 308 """Parse common options passed to _SendChangeHTTP and _SendChangeSVN."""
284 values = [ 309 values = [
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 diff_url = ('%s/download/issue%d_%d.diff' % 768 diff_url = ('%s/download/issue%d_%d.diff' %
744 (options.rietveld_url, options.issue, options.patchset)) 769 (options.rietveld_url, options.issue, options.patchset))
745 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines()) 770 diff = GetMungedDiff('', urllib.urlopen(diff_url).readlines())
746 options.diff = ''.join(diff[0]) 771 options.diff = ''.join(diff[0])
747 changed_files = diff[1] 772 changed_files = diff[1]
748 else: 773 else:
749 # Use this as the base. 774 # Use this as the base.
750 root = checkouts[0].checkout_root 775 root = checkouts[0].checkout_root
751 diffs = [] 776 diffs = []
752 for checkout in checkouts: 777 for checkout in checkouts:
753 diff = checkout.GenerateDiff().splitlines(True) 778 raw_diff = checkout.GenerateDiff()
779 if not raw_diff:
780 return 1
781 diff = raw_diff.splitlines(True)
754 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root) 782 path_diff = gclient_utils.PathDifference(root, checkout.checkout_root)
755 # Munge it. 783 # Munge it.
756 diffs.extend(GetMungedDiff(path_diff, diff)[0]) 784 diffs.extend(GetMungedDiff(path_diff, diff)[0])
757 options.diff = ''.join(diffs) 785 options.diff = ''.join(diffs)
758 786
759 if not options.name: 787 if not options.name:
760 if options.issue: 788 if options.issue:
761 options.name = 'Issue %s' % options.issue 789 options.name = 'Issue %s' % options.issue
762 else: 790 else:
763 options.name = 'Unnamed' 791 options.name = 'Unnamed'
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 return 1 866 return 1
839 except (gclient_utils.Error, subprocess2.CalledProcessError), e: 867 except (gclient_utils.Error, subprocess2.CalledProcessError), e:
840 print >> sys.stderr, e 868 print >> sys.stderr, e
841 return 1 869 return 1
842 return 0 870 return 0
843 871
844 872
845 if __name__ == "__main__": 873 if __name__ == "__main__":
846 fix_encoding.fix_encoding() 874 fix_encoding.fix_encoding()
847 sys.exit(TryChange(None, None, False)) 875 sys.exit(TryChange(None, None, False))
OLDNEW
« no previous file with comments | « tests/trychange_unittest.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698