1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-03 01:18:10 +03:00

wscript: fix installing pre-commit with 'git worktree'

.git is not always a directory, with 'git worktree' it's a file.

'git rev-parse --git-path hooks' is the generic way to find the
patch for the githooks.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>

Autobuild-User(master): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(master): Thu Aug 12 08:56:13 UTC 2021 on sn-devel-184

(cherry picked from commit 8858cf72af)

Autobuild-User(v4-14-test): Stefan Metzmacher <metze@samba.org>
Autobuild-Date(v4-14-test): Thu Aug 12 11:49:18 UTC 2021 on sn-devel-184
This commit is contained in:
Stefan Metzmacher 2021-08-11 13:26:41 +02:00
parent e393635ab8
commit a8b40f15f9

16
wscript
View File

@ -148,9 +148,19 @@ def configure(conf):
conf.env.DEVELOPER = True
# if we are in a git tree without a pre-commit hook, install a
# simple default.
pre_commit_hook = os.path.join(Context.g_module.top, '.git/hooks/pre-commit')
if (os.path.isdir(os.path.dirname(pre_commit_hook)) and
not os.path.exists(pre_commit_hook)):
# we need git for 'waf dist'
githooksdir = None
conf.find_program('git', var='GIT')
if 'GIT' in conf.env:
githooksdir = conf.CHECK_COMMAND('%s rev-parse --git-path hooks' % conf.env.GIT[0],
msg='Finding githooks directory',
define=None,
on_target=False)
if githooksdir and os.path.isdir(githooksdir):
pre_commit_hook = os.path.join(githooksdir, 'pre-commit')
if not os.path.exists(pre_commit_hook):
Logs.info("Installing script/git-hooks/pre-commit-hook as %s" %
pre_commit_hook)
shutil.copy(os.path.join(Context.g_module.top, 'script/git-hooks/pre-commit-hook'),
pre_commit_hook)