Chromium Code Reviews| Index: git_cl.py |
| diff --git a/git_cl.py b/git_cl.py |
| index 3cb66231ff896fba995c2e60c8d77b250fe021ce..4067a9e50f4e9d8212f13cb09c8c98821a7d5272 100755 |
| --- a/git_cl.py |
| +++ b/git_cl.py |
| @@ -1038,6 +1038,14 @@ def urlretrieve(source, destination): |
| f.write(urllib2.urlopen(source).read()) |
| +def checkHookScript(fname): |
|
M-A Ruel
2013/11/26 14:06:56
s/checkHookScript/hasSheBang/
ukai
2013/11/26 14:17:20
Done.
|
| + """Checks fname is a script.""" |
| + with open(fname) as f: |
| + s = f.read() |
|
M-A Ruel
2013/11/26 14:06:56
return f.read(2).startswith('#!'):
ukai
2013/11/26 14:17:20
Done.
|
| + if not s.startswith('#!'): |
| + raise Exception('unexpected script') |
| + |
| + |
| def DownloadHooks(force): |
| """downloads hooks |
| @@ -1046,21 +1054,23 @@ 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) |
| + checkHookScript(dst) |
|
M-A Ruel
2013/11/26 14:06:56
if not hasSheBang(dst):
DieWithError('Not a scri
ukai
2013/11/26 14:17:20
Done.
|
| 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]') |