Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(758)

Unified Diff: git_cl.py

Issue 2045973002: Gerrit git cl upload: warn and offer to remove Gerrit commit-msg hook. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: review Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: git_cl.py
diff --git a/git_cl.py b/git_cl.py
index a08141bbe2967eff217db328b9ce8e9c02c856c2..3a98f8794164328d83efcef7ce138b2c5217b18e 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -2314,6 +2314,27 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
hostname=parsed_url.netloc)
return None
+ def _GerritCommitMsgHookCheck(self, offer_removal):
+ hook = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg')
+ if not os.path.exists(hook):
+ return
+ # Crude attempt to distinguish Gerrit Codereview hook from potentially
+ # custom developer made one.
+ data = gclient_utils.FileRead(hook)
+ if not('From Gerrit Code Review' in data and 'add_ChangeId()' in data):
+ return
+ print('Warning: you have Gerrit commit-msg hook installed.\n'
+ 'It is not neccessary for uploading with git cl in squash mode, '
+ 'and may interfere with it in subtle ways.\n'
+ 'We recommend you remove the commit-msg hook.')
+ if offer_removal:
+ reply = ask_for_data('Do you want to remove it now? [Yes/No]')
+ if reply.lower().startswith('y'):
+ gclient_utils.rm_file_or_tree(hook)
+ print('Gerrit commit-msg hook removed.')
+ else:
+ print('OK, will keep Gerrit commit-msg hook in place.')
+
def CMDUploadChange(self, options, args, change):
"""Upload the current branch to Gerrit."""
if options.squash and options.no_squash:
@@ -2329,6 +2350,7 @@ class _GerritChangelistImpl(_ChangelistCodereviewBase):
pending_prefix='')
if options.squash:
+ self._GerritCommitMsgHookCheck(offer_removal=not options.force)
if not self.GetIssue():
# TODO(tandrii): deperecate this after 2016Q2. Backwards compatibility
# with shadow branch, which used to contain change-id for a given
« no previous file with comments | « no previous file | tests/git_cl_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698