Install commit hook into submodules

If there are submodules, the commit hook should be installed into them,
according to https://gerrit-review.googlesource.com/Documentation/dev-crafting-changes.html#git-commit-settings

git submodule foreach is a no-op if there are no submodules, so just run
it directly.

Change-Id: I559e2786c84be9975cc082bce80b32c8e47a9fb5
This commit is contained in:
Monty Taylor 2019-08-25 16:53:04 +02:00
parent dba41b2532
commit f9340df184

View File

@ -352,6 +352,12 @@ def set_hooks_commit_msg(remote, target_file):
% (userhost, (":%s" % port) if port else "")
print("Fetching commit hook from: %s" % hook_url)
run_command_exc(CannotInstallHook, *cmd)
# If there are submodules, the hook needs to be installed into
# each of them.
run_command_exc(
CannotInstallHook,
"git", "submodule", "foreach",
'cp -p %s "$(git rev-parse --git-dir)/hooks/"' % target_file)
if not os.access(target_file, os.X_OK):
os.chmod(target_file, os.path.stat.S_IREAD | os.path.stat.S_IEXEC)