OLD | NEW |
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 and Gerrit.""" | 8 """A git-command for integrating reviews on Rietveld and Gerrit.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
985 return None | 985 return None |
986 self.branchref = branchref | 986 self.branchref = branchref |
987 self.branch = ShortBranchName(self.branchref) | 987 self.branch = ShortBranchName(self.branchref) |
988 return self.branch | 988 return self.branch |
989 | 989 |
990 def GetBranchRef(self): | 990 def GetBranchRef(self): |
991 """Returns the full branch name, e.g. 'refs/heads/master'.""" | 991 """Returns the full branch name, e.g. 'refs/heads/master'.""" |
992 self.GetBranch() # Poke the lazy loader. | 992 self.GetBranch() # Poke the lazy loader. |
993 return self.branchref | 993 return self.branchref |
994 | 994 |
| 995 def ClearBranch(self): |
| 996 """Clears cached branch data of this object.""" |
| 997 self.branch = self.branchref = None |
| 998 |
995 @staticmethod | 999 @staticmethod |
996 def FetchUpstreamTuple(branch): | 1000 def FetchUpstreamTuple(branch): |
997 """Returns a tuple containing remote and remote ref, | 1001 """Returns a tuple containing remote and remote ref, |
998 e.g. 'origin', 'refs/heads/master' | 1002 e.g. 'origin', 'refs/heads/master' |
999 """ | 1003 """ |
1000 remote = '.' | 1004 remote = '.' |
1001 upstream_branch = RunGit(['config', 'branch.%s.merge' % branch], | 1005 upstream_branch = RunGit(['config', 'branch.%s.merge' % branch], |
1002 error_ok=True).strip() | 1006 error_ok=True).strip() |
1003 if upstream_branch: | 1007 if upstream_branch: |
1004 remote = RunGit(['config', 'branch.%s.remote' % branch]).strip() | 1008 remote = RunGit(['config', 'branch.%s.remote' % branch]).strip() |
(...skipping 3305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4310 cl = Changelist(auth_config=auth_config) | 4314 cl = Changelist(auth_config=auth_config) |
4311 issue = cl.GetIssue() | 4315 issue = cl.GetIssue() |
4312 branch = cl.GetBranch() | 4316 branch = cl.GetBranch() |
4313 if not issue: | 4317 if not issue: |
4314 DieWithError('No issue found for current branch (%s)' % branch) | 4318 DieWithError('No issue found for current branch (%s)' % branch) |
4315 TMP_BRANCH = 'git-cl-diff' | 4319 TMP_BRANCH = 'git-cl-diff' |
4316 base_branch = cl.GetCommonAncestorWithUpstream() | 4320 base_branch = cl.GetCommonAncestorWithUpstream() |
4317 | 4321 |
4318 # Create a new branch based on the merge-base | 4322 # Create a new branch based on the merge-base |
4319 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) | 4323 RunGit(['checkout', '-q', '-b', TMP_BRANCH, base_branch]) |
4320 # Update the cached branch in cl instance, to avoid overwriting original | 4324 # Clear cached branch in cl object, to avoid overwriting original CL branch |
4321 # branch properties. | 4325 # properties. |
4322 cl.branch = cl.branchref = None | 4326 cl.ClearBranch() |
4323 try: | 4327 try: |
4324 rtn = cl.CMDPatchIssue(issue, reject=False, nocommit=False, directory=None) | 4328 rtn = cl.CMDPatchIssue(issue, reject=False, nocommit=False, directory=None) |
4325 if rtn != 0: | 4329 if rtn != 0: |
4326 RunGit(['reset', '--hard']) | 4330 RunGit(['reset', '--hard']) |
4327 return rtn | 4331 return rtn |
4328 | 4332 |
4329 # Switch back to starting branch and diff against the temporary | 4333 # Switch back to starting branch and diff against the temporary |
4330 # branch containing the latest rietveld patch. | 4334 # branch containing the latest rietveld patch. |
4331 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) | 4335 subprocess2.check_call(['git', 'diff', TMP_BRANCH, branch, '--']) |
4332 finally: | 4336 finally: |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4624 if __name__ == '__main__': | 4628 if __name__ == '__main__': |
4625 # These affect sys.stdout so do it outside of main() to simplify mocks in | 4629 # These affect sys.stdout so do it outside of main() to simplify mocks in |
4626 # unit testing. | 4630 # unit testing. |
4627 fix_encoding.fix_encoding() | 4631 fix_encoding.fix_encoding() |
4628 setup_color.init() | 4632 setup_color.init() |
4629 try: | 4633 try: |
4630 sys.exit(main(sys.argv[1:])) | 4634 sys.exit(main(sys.argv[1:])) |
4631 except KeyboardInterrupt: | 4635 except KeyboardInterrupt: |
4632 sys.stderr.write('interrupted\n') | 4636 sys.stderr.write('interrupted\n') |
4633 sys.exit(1) | 4637 sys.exit(1) |
OLD | NEW |