Improve "dcommit in git repo" error message.

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

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@295609 0039d316-1c4b-4281-b951-d872f2087c98
changes/01/332501/1
mmoss@chromium.org 11 years ago
parent 8e095af012
commit f0e4152061

@ -23,7 +23,7 @@ import subprocess2
from git_common import run as run_git from git_common import run as run_git
from git_common import run_stream as run_git_stream from git_common import run_stream as run_git_stream
from git_common import set_config, root, ROOT from git_common import set_config, root, ROOT
from git_footers import parse_footers, get_unique, GIT_SVN_ID_PATTERN from git_footers import get_footer_svn_id
SVN_EXE = ROOT+'\\svn.bat' if sys.platform.startswith('win') else 'svn' SVN_EXE = ROOT+'\\svn.bat' if sys.platform.startswith('win') else 'svn'
@ -58,14 +58,11 @@ def main(argv):
parser.parse_args(argv) parser.parse_args(argv)
upstream = root() upstream = root()
message = run_git('log', '-1', '--format=%B', upstream) svn_id = get_footer_svn_id(upstream)
footers = parse_footers(message) assert svn_id, 'No valid git-svn-id footer found on %s.' % upstream
git_svn_id = get_unique(footers, 'git-svn-id') print 'Found git-svn-id footer %s on %s' % (svn_id, upstream)
match = GIT_SVN_ID_PATTERN.match(git_svn_id)
assert match, 'No valid git-svn-id footer found on %s.' % upstream parsed_svn = urlparse.urlparse(svn_id)
print 'Found git-svn-id footer %s on %s' % (match.group(1), upstream)
parsed_svn = urlparse.urlparse(match.group(1))
path_components = parsed_svn.path.split('/') path_components = parsed_svn.path.split('/')
svn_repo = None svn_repo = None
svn_path = None svn_path = None
@ -86,7 +83,7 @@ def main(argv):
' from https://chromium-access.appspot.com' % maybe_repo) ' from https://chromium-access.appspot.com' % maybe_repo)
print print
continue continue
assert svn_repo is not None, 'Unable to find svn repo for %s' % match.group(1) 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) 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.url', svn_repo)

@ -44,6 +44,7 @@ import dart_format
import fix_encoding import fix_encoding
import gclient_utils import gclient_utils
import git_common import git_common
from git_footers import get_footer_svn_id
import owners import owners
import owners_finder import owners_finder
import presubmit_support import presubmit_support
@ -2645,13 +2646,20 @@ def IsFatalPushFailure(push_stdout):
def CMDdcommit(parser, args): def CMDdcommit(parser, args):
"""Commits the current changelist via git-svn.""" """Commits the current changelist via git-svn."""
if not settings.GetIsGitSvn(): if not settings.GetIsGitSvn():
message = """This doesn't appear to be an SVN repository. if get_footer_svn_id():
If your project has a git mirror with an upstream SVN master, you probably need # If it looks like previous commits were mirrored with git-svn.
to run 'git svn init', see your project's git mirror documentation. message = """This repository appears to be a git-svn mirror, but no
If your project has a true writeable upstream repository, you probably want upstream SVN master is set. You probably need to run 'git auto-svn' once."""
to run 'git cl land' instead. else:
Choose wisely, if you get this wrong, your commit might appear to succeed but message = """This doesn't appear to be an SVN repository.
will instead be silently ignored.""" If your project has a true, writeable git repository, you probably want to run
'git cl land' instead.
If your project has a git mirror of an upstream SVN master, you probably need
to run 'git svn init'.
Using the wrong command might cause your commit to appear to succeed, and the
review to be closed, without actually landing upstream. If you choose to
proceed, please verify that the commit lands upstream as expected."""
print(message) print(message)
ask_for_data('[Press enter to dcommit or ctrl-C to quit]') ask_for_data('[Press enter to dcommit or ctrl-C to quit]')
return SendUpstream(parser, args, 'dcommit') return SendUpstream(parser, args, 'dcommit')
@ -2660,9 +2668,10 @@ will instead be silently ignored."""
@subcommand.usage('[upstream branch to apply against]') @subcommand.usage('[upstream branch to apply against]')
def CMDland(parser, args): def CMDland(parser, args):
"""Commits the current changelist via git.""" """Commits the current changelist via git."""
if settings.GetIsGitSvn(): if settings.GetIsGitSvn() or get_footer_svn_id():
print('This appears to be an SVN repository.') print('This appears to be an SVN repository.')
print('Are you sure you didn\'t mean \'git cl dcommit\'?') print('Are you sure you didn\'t mean \'git cl dcommit\'?')
print('(Ignore if this is the first commit after migrating from svn->git)')
ask_for_data('[Press enter to push or ctrl-C to quit]') ask_for_data('[Press enter to push or ctrl-C to quit]')
return SendUpstream(parser, args, 'land') return SendUpstream(parser, args, 'land')

@ -48,6 +48,20 @@ def parse_footers(message):
return footer_map return footer_map
def get_footer_svn_id(branch=None):
if not branch:
branch = git.root()
svn_id = None
message = git.run('log', '-1', '--format=%B', branch)
footers = parse_footers(message)
git_svn_id = get_unique(footers, 'git-svn-id')
if git_svn_id:
match = GIT_SVN_ID_PATTERN.match(git_svn_id)
if match:
svn_id = match.group(1)
return svn_id
def get_unique(footers, key): def get_unique(footers, key):
key = normalize_name(key) key = normalize_name(key)
values = footers[key] values = footers[key]

Loading…
Cancel
Save