Commit 09d7a6a8 authored by tandrii@chromium.org's avatar tandrii@chromium.org

git cl upload for Gerit no-squash: correct detect missing Change-Id.

BUG=579183

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299105 0039d316-1c4b-4281-b951-d872f2087c98
parent b371370e
...@@ -48,7 +48,7 @@ import dart_format ...@@ -48,7 +48,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 git_footers
import owners import owners
import owners_finder import owners_finder
import presubmit_support import presubmit_support
...@@ -2146,7 +2146,7 @@ def AddChangeIdToCommitMessage(options, args): ...@@ -2146,7 +2146,7 @@ def AddChangeIdToCommitMessage(options, args):
git_command = ['commit', '--amend', '-m', log_desc] git_command = ['commit', '--amend', '-m', log_desc]
RunGit(git_command) RunGit(git_command)
new_log_desc = CreateDescriptionFromLog(args) new_log_desc = CreateDescriptionFromLog(args)
if CHANGE_ID in new_log_desc: if git_footers.get_footer_change_id(new_log_desc):
print 'git-cl: Added Change-Id to commit message.' print 'git-cl: Added Change-Id to commit message.'
else: else:
print >> sys.stderr, 'ERROR: Gerrit commit-msg hook not available.' print >> sys.stderr, 'ERROR: Gerrit commit-msg hook not available.'
...@@ -2264,7 +2264,7 @@ def GerritUpload(options, args, cl, change): ...@@ -2264,7 +2264,7 @@ def GerritUpload(options, args, cl, change):
ref_to_push = RunGit(['commit-tree', tree, '-p', parent, ref_to_push = RunGit(['commit-tree', tree, '-p', parent,
'-m', message]).strip() '-m', message]).strip()
else: else:
if CHANGE_ID not in change_desc.description: if not git_footers.get_footer_change_id(change_desc.description):
AddChangeIdToCommitMessage(options, args) AddChangeIdToCommitMessage(options, args)
ref_to_push = 'HEAD' ref_to_push = 'HEAD'
parent = '%s/%s' % (gerrit_remote, branch) parent = '%s/%s' % (gerrit_remote, branch)
...@@ -3076,7 +3076,7 @@ def IsFatalPushFailure(push_stdout): ...@@ -3076,7 +3076,7 @@ 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():
if get_footer_svn_id(): if git_footers.get_footer_svn_id():
# If it looks like previous commits were mirrored with git-svn. # If it looks like previous commits were mirrored with git-svn.
message = """This repository appears to be a git-svn mirror, but no 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.""" upstream SVN master is set. You probably need to run 'git auto-svn' once."""
...@@ -3098,7 +3098,7 @@ proceed, please verify that the commit lands upstream as expected.""" ...@@ -3098,7 +3098,7 @@ proceed, please verify that the commit lands upstream as expected."""
@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() or get_footer_svn_id(): if settings.GetIsGitSvn() or git_footers.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)') print('(Ignore if this is the first commit after migrating from svn->git)')
......
...@@ -660,6 +660,8 @@ class TestGitCl(TestCase): ...@@ -660,6 +660,8 @@ class TestGitCl(TestCase):
self.calls += self._gerrit_upload_calls( self.calls += self._gerrit_upload_calls(
description, reviewers, squash, description, reviewers, squash,
expected_upstream_ref=expected_upstream_ref) expected_upstream_ref=expected_upstream_ref)
# Uncomment when debugging.
# print '\n'.join(map(lambda x: '%2i: %s' % x, enumerate(self.calls)))
git_cl.main(['upload'] + upload_args) git_cl.main(['upload'] + upload_args)
def test_gerrit_upload_without_change_id(self): def test_gerrit_upload_without_change_id(self):
...@@ -671,20 +673,20 @@ class TestGitCl(TestCase): ...@@ -671,20 +673,20 @@ class TestGitCl(TestCase):
def test_gerrit_no_reviewer(self): def test_gerrit_no_reviewer(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
'desc\n\nBUG=\nChange-Id:123456789\n', 'desc\n\nBUG=\n\nChange-Id: I123456789\n',
[]) [])
def test_gerrit_reviewers_cmd_line(self): def test_gerrit_reviewers_cmd_line(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
['-r', 'foo@example.com'], ['-r', 'foo@example.com'],
'desc\n\nBUG=\nChange-Id:123456789', 'desc\n\nBUG=\n\nChange-Id: I123456789',
['foo@example.com']) ['foo@example.com'])
def test_gerrit_reviewer_multiple(self): def test_gerrit_reviewer_multiple(self):
self._run_gerrit_upload_test( self._run_gerrit_upload_test(
[], [],
'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n' 'desc\nTBR=reviewer@example.com\nBUG=\nR=another@example.com\n\n'
'Change-Id:123456789\n', 'Change-Id: 123456789\n',
['reviewer@example.com', 'another@example.com']) ['reviewer@example.com', 'another@example.com'])
def test_gerrit_upload_squash(self): def test_gerrit_upload_squash(self):
......
...@@ -73,6 +73,10 @@ My commit message is my best friend. It is my life. I must master it. ...@@ -73,6 +73,10 @@ My commit message is my best friend. It is my life. I must master it.
'', # Above is ignored because of this empty line. '', # Above is ignored because of this empty line.
'Change-Id: Ideadbeaf']) 'Change-Id: Ideadbeaf'])
self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg)) self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg))
self.assertEqual([], git_footers.get_footer_change_id(
'desc\nBUG=not-a-valid-footer\nChange-Id: Ixxx'))
self.assertEqual(['Ixxx'], git_footers.get_footer_change_id(
'desc\nBUG=not-a-valid-footer\n\nChange-Id: Ixxx'))
def testAddFooterChangeId(self): def testAddFooterChangeId(self):
self.assertEqual( self.assertEqual(
......
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