From 57d8654568a17d740fa096b88e25c7900d392557 Mon Sep 17 00:00:00 2001 From: "tandrii@chromium.org" Date: Fri, 4 Mar 2016 16:11:32 +0000 Subject: [PATCH] git cl for Gerrit: make --squash generate Change-Id directly. BUG=579183 Review URL: https://codereview.chromium.org/1763593002 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299107 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cl.py | 38 +++++++------------------------------- tests/git_cl_test.py | 3 ++- 2 files changed, 9 insertions(+), 32 deletions(-) diff --git a/git_cl.py b/git_cl.py index fe03778ba..bd2eae9c8 100755 --- a/git_cl.py +++ b/git_cl.py @@ -64,7 +64,6 @@ DEFAULT_SERVER = 'https://codereview.appspot.com' POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' GIT_INSTRUCTIONS_URL = 'http://code.google.com/p/chromium/wiki/UsingGit' -CHANGE_ID = 'Change-Id:' REFS_THAT_ALIAS_TO_OTHER_REFS = { 'refs/remotes/origin/lkgr': 'refs/remotes/origin/master', 'refs/remotes/origin/lkcr': 'refs/remotes/origin/master', @@ -2212,40 +2211,17 @@ def GerritUpload(options, args, cl, change): if not message: if not options.force: change_desc.prompt() - - if CHANGE_ID not in change_desc.description: - # Run the commit-msg hook without modifying the head commit by writing - # the commit message to a temporary file and running the hook over it, - # then reading the file back in. - commit_msg_hook = os.path.join(settings.GetRoot(), '.git', 'hooks', - 'commit-msg') - file_handle, msg_file = tempfile.mkstemp(text=True, - prefix='commit_msg') - logging.debug("%s %s", file_handle, msg_file) - try: - try: - try: - fileobj = os.fdopen(file_handle, 'w') - except OSError: - # if fdopen fails, file_handle remains open. - # See https://docs.python.org/2/library/os.html#os.fdopen. - os.close(file_handle) - raise - with fileobj: - # This will close the file_handle. - fileobj.write(change_desc.description) - logging.debug("%s %s finish editing", file_handle, msg_file) - finally: - RunCommand([commit_msg_hook, msg_file]) - change_desc.set_description(gclient_utils.FileRead(msg_file)) - finally: - os.remove(msg_file) - if not change_desc.description: print "Description is empty; aborting." return 1 - message = change_desc.description + change_ids = git_footers.get_footer_change_id(message) + if len(change_ids) > 1: + DieWithError('too many Change-Id footers in %s branch' % shadow_branch) + if not change_ids: + message = git_footers.add_footer_change_id( + message, GenerateGerritChangeId(message)) + change_desc.set_description(message) remote, upstream_branch = cl.FetchUpstreamTuple(cl.GetBranch()) if remote is '.': diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py index f1cee8a27..e4a412b79 100755 --- a/tests/git_cl_test.py +++ b/tests/git_cl_test.py @@ -17,6 +17,7 @@ from testing_support.auto_stub import TestCase import git_cl import git_common +import git_footers import subprocess2 class PresubmitMock(object): @@ -588,7 +589,7 @@ class TestGitCl(TestCase): 'fake_ancestor_sha..HEAD'],), description) ] - if git_cl.CHANGE_ID not in description: + if not git_footers.get_footer_change_id(description) and not squash: calls += [ ((['git', 'log', '--pretty=format:%s\n\n%b', 'fake_ancestor_sha..HEAD'],),