Skip to content

Commit 804e3a3

Browse files
authored
Merge pull request #970 from GitGuardian/agateau/ignore-git-config
Fix parsing patches when the diff.noprefix git config option is set
2 parents 50b56bb + c97aab6 commit 804e3a3

File tree

7 files changed

+16
-49
lines changed

7 files changed

+16
-49
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Fixed
2+
3+
- Fixed a case where ggshield commit parser could fail because of the local git configuration.

docker/actions-iac-entrypoint.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
# AUTOGENERATED FILE, DO NOT EDIT!
4-
# This file has been generated by the `action-entrypoint-generator` script
5-
# defined in `scripts/action-entrypoint-generator`. To make changes to this
6-
# file, modify the script and rerun it.
7-
8-
9-
# Mark the current directory as safe. If we don't do this, git commands fail
10-
# because the source in $PWD is owned by a different user than our `app` user.
11-
git config --global --add safe.directory "$PWD"
12-
13-
143
args=("$@")
15-
ggshield iac scan ci ${args[@]}
4+
exec /app/docker/entrypoint.sh ggshield iac scan ci ${args[@]}

docker/actions-sca-entrypoint.sh

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
# AUTOGENERATED FILE, DO NOT EDIT!
4-
# This file has been generated by the `action-entrypoint-generator` script
5-
# defined in `scripts/action-entrypoint-generator`. To make changes to this
6-
# file, modify the script and rerun it.
7-
8-
9-
# Mark the current directory as safe. If we don't do this, git commands fail
10-
# because the source in $PWD is owned by a different user than our `app` user.
11-
git config --global --add safe.directory "$PWD"
12-
13-
143
args=("$@")
15-
ggshield sca scan ci -v ${args[@]}
4+
exec /app/docker/entrypoint.sh ggshield sca scan ci -v ${args[@]}
Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
3-
# AUTOGENERATED FILE, DO NOT EDIT!
4-
# This file has been generated by the `action-entrypoint-generator` script
5-
# defined in `scripts/action-entrypoint-generator`. To make changes to this
6-
# file, modify the script and rerun it.
7-
8-
9-
# Mark the current directory as safe. If we don't do this, git commands fail
10-
# because the source in $PWD is owned by a different user than our `app` user.
11-
git config --global --add safe.directory "$PWD"
12-
13-
143
args=("$@")
15-
ggshield secret scan -v ${args[@]} ci
4+
exec /app/docker/entrypoint.sh ggshield secret scan -v ${args[@]} ci

docker/entrypoint.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
export GG_GIT_CONFIG=/tmp/ggshield-git-config
5+
46
# Mark the current directory as safe. If we don't do this, git commands fail
57
# because the source in $PWD is owned by a different user than our `app` user.
6-
git config --global --add safe.directory "$PWD"
8+
#
9+
# We use our own git config because ggshield ignores the global git configuration file.
10+
git config --file "$GG_GIT_CONFIG" --add safe.directory "$PWD"
711

812
exec "$@"

ggshield/utils/git_shell.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,12 @@ def git(
189189
) -> str:
190190
"""Calls git with the given arguments, returns stdout as a string"""
191191
env = os.environ.copy()
192+
# Ensure git messages are in English
192193
env["LANG"] = "C"
194+
# Ensure git behavior is not affected by the user git configuration, but give us a
195+
# way to set some configuration (useful for safe.directory)
196+
env["GIT_CONFIG_GLOBAL"] = os.getenv("GG_GIT_CONFIG", "")
197+
env["GIT_CONFIG_SYSTEM"] = ""
193198

194199
if cwd is None:
195200
cwd = Path.cwd()

tests/conftest.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,6 @@ def is_windows():
7575
"""
7676

7777

78-
@pytest.fixture(scope="session", autouse=True)
79-
def isolated_git():
80-
"""
81-
Don't use any of the existing Git config
82-
83-
NOTE: As the fixture is scoped to the session we don't have to restore the
84-
original values.
85-
"""
86-
os.environ["GIT_CONFIG_GLOBAL"] = ""
87-
os.environ["GIT_CONFIG_SYSTEM"] = ""
88-
89-
9078
@pytest.fixture(autouse=True)
9179
def do_not_use_real_user_dirs(monkeypatch, tmp_path):
9280
"""

0 commit comments

Comments
 (0)