FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

don't leak GIT_* env into `npm install` for `language: node` by cbirkhold · Pull Request #3774 · pre-commit/pre-commit · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
3 changes: 2 additions & 1 deletion pre_commit/languages/node.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pre_commit.envcontext import PatchesT
from pre_commit.envcontext import UNSET
from pre_commit.envcontext import Var
from pre_commit.git import no_git_env
from pre_commit.languages.python import bin_dir
from pre_commit.prefix import Prefix
from pre_commit.util import cmd_output
Expand Down Expand Up @@ -103,4 +104,4 @@ def install_environment(
'npm', 'install', '--allow-git=root', '--install-links', '-g',
*pkgs,
)
lang_base.setup_cmd(prefix, install)
lang_base.setup_cmd(prefix, install, env=no_git_env())
23 changes: 23 additions & 0 deletions tests/languages/node_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,29 @@ def test_node_hook_system(tmp_path):
assert ret == (0, b'Hello World\n')


def test_node_hook_install_does_not_write_callers_index(tmp_path):
# git sets GIT_DIR / GIT_INDEX_FILE to absolute paths when running hooks
# in a submodule, `npm install git+file://...` must not inherit them
hook_repo = tmp_path.joinpath('hook')
hook_repo.mkdir()
_make_hello_world(hook_repo)

user_repo = tmp_path.joinpath('user')
cmd_output_b('git', 'init', user_repo)
user_repo.joinpath('f').touch()
cmd_output_b('git', 'add', 'f', cwd=user_repo)

git_dir = user_repo.joinpath('.git')
with envcontext.envcontext((
('GIT_DIR', str(git_dir)),
('GIT_INDEX_FILE', str(git_dir.joinpath('index'))),
)):
ret = run_language(hook_repo, node, 'node-hello')
assert ret == (0, b'Hello World\n')

assert cmd_output('git', 'ls-files', cwd=user_repo)[1] == 'f\n'


def test_node_with_user_config_set(tmp_path):
cfg = tmp_path.joinpath('cfg')
cfg.write_text('cache=/dne\n')
Expand Down
Loading

Back | FazBrowse Home | New Git URL