Skip to content

Commit a2cbbbb

Browse files
Choosing a default remote for determining base_url.
BUG=116057 Review URL: http://codereview.chromium.org/9836013 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@128293 0039d316-1c4b-4281-b951-d872f2087c98
1 parent c6a9cb2 commit a2cbbbb

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

git_cl.py

+27-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
DEFAULT_SERVER = 'https://codereview.appspot.com'
4949
POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s'
5050
DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup'
51+
GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingNewGit'
5152

5253

5354
# Initialized in main()
@@ -308,6 +309,7 @@ def __init__(self, branchref=None):
308309
self._rpc_server = None
309310
self.cc = None
310311
self.watchers = ()
312+
self._remote = None
311313

312314
def GetCCList(self):
313315
"""Return the users cc'd on this CL.
@@ -386,14 +388,36 @@ def GetUpstreamBranch(self):
386388
self.upstream_branch = upstream_branch
387389
return self.upstream_branch
388390

391+
def GetRemote(self):
392+
if not self._remote:
393+
self._remote = self.FetchUpstreamTuple()[0]
394+
if self._remote == '.':
395+
396+
remotes = RunGit(['remote'], error_ok=True).split()
397+
if len(remotes) == 1:
398+
self._remote, = remotes
399+
elif 'origin' in remotes:
400+
self._remote = 'origin'
401+
logging.warning('Could not determine which remote this change is '
402+
'associated with, so defaulting to "%s". This may '
403+
'not be what you want. You may prevent this message '
404+
'by running "git svn info" as documented here: %s',
405+
self._remote,
406+
GIT_INSTRUCTIONS_URL)
407+
else:
408+
logging.warn('Could not determine which remote this change is '
409+
'associated with. You may prevent this message by '
410+
'running "git svn info" as documented here: %s',
411+
GIT_INSTRUCTIONS_URL)
412+
return self._remote
413+
414+
389415
def GetRemoteUrl(self):
390416
"""Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
391417
392418
Returns None if there is no remote.
393419
"""
394-
remote = self.FetchUpstreamTuple()[0]
395-
if remote == '.':
396-
return None
420+
remote = self.GetRemote()
397421
return RunGit(['config', 'remote.%s.url' % remote], error_ok=True).strip()
398422

399423
def GetIssue(self):

0 commit comments

Comments
 (0)