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.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
9 | 9 |
10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 return RunGitWithCode(args, suppress_stderr=True)[1] | 131 return RunGitWithCode(args, suppress_stderr=True)[1] |
132 | 132 |
133 | 133 |
134 def IsGitVersionAtLeast(min_version): | 134 def IsGitVersionAtLeast(min_version): |
135 prefix = 'git version ' | 135 prefix = 'git version ' |
136 version = RunGit(['--version']).strip() | 136 version = RunGit(['--version']).strip() |
137 return (version.startswith(prefix) and | 137 return (version.startswith(prefix) and |
138 LooseVersion(version[len(prefix):]) >= LooseVersion(min_version)) | 138 LooseVersion(version[len(prefix):]) >= LooseVersion(min_version)) |
139 | 139 |
140 | 140 |
| 141 def BranchExists(branch): |
| 142 """Return True if specified branch exists.""" |
| 143 code, _ = RunGitWithCode(['rev-parse', '--verify', branch], |
| 144 suppress_stderr=True) |
| 145 return not code |
| 146 |
| 147 |
141 def ask_for_data(prompt): | 148 def ask_for_data(prompt): |
142 try: | 149 try: |
143 return raw_input(prompt) | 150 return raw_input(prompt) |
144 except KeyboardInterrupt: | 151 except KeyboardInterrupt: |
145 # Hide the exception. | 152 # Hide the exception. |
146 sys.exit(1) | 153 sys.exit(1) |
147 | 154 |
148 | 155 |
149 def git_set_branch_value(key, value): | 156 def git_set_branch_value(key, value): |
150 branch = Changelist().GetBranch() | 157 branch = Changelist().GetBranch() |
(...skipping 560 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 else: | 718 else: |
712 DieWithError("""Unable to determine default branch to diff against. | 719 DieWithError("""Unable to determine default branch to diff against. |
713 Either pass complete "git diff"-style arguments, like | 720 Either pass complete "git diff"-style arguments, like |
714 git cl upload origin/master | 721 git cl upload origin/master |
715 or verify this branch is set up to track another (via the --track argument to | 722 or verify this branch is set up to track another (via the --track argument to |
716 "git checkout -b ...").""") | 723 "git checkout -b ...").""") |
717 | 724 |
718 return remote, upstream_branch | 725 return remote, upstream_branch |
719 | 726 |
720 def GetCommonAncestorWithUpstream(self): | 727 def GetCommonAncestorWithUpstream(self): |
| 728 upstream_branch = self.GetUpstreamBranch() |
| 729 if not BranchExists(upstream_branch): |
| 730 DieWithError('The upstream for the current branch (%s) does not exist ' |
| 731 'anymore.\nPlease fix it and try again.' % self.GetBranch()) |
721 return git_common.get_or_create_merge_base(self.GetBranch(), | 732 return git_common.get_or_create_merge_base(self.GetBranch(), |
722 self.GetUpstreamBranch()) | 733 upstream_branch) |
723 | 734 |
724 def GetUpstreamBranch(self): | 735 def GetUpstreamBranch(self): |
725 if self.upstream_branch is None: | 736 if self.upstream_branch is None: |
726 remote, upstream_branch = self.FetchUpstreamTuple(self.GetBranch()) | 737 remote, upstream_branch = self.FetchUpstreamTuple(self.GetBranch()) |
727 if remote is not '.': | 738 if remote is not '.': |
728 upstream_branch = upstream_branch.replace('refs/heads/', | 739 upstream_branch = upstream_branch.replace('refs/heads/', |
729 'refs/remotes/%s/' % remote) | 740 'refs/remotes/%s/' % remote) |
730 upstream_branch = upstream_branch.replace('refs/branch-heads/', | 741 upstream_branch = upstream_branch.replace('refs/branch-heads/', |
731 'refs/remotes/branch-heads/') | 742 'refs/remotes/branch-heads/') |
732 self.upstream_branch = upstream_branch | 743 self.upstream_branch = upstream_branch |
(...skipping 2639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3372 if __name__ == '__main__': | 3383 if __name__ == '__main__': |
3373 # These affect sys.stdout so do it outside of main() to simplify mocks in | 3384 # These affect sys.stdout so do it outside of main() to simplify mocks in |
3374 # unit testing. | 3385 # unit testing. |
3375 fix_encoding.fix_encoding() | 3386 fix_encoding.fix_encoding() |
3376 colorama.init() | 3387 colorama.init() |
3377 try: | 3388 try: |
3378 sys.exit(main(sys.argv[1:])) | 3389 sys.exit(main(sys.argv[1:])) |
3379 except KeyboardInterrupt: | 3390 except KeyboardInterrupt: |
3380 sys.stderr.write('interrupted\n') | 3391 sys.stderr.write('interrupted\n') |
3381 sys.exit(1) | 3392 sys.exit(1) |
OLD | NEW |