From bfba7121129317c9b8093ede4c6a3db5a1cf3fe0 Mon Sep 17 00:00:00 2001
From: Amin Bandali <amin.bandali@savoirfairelinux.com>
Date: Mon, 11 Jul 2022 14:31:32 -0400
Subject: [PATCH] build: Make sure the 'hooks' directory for each submodule
 exists

git-init may not create the hooks directory with the default sample
hooks in some scenarios, for example if the user has set the
init.templateDir configuration option in their global git config, and
if that directory does not include a hooks subdirectory then no hooks
directory will be created by git-init, including for clones and
submodule initializations.

Change-Id: I09ce586fd36d3db9224bbbeed5d7721d6635ea7b
---
 build.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/build.py b/build.py
index 18a89489..50f271b5 100755
--- a/build.py
+++ b/build.py
@@ -392,15 +392,18 @@ def run_init():
     subprocess.run(["git", "submodule", "update", "--init"], check=True)
     subprocess.run(["git", "submodule", "foreach",
                     "git checkout master && git pull"], check=True)
+
     for name in module_names:
-        copy_file("./scripts/commit-msg", ".git/modules/"+name+"/hooks")
+        hooks_dir = ".git/modules/" + name + "/hooks"
+        if not os.path.exists(hooks_dir):
+            os.makedirs(hooks_dir)
+        copy_file("./scripts/commit-msg", hooks_dir + "/commit-msg")
 
     module_names_to_format = ['daemon', 'client-qt', 'plugins']
     for name in module_names_to_format:
-        execute_script(
-            ['./scripts/format.sh --install  %(path)s'],
-            {"path": ".git/modules/" + name + "/hooks"}
-        )
+        hooks_dir = ".git/modules/" + name + "/hooks"
+        execute_script(['./scripts/format.sh --install %(path)s'],
+                       {"path": hooks_dir})
 
 
 def copy_file(src, dest):
-- 
GitLab