Commit 6b0051e7 authored by kalmard@homejinni.com's avatar kalmard@homejinni.com

Allow overriding base-url in git-cl.

This is useful if git-cl has no way to find out the original svn repo's url
and the user does not wish to configure git-svn and fetch the repository.

Review URL: http://codereview.chromium.org/9969099

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@130372 0039d316-1c4b-4281-b951-d872f2087c98
parent 92d67165
...@@ -411,6 +411,13 @@ or verify this branch is set up to track another (via the --track argument to ...@@ -411,6 +411,13 @@ or verify this branch is set up to track another (via the --track argument to
GIT_INSTRUCTIONS_URL) GIT_INSTRUCTIONS_URL)
return self._remote return self._remote
def GetGitBaseUrlFromConfig(self):
"""Return the configured base URL from branch.<branchname>.baseurl.
Returns None if it is not set.
"""
return RunGit(['config', 'branch.%s.base-url' % self.GetBranch()],
error_ok=True).strip()
def GetRemoteUrl(self): def GetRemoteUrl(self):
"""Return the configured remote URL, e.g. 'git://example.org/foo.git/'. """Return the configured remote URL, e.g. 'git://example.org/foo.git/'.
...@@ -787,6 +794,21 @@ def CMDconfig(parser, args): ...@@ -787,6 +794,21 @@ def CMDconfig(parser, args):
return 0 return 0
def CMDbaseurl(parser, args):
"""get or set base-url for this branch"""
branchref = RunGit(['symbolic-ref', 'HEAD']).strip()
branch = ShortBranchName(branchref)
_, args = parser.parse_args(args)
if not args:
print("Current base-url:")
return RunGit(['config', 'branch.%s.base-url' % branch],
error_ok=False).strip()
else:
print("Setting base-url to %s" % args[0])
return RunGit(['config', 'branch.%s.base-url' % branch, args[0]],
error_ok=False).strip()
def CMDstatus(parser, args): def CMDstatus(parser, args):
"""show status of changelists""" """show status of changelists"""
parser.add_option('--field', parser.add_option('--field',
...@@ -982,18 +1004,19 @@ def RietveldUpload(options, args, cl): ...@@ -982,18 +1004,19 @@ def RietveldUpload(options, args, cl):
# Include the upstream repo's URL in the change -- this is useful for # Include the upstream repo's URL in the change -- this is useful for
# projects that have their source spread across multiple repos. # projects that have their source spread across multiple repos.
remote_url = None remote_url = cl.GetGitBaseUrlFromConfig()
if settings.GetIsGitSvn(): if not remote_url:
# URL is dependent on the current directory. if settings.GetIsGitSvn():
data = RunGit(['svn', 'info'], cwd=settings.GetRoot()) # URL is dependent on the current directory.
if data: data = RunGit(['svn', 'info'], cwd=settings.GetRoot())
keys = dict(line.split(': ', 1) for line in data.splitlines() if data:
if ': ' in line) keys = dict(line.split(': ', 1) for line in data.splitlines()
remote_url = keys.get('URL', None) if ': ' in line)
else: remote_url = keys.get('URL', None)
if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch(): else:
remote_url = (cl.GetRemoteUrl() + '@' if cl.GetRemoteUrl() and '/' in cl.GetUpstreamBranch():
+ cl.GetUpstreamBranch().split('/')[-1]) remote_url = (cl.GetRemoteUrl() + '@'
+ cl.GetUpstreamBranch().split('/')[-1])
if remote_url: if remote_url:
upload_args.extend(['--base_url', remote_url]) upload_args.extend(['--base_url', remote_url])
......
...@@ -123,6 +123,7 @@ class TestGitCl(TestCase): ...@@ -123,6 +123,7 @@ class TestGitCl(TestCase):
def _git_upload_calls(): def _git_upload_calls():
return [ return [
((['git', 'config', 'rietveld.cc'],), ''), ((['git', 'config', 'rietveld.cc'],), ''),
((['git', 'config', 'branch.master.base-url'],), ''),
((['git', 'config', '--get-regexp', '^svn-remote\\.'],), ((['git', 'config', '--get-regexp', '^svn-remote\\.'],),
(('', None), 0)), (('', None), 0)),
((['git', 'rev-parse', '--show-cdup'],), ''), ((['git', 'rev-parse', '--show-cdup'],), ''),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment