From f0e41520618de5eace229a7a4d4e3363853d7e32 Mon Sep 17 00:00:00 2001 From: "mmoss@chromium.org" Date: Wed, 10 Jun 2015 19:52:01 +0000 Subject: [PATCH] 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 --- git_auto_svn.py | 17 +++++++---------- git_cl.py | 25 +++++++++++++++++-------- git_footers.py | 14 ++++++++++++++ 3 files changed, 38 insertions(+), 18 deletions(-) diff --git a/git_auto_svn.py b/git_auto_svn.py index 0e8f341c7c..722029c9d4 100755 --- a/git_auto_svn.py +++ b/git_auto_svn.py @@ -23,7 +23,7 @@ import subprocess2 from git_common import run as run_git from git_common import run_stream as run_git_stream 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' @@ -58,14 +58,11 @@ def main(argv): parser.parse_args(argv) upstream = root() - message = run_git('log', '-1', '--format=%B', upstream) - footers = parse_footers(message) - git_svn_id = get_unique(footers, 'git-svn-id') - match = GIT_SVN_ID_PATTERN.match(git_svn_id) - assert match, 'No valid git-svn-id footer found on %s.' % upstream - print 'Found git-svn-id footer %s on %s' % (match.group(1), upstream) - - parsed_svn = urlparse.urlparse(match.group(1)) + 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) + + parsed_svn = urlparse.urlparse(svn_id) path_components = parsed_svn.path.split('/') svn_repo = None svn_path = None @@ -86,7 +83,7 @@ def main(argv): ' from https://chromium-access.appspot.com' % maybe_repo) print 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) set_config('svn-remote.svn.url', svn_repo) diff --git a/git_cl.py b/git_cl.py index b6810e8b6b..7c3f530b7c 100755 --- a/git_cl.py +++ b/git_cl.py @@ -44,6 +44,7 @@ import dart_format import fix_encoding import gclient_utils import git_common +from git_footers import get_footer_svn_id import owners import owners_finder import presubmit_support @@ -2645,13 +2646,20 @@ def IsFatalPushFailure(push_stdout): def CMDdcommit(parser, args): """Commits the current changelist via git-svn.""" if not settings.GetIsGitSvn(): - message = """This doesn't appear to be an SVN repository. -If your project has a git mirror with an upstream SVN master, you probably need -to run 'git svn init', see your project's git mirror documentation. -If your project has a true writeable upstream repository, you probably want -to run 'git cl land' instead. -Choose wisely, if you get this wrong, your commit might appear to succeed but -will instead be silently ignored.""" + if get_footer_svn_id(): + # If it looks like previous commits were mirrored with git-svn. + message = """This repository appears to be a git-svn mirror, but no +upstream SVN master is set. You probably need to run 'git auto-svn' once.""" + else: + message = """This doesn't appear to be an SVN repository. +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) ask_for_data('[Press enter to dcommit or ctrl-C to quit]') return SendUpstream(parser, args, 'dcommit') @@ -2660,9 +2668,10 @@ will instead be silently ignored.""" @subcommand.usage('[upstream branch to apply against]') def CMDland(parser, args): """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('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]') return SendUpstream(parser, args, 'land') diff --git a/git_footers.py b/git_footers.py index 01a4cd5805..3e3ea827ba 100755 --- a/git_footers.py +++ b/git_footers.py @@ -48,6 +48,20 @@ def parse_footers(message): 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): key = normalize_name(key) values = footers[key]