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

Unified Diff: git_cl.py

Issue 87173002: Download commit-msg from gerrit-review.googlesource.com (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: change checkHookScript to hasSheBang, etc Created 7 years, 1 month 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 3cb66231ff896fba995c2e60c8d77b250fe021ce..5e166324f10d66ba82eb5703c94eeca4f17692b5 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -1038,6 +1038,12 @@ def urlretrieve(source, destination):
f.write(urllib2.urlopen(source).read())
+def hasSheBang(fname):
+ """Checks fname is a #! script."""
+ with open(fname) as f:
+ return f.read(2).startswith('#!')
+
+
def DownloadHooks(force):
"""downloads hooks
@@ -1046,21 +1052,27 @@ def DownloadHooks(force):
"""
if not settings.GetIsGerrit():
return
- server_url = settings.GetDefaultServerUrl()
- src = '%s/tools/hooks/commit-msg' % server_url
+ src = 'https://gerrit-review.googlesource.com/tools/hooks/commit-msg'
dst = os.path.join(settings.GetRoot(), '.git', 'hooks', 'commit-msg')
if not os.access(dst, os.X_OK):
if os.path.exists(dst):
if not force:
return
- os.remove(dst)
try:
urlretrieve(src, dst)
+ if not hasSheBang(dst):
+ DieWithError('Not a script: %s\n'
+ 'You need to download from\n%s\n'
+ 'into .git/hooks/commit-msg and '
+ 'chmod +x .git/hooks/commit-msg' % (dst, src))
os.chmod(dst, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
except Exception:
if os.path.exists(dst):
os.remove(dst)
- DieWithError('\nFailed to download hooks from %s' % src)
+ DieWithError('\nFailed to download hooks.\n'
+ 'You need to download from\n%s\n'
+ 'into .git/hooks/commit-msg and '
+ 'chmod +x .git/hooks/commit-msg' % src)
@subcommand.usage('[repo root containing codereview.settings]')
« 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