summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--CHANGELOG.md8
-rw-r--r--pre_commit/languages/golang.py3
-rw-r--r--setup.cfg2
-rw-r--r--tests/languages/golang_test.py31
4 files changed, 42 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be2fee6..6c2ee94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+3.6.2 - 2024-02-18
+==================
+
+### Fixes
+- Fix building golang hooks during `git commit --all`.
+ - #3130 PR by @asottile.
+ - #2722 issue by @pestanko and @matthewhughes934.
+
3.6.1 - 2024-02-10
==================
diff --git a/pre_commit/languages/golang.py b/pre_commit/languages/golang.py
index 4c13d8f..66e07cf 100644
--- a/pre_commit/languages/golang.py
+++ b/pre_commit/languages/golang.py
@@ -23,6 +23,7 @@ from pre_commit import lang_base
from pre_commit.envcontext import envcontext
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import Var
+from pre_commit.git import no_git_env
from pre_commit.prefix import Prefix
from pre_commit.util import cmd_output
from pre_commit.util import rmtree
@@ -141,7 +142,7 @@ def install_environment(
else:
gopath = env_dir
- env = dict(os.environ, GOPATH=gopath)
+ env = no_git_env(dict(os.environ, GOPATH=gopath))
env.pop('GOBIN', None)
if version != 'system':
env['GOROOT'] = os.path.join(env_dir, '.go')
diff --git a/setup.cfg b/setup.cfg
index 2002a68..a447bbb 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,6 +1,6 @@
[metadata]
name = pre_commit
-version = 3.6.1
+version = 3.6.2
description = A framework for managing and maintaining multi-language pre-commit hooks.
long_description = file: README.md
long_description_content_type = text/markdown
diff --git a/tests/languages/golang_test.py b/tests/languages/golang_test.py
index 19e9f62..02e35d7 100644
--- a/tests/languages/golang_test.py
+++ b/tests/languages/golang_test.py
@@ -7,10 +7,16 @@ import re_assert
import pre_commit.constants as C
from pre_commit import lang_base
+from pre_commit.commands.install_uninstall import install
from pre_commit.envcontext import envcontext
from pre_commit.languages import golang
from pre_commit.store import _make_local_repo
+from pre_commit.util import cmd_output
+from testing.fixtures import add_config_to_repo
+from testing.fixtures import make_config_from_repo
from testing.language_helpers import run_language
+from testing.util import cmd_output_mocked_pre_commit_home
+from testing.util import git_commit
ACTUAL_GET_DEFAULT_VERSION = golang.get_default_version.__wrapped__
@@ -134,3 +140,28 @@ def test_local_golang_additional_deps(tmp_path):
def test_golang_hook_still_works_when_gobin_is_set(tmp_path):
with envcontext((('GOBIN', str(tmp_path.joinpath('gobin'))),)):
test_golang_system(tmp_path)
+
+
+def test_during_commit_all(tmp_path, tempdir_factory, store, in_git_dir):
+ hook_dir = tmp_path.joinpath('hook')
+ hook_dir.mkdir()
+ _make_hello_world(hook_dir)
+ hook_dir.joinpath('.pre-commit-hooks.yaml').write_text(
+ '- id: hello-world\n'
+ ' name: hello world\n'
+ ' entry: golang-hello-world\n'
+ ' language: golang\n'
+ ' always_run: true\n',
+ )
+ cmd_output('git', 'init', hook_dir)
+ cmd_output('git', 'add', '.', cwd=hook_dir)
+ git_commit(cwd=hook_dir)
+
+ add_config_to_repo(in_git_dir, make_config_from_repo(hook_dir))
+
+ assert not install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
+
+ git_commit(
+ fn=cmd_output_mocked_pre_commit_home,
+ tempdir_factory=tempdir_factory,
+ )