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

Side by Side Diff: git_cl.py

Issue 86133002: Fix "git cl diff" when run on branch without an issue. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 7 years 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 | « no previous file | 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 # Copyright (C) 2008 Evan Martin <martine@danga.com> 6 # Copyright (C) 2008 Evan Martin <martine@danga.com>
7 7
8 """A git-command for integrating reviews on Rietveld.""" 8 """A git-command for integrating reviews on Rietveld."""
9 9
10 from distutils.version import LooseVersion 10 from distutils.version import LooseVersion
(...skipping 2142 matching lines...) Expand 10 before | Expand all | Expand 10 after
2153 cl = Changelist() 2153 cl = Changelist()
2154 # Ensure there actually is an issue to close. 2154 # Ensure there actually is an issue to close.
2155 cl.GetDescription() 2155 cl.GetDescription()
2156 cl.CloseIssue() 2156 cl.CloseIssue()
2157 return 0 2157 return 0
2158 2158
2159 2159
2160 def CMDdiff(parser, args): 2160 def CMDdiff(parser, args):
2161 """shows differences between local tree and last upload.""" 2161 """shows differences between local tree and last upload."""
2162 cl = Changelist() 2162 cl = Changelist()
2163 issue = cl.GetIssue()
2163 branch = cl.GetBranch() 2164 branch = cl.GetBranch()
2165 if not issue:
2166 DieWithError('No issue found for current branch (%s)' % branch)
2164 TMP_BRANCH = 'git-cl-diff' 2167 TMP_BRANCH = 'git-cl-diff'
2165 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip() 2168 base_branch = RunGit(['merge-base', cl.GetUpstreamBranch(), 'HEAD']).strip()
2166 2169
2167 # Create a new branch based on the merge-base 2170 # Create a new branch based on the merge-base
2168 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) 2171 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch])
2169 try: 2172 try:
2170 # Patch in the latest changes from rietveld. 2173 # Patch in the latest changes from rietveld.
2171 rtn = PatchIssue(cl.GetIssue(), False, False, None) 2174 rtn = PatchIssue(issue, False, False, None)
2172 if rtn != 0: 2175 if rtn != 0:
2173 return rtn 2176 return rtn
2174 2177
2175 # Switch back to starting brand and diff against the temporary 2178 # Switch back to starting brand and diff against the temporary
2176 # branch containing the latest rietveld patch. 2179 # branch containing the latest rietveld patch.
2177 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch]) 2180 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch])
2178 finally: 2181 finally:
2179 RunGit(['checkout', '-q', branch]) 2182 RunGit(['checkout', '-q', branch])
2180 RunGit(['branch', '-D', TMP_BRANCH]) 2183 RunGit(['branch', '-D', TMP_BRANCH])
2181 2184
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
2318 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' 2321 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith '
2319 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) 2322 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e)))
2320 2323
2321 2324
2322 if __name__ == '__main__': 2325 if __name__ == '__main__':
2323 # These affect sys.stdout so do it outside of main() to simplify mocks in 2326 # These affect sys.stdout so do it outside of main() to simplify mocks in
2324 # unit testing. 2327 # unit testing.
2325 fix_encoding.fix_encoding() 2328 fix_encoding.fix_encoding()
2326 colorama.init() 2329 colorama.init()
2327 sys.exit(main(sys.argv[1:])) 2330 sys.exit(main(sys.argv[1:]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698