mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-17 15:22:59 +01:00
pre-commit: installed git hook should have full path to binary (#77638)
pre-commit currently install impure Git hooks that look for the `pre-commit` binary in PATH. If the user has `pre-commit` loaded via a nix-shell instead of having it installed then GUI editors, such as Intellij, won't be able to use Git commit because the hook fails trying to look for the `pre-commit` binary in PATH. This patch updates the hook template to use the hardcoded path to the `pre-commit` binary if it was found, fallback to using the one from PATH.
This commit is contained in:
parent
65e6812dc8
commit
1882d20155
2 changed files with 35 additions and 0 deletions
|
@ -7,6 +7,7 @@
|
||||||
, importlib-metadata
|
, importlib-metadata
|
||||||
, importlib-resources
|
, importlib-resources
|
||||||
, nodeenv
|
, nodeenv
|
||||||
|
, python
|
||||||
, six
|
, six
|
||||||
, toml
|
, toml
|
||||||
, virtualenv
|
, virtualenv
|
||||||
|
@ -22,6 +23,10 @@ buildPythonApplication rec {
|
||||||
sha256 = "0l5qg1cw4a0670m96s0ryy5mqz5aslfrrnwpriqgmrnsgdixhj4g";
|
sha256 = "0l5qg1cw4a0670m96s0ryy5mqz5aslfrrnwpriqgmrnsgdixhj4g";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
patches = [
|
||||||
|
./hook-tmpl-use-the-hardcoded-path-to-pre-commit.patch
|
||||||
|
];
|
||||||
|
|
||||||
propagatedBuildInputs = [
|
propagatedBuildInputs = [
|
||||||
aspy-yaml
|
aspy-yaml
|
||||||
cached-property
|
cached-property
|
||||||
|
@ -38,6 +43,11 @@ buildPythonApplication rec {
|
||||||
# slow and impure
|
# slow and impure
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
|
|
||||||
|
preFixup = ''
|
||||||
|
substituteInPlace $out/${python.sitePackages}/pre_commit/resources/hook-tmpl \
|
||||||
|
--subst-var-by pre-commit $out
|
||||||
|
'';
|
||||||
|
|
||||||
meta = with lib; {
|
meta = with lib; {
|
||||||
description = "A framework for managing and maintaining multi-language pre-commit hooks";
|
description = "A framework for managing and maintaining multi-language pre-commit hooks";
|
||||||
homepage = https://pre-commit.com/;
|
homepage = https://pre-commit.com/;
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
From d9e6999e32112602ec276634cb004eda3ca64ec3 Mon Sep 17 00:00:00 2001
|
||||||
|
From: "Wael M. Nasreddine" <wael.nasreddine@gmail.com>
|
||||||
|
Date: Mon, 13 Jan 2020 11:04:58 -0800
|
||||||
|
Subject: [PATCH] hook-tmpl: use the hardcoded path to pre-commit, if found
|
||||||
|
|
||||||
|
---
|
||||||
|
pre_commit/resources/hook-tmpl | 2 ++
|
||||||
|
1 file changed, 2 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/pre_commit/resources/hook-tmpl b/pre_commit/resources/hook-tmpl
|
||||||
|
index 213d16e..3a99211 100755
|
||||||
|
--- a/pre_commit/resources/hook-tmpl
|
||||||
|
+++ b/pre_commit/resources/hook-tmpl
|
||||||
|
@@ -107,6 +107,8 @@ def _exe() -> Tuple[str, ...]:
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
+ if os.path.isfile('@pre-commit@/bin/pre-commit') and os.access('@pre-commit@/bin/pre-commit', os.X_OK):
|
||||||
|
+ return ('@pre-commit@/bin/pre-commit', 'run')
|
||||||
|
if distutils.spawn.find_executable('pre-commit'):
|
||||||
|
return ('pre-commit', 'run')
|
||||||
|
|
||||||
|
--
|
||||||
|
2.23.1
|
||||||
|
|
Loading…
Reference in a new issue