File tree Expand file tree Collapse file tree 4 files changed +59
-2
lines changed Expand file tree Collapse file tree 4 files changed +59
-2
lines changed Original file line number Diff line number Diff line change 6
6
7
7
* fix #305 - ensure the git file finder closes filedescriptors even when errors happen
8
8
9
+ * fix #381 - clean out env vars from the git hook system to ensure correct function from within
10
+
9
11
v3.3.3
10
12
======
11
13
Original file line number Diff line number Diff line change 20
20
string_types = (str ,) if PY3 else (str , unicode ) # noqa
21
21
22
22
23
+ def no_git_env (env ):
24
+ # adapted from pre-commit
25
+ # Too many bugs dealing with environment variables and GIT:
26
+ # https://github.com/pre-commit/pre-commit/issues/300
27
+ # In git 2.6.3 (maybe others), git exports GIT_WORK_TREE while running
28
+ # pre-commit hooks
29
+ # In git 1.9.1 (maybe others), git exports GIT_DIR and GIT_INDEX_FILE
30
+ # while running pre-commit hooks in submodules.
31
+ # GIT_DIR: Causes git clone to clone wrong thing
32
+ # GIT_INDEX_FILE: Causes 'error invalid object ...' during commit
33
+ for k , v in env .items ():
34
+ if k .startswith ("GIT_" ):
35
+ trace (k , v )
36
+ return {
37
+ k : v
38
+ for k , v in env .items ()
39
+ if not k .startswith ("GIT_" )
40
+ or k in ("GIT_EXEC_PATH" , "GIT_SSH" , "GIT_SSH_COMMAND" )
41
+ }
42
+
43
+
23
44
def trace (* k ):
24
45
if DEBUG :
25
46
print (* k )
@@ -48,15 +69,15 @@ def _always_strings(env_dict):
48
69
49
70
50
71
def _popen_pipes (cmd , cwd ):
51
-
52
72
return subprocess .Popen (
53
73
cmd ,
54
74
stdout = subprocess .PIPE ,
55
75
stderr = subprocess .PIPE ,
56
76
cwd = str (cwd ),
57
77
env = _always_strings (
58
78
dict (
59
- os .environ ,
79
+ no_git_env (os .environ ),
80
+ # os.environ,
60
81
# try to disable i18n
61
82
LC_ALL = "C" ,
62
83
LANGUAGE = "" ,
Original file line number Diff line number Diff line change
1
+ #! /usr/bin/env bash
2
+ set -euxo pipefail
3
+
4
+ rm -rf y z home venv tmp
5
+
6
+ [ ! -d black ] && git clone https://github.com/psf/black
7
+ export SETUPTOOLS_SCM_DEBUG=1
8
+ export PRE_COMMIT_HOME=" $PWD /home"
9
+ export TMPDIR=" $PWD /tmp"
10
+
11
+ git init y
12
+ git init z
13
+ git -C z commit --allow-empty -m ' commit!'
14
+ git -C y submodule add " $PWD /z"
15
+ cat > " $PWD /y/.git/modules/z/hooks/pre-commit" << EOF
16
+ #!/usr/bin/env bash
17
+ virtualenv "$PWD /venv"
18
+ "$PWD /venv/bin/pip" install -e "$1 "
19
+ "$PWD /venv/bin/pip" install --no-clean "$PWD /black"
20
+ EOF
21
+ chmod +x " $PWD /y/.git/modules/z/hooks/pre-commit"
22
+ cd y/z
23
+ git commit -m " test"
Original file line number Diff line number Diff line change @@ -229,3 +229,14 @@ def test_not_matching_tags(wd):
229
229
tag_regex = r"^apache-arrow-([\.0-9]+)$" ,
230
230
git_describe_command = "git describe --dirty --tags --long --exclude *js* " ,
231
231
).startswith ("0.11.2" )
232
+
233
+
234
+ @pytest .mark .issue ("https://github.com/pypa/setuptools_scm/issues/381" )
235
+ def test_gitdir (monkeypatch , wd ):
236
+ """
237
+ """
238
+ wd .commit_testfile ()
239
+ normal = wd .version
240
+ # git hooks set this and break subsequent setuptools_scm unless we clean
241
+ monkeypatch .setenv ("GIT_DIR" , __file__ )
242
+ assert wd .version == normal
You can’t perform that action at this time.
0 commit comments