Commit 2ad16009 authored by mmoss@chromium.org's avatar mmoss@chromium.org

Make auto-svn also configure the current svn branch (if any).

With this change, and running 'git auto-svn' whenever starting work on a
new upstream branch, much git-svn confusion and mayhem can be avoided.
For example:

$ git checkout -b drover_2403 branch-heads/2403
$ git svn info --url
  svn://svn.chromium.org/chrome-internal/trunk/tools/build
  # git-svn still thinks it's dealing with trunk.
$ git auto-svn
...
$ git svn info --url
  svn://svn.chromium.org/chrome-internal/branches/2403/tools/build
  # That's better.

R=agable@chromium.org, amineer@chromium.org

Review URL: https://codereview.chromium.org/1340733002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@296667 0039d316-1c4b-4281-b951-d872f2087c98
parent 02ad753f
......@@ -22,7 +22,8 @@ import subprocess2
from git_common import run as run_git
from git_common import run_stream_with_retcode as run_git_stream_with_retcode
from git_common import set_config, root, ROOT
from git_common import set_config, root, ROOT, current_branch
from git_common import upstream as get_upstream
from git_footers import get_footer_svn_id
......@@ -57,7 +58,24 @@ def main(argv):
description='Automatically set up git-svn for a repo mirrored from svn.')
parser.parse_args(argv)
upstream = root()
upstreams = []
# Always configure the upstream trunk.
upstreams.append(root())
# Optionally configure whatever upstream branch might be currently checked
# out. This is needed for work on svn-based branches, otherwise git-svn gets
# very confused and tries to relate branch commits back to trunk, making a big
# mess of the codereview patches, and generating all kinds of spurious errors
# about the repo being in some sort of bad state.
curr_upstream = get_upstream(current_branch())
# There will be no upstream if the checkout is in detached HEAD.
if curr_upstream:
upstreams.append(curr_upstream)
for upstream in upstreams:
config_svn(upstream)
return 0
def config_svn(upstream):
svn_id = get_footer_svn_id(upstream)
assert svn_id, 'No valid git-svn-id footer found on %s.' % upstream
print 'Found git-svn-id footer %s on %s' % (svn_id, upstream)
......@@ -86,14 +104,14 @@ def main(argv):
assert svn_repo is not None, 'Unable to find svn repo for %s' % svn_id
print 'Found upstream svn repo %s and path %s' % (svn_repo, svn_path)
set_config('svn-remote.svn.url', svn_repo)
set_config('svn-remote.svn.fetch',
'%s:refs/remotes/%s' % (svn_path, upstream))
run_git('config', '--local', '--replace-all', 'svn-remote.svn.url', svn_repo)
run_git('config', '--local', '--replace-all', 'svn-remote.svn.fetch',
'%s:refs/remotes/%s' % (svn_path, upstream),
'refs/remotes/%s$' % upstream)
print 'Configured metadata, running "git svn fetch". This may take some time.'
with run_git_stream_with_retcode('svn', 'fetch') as stdout:
for line in stdout.xreadlines():
print line.strip()
return 0
if __name__ == '__main__':
......
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