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
diff --git a/git_auto_svn.py b/git_auto_svn.py
index 0e8f341..722029c 100755
--- a/git_auto_svn.py
+++ b/git_auto_svn.py
@@ -23,7 +23,7 @@
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 @@
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)
+ 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(match.group(1))
+ parsed_svn = urlparse.urlparse(svn_id)
path_components = parsed_svn.path.split('/')
svn_repo = None
svn_path = None
@@ -86,7 +83,7 @@
' 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 b6810e8..7c3f530 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -44,6 +44,7 @@
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 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 @@
@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 01a4cd5..3e3ea82 100755
--- a/git_footers.py
+++ b/git_footers.py
@@ -48,6 +48,20 @@
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]