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

Side by Side Diff: git_cl.py

Issue 1156223008: Added message when upstream branch is gone. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 5 years, 6 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
« 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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)
iannucci 2015/06/08 18:01:56 why not have GetUpstreamBranch do this check?
pgervais 2015/06/08 20:48:16 I wasn't sure it wouldn't break something else, li
pgervais 2015/06/08 22:23:13 Well, it would break CMDupstream, when it's used t
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 2637 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 if __name__ == '__main__': 3381 if __name__ == '__main__':
3371 # These affect sys.stdout so do it outside of main() to simplify mocks in 3382 # These affect sys.stdout so do it outside of main() to simplify mocks in
3372 # unit testing. 3383 # unit testing.
3373 fix_encoding.fix_encoding() 3384 fix_encoding.fix_encoding()
3374 colorama.init() 3385 colorama.init()
3375 try: 3386 try:
3376 sys.exit(main(sys.argv[1:])) 3387 sys.exit(main(sys.argv[1:]))
3377 except KeyboardInterrupt: 3388 except KeyboardInterrupt:
3378 sys.stderr.write('interrupted\n') 3389 sys.stderr.write('interrupted\n')
3379 sys.exit(1) 3390 sys.exit(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