OLD | NEW |
1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
6 | 6 |
7 import glob | 7 import glob |
8 import os | 8 import os |
9 import re | 9 import re |
10 import shutil | 10 import shutil |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 ['config', 'branch.%s.merge' % branch], in_directory=cwd, | 211 ['config', 'branch.%s.merge' % branch], in_directory=cwd, |
212 error_ok=True)[0].strip() | 212 error_ok=True)[0].strip() |
213 if upstream_branch: | 213 if upstream_branch: |
214 remote = GIT.Capture( | 214 remote = GIT.Capture( |
215 ['config', 'branch.%s.remote' % branch], | 215 ['config', 'branch.%s.remote' % branch], |
216 in_directory=cwd, error_ok=True)[0].strip() | 216 in_directory=cwd, error_ok=True)[0].strip() |
217 else: | 217 else: |
218 # Fall back on trying a git-svn upstream branch. | 218 # Fall back on trying a git-svn upstream branch. |
219 if GIT.IsGitSvn(cwd): | 219 if GIT.IsGitSvn(cwd): |
220 upstream_branch = GIT.GetSVNBranch(cwd) | 220 upstream_branch = GIT.GetSVNBranch(cwd) |
221 # Fall back on origin/master if it exits. | |
222 elif GIT.Capture(['branch', '-r'], in_directory=cwd | |
223 )[0].split().count('origin/master'): | |
224 remote = 'origin' | |
225 upstream_branch = 'refs/heads/master' | |
226 else: | 221 else: |
227 remote = None | 222 # Else, try to guess the origin remote. |
228 upstream_branch = None | 223 remote_branches = GIT.Capture( |
| 224 ['branch', '-r'], in_directory=cwd)[0].split() |
| 225 if 'origin/master' in remote_branches: |
| 226 # Fall back on origin/master if it exits. |
| 227 remote = 'origin' |
| 228 upstream_branch = 'refs/heads/master' |
| 229 elif 'origin/trunk' in remote_branches: |
| 230 # Fall back on origin/trunk if it exists. Generally a shared |
| 231 # git-svn clone |
| 232 remote = 'origin' |
| 233 upstream_branch = 'refs/heads/trunk' |
| 234 else: |
| 235 # Give up. |
| 236 remote = None |
| 237 upstream_branch = None |
229 return remote, upstream_branch | 238 return remote, upstream_branch |
230 | 239 |
231 @staticmethod | 240 @staticmethod |
232 def GetUpstreamBranch(cwd): | 241 def GetUpstreamBranch(cwd): |
233 """Gets the current branch's upstream branch.""" | 242 """Gets the current branch's upstream branch.""" |
234 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) | 243 remote, upstream_branch = GIT.FetchUpstreamTuple(cwd) |
235 if remote != '.': | 244 if remote != '.' and upstream_branch: |
236 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) | 245 upstream_branch = upstream_branch.replace('heads', 'remotes/' + remote) |
237 return upstream_branch | 246 return upstream_branch |
238 | 247 |
239 @staticmethod | 248 @staticmethod |
240 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, | 249 def GenerateDiff(cwd, branch=None, branch_head='HEAD', full_move=False, |
241 files=None): | 250 files=None): |
242 """Diffs against the upstream branch or optionally another branch. | 251 """Diffs against the upstream branch or optionally another branch. |
243 | 252 |
244 full_move means that move or copy operations should completely recreate the | 253 full_move means that move or copy operations should completely recreate the |
245 files, usually in the prospect to apply the patch for a try job.""" | 254 files, usually in the prospect to apply the patch for a try job.""" |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
787 if not SVN.current_version: | 796 if not SVN.current_version: |
788 SVN.current_version = SVN.Capture(['--version']).split()[2] | 797 SVN.current_version = SVN.Capture(['--version']).split()[2] |
789 current_version_list = map(only_int, SVN.current_version.split('.')) | 798 current_version_list = map(only_int, SVN.current_version.split('.')) |
790 for min_ver in map(int, min_version.split('.')): | 799 for min_ver in map(int, min_version.split('.')): |
791 ver = current_version_list.pop(0) | 800 ver = current_version_list.pop(0) |
792 if ver < min_ver: | 801 if ver < min_ver: |
793 return (False, SVN.current_version) | 802 return (False, SVN.current_version) |
794 elif ver > min_ver: | 803 elif ver > min_ver: |
795 return (True, SVN.current_version) | 804 return (True, SVN.current_version) |
796 return (True, SVN.current_version) | 805 return (True, SVN.current_version) |
OLD | NEW |