Skip to content

Commit

Permalink
Merge pull request #970 from GitGuardian/agateau/ignore-git-config
Browse files Browse the repository at this point in the history
Fix parsing patches when the diff.noprefix git config option is set
  • Loading branch information
agateau-gg committed Sep 30, 2024
2 parents 50b56bb + c97aab6 commit 804e3a3
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 49 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- Fixed a case where ggshield commit parser could fail because of the local git configuration.
13 changes: 1 addition & 12 deletions docker/actions-iac-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
# AUTOGENERATED FILE, DO NOT EDIT!
# This file has been generated by the `action-entrypoint-generator` script
# defined in `scripts/action-entrypoint-generator`. To make changes to this
# file, modify the script and rerun it.


# Mark the current directory as safe. If we don't do this, git commands fail
# because the source in $PWD is owned by a different user than our `app` user.
git config --global --add safe.directory "$PWD"


args=("$@")
ggshield iac scan ci ${args[@]}
exec /app/docker/entrypoint.sh ggshield iac scan ci ${args[@]}
13 changes: 1 addition & 12 deletions docker/actions-sca-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
# AUTOGENERATED FILE, DO NOT EDIT!
# This file has been generated by the `action-entrypoint-generator` script
# defined in `scripts/action-entrypoint-generator`. To make changes to this
# file, modify the script and rerun it.


# Mark the current directory as safe. If we don't do this, git commands fail
# because the source in $PWD is owned by a different user than our `app` user.
git config --global --add safe.directory "$PWD"


args=("$@")
ggshield sca scan ci -v ${args[@]}
exec /app/docker/entrypoint.sh ggshield sca scan ci -v ${args[@]}
13 changes: 1 addition & 12 deletions docker/actions-secret-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,4 @@
#!/usr/bin/env bash
set -euo pipefail
# AUTOGENERATED FILE, DO NOT EDIT!
# This file has been generated by the `action-entrypoint-generator` script
# defined in `scripts/action-entrypoint-generator`. To make changes to this
# file, modify the script and rerun it.


# Mark the current directory as safe. If we don't do this, git commands fail
# because the source in $PWD is owned by a different user than our `app` user.
git config --global --add safe.directory "$PWD"


args=("$@")
ggshield secret scan -v ${args[@]} ci
exec /app/docker/entrypoint.sh ggshield secret scan -v ${args[@]} ci
6 changes: 5 additions & 1 deletion docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail

export GG_GIT_CONFIG=/tmp/ggshield-git-config

# Mark the current directory as safe. If we don't do this, git commands fail
# because the source in $PWD is owned by a different user than our `app` user.
git config --global --add safe.directory "$PWD"
#
# We use our own git config because ggshield ignores the global git configuration file.
git config --file "$GG_GIT_CONFIG" --add safe.directory "$PWD"

exec "$@"
5 changes: 5 additions & 0 deletions ggshield/utils/git_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ def git(
) -> str:
"""Calls git with the given arguments, returns stdout as a string"""
env = os.environ.copy()
# Ensure git messages are in English
env["LANG"] = "C"
# Ensure git behavior is not affected by the user git configuration, but give us a
# way to set some configuration (useful for safe.directory)
env["GIT_CONFIG_GLOBAL"] = os.getenv("GG_GIT_CONFIG", "")
env["GIT_CONFIG_SYSTEM"] = ""

if cwd is None:
cwd = Path.cwd()
Expand Down
12 changes: 0 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,18 +75,6 @@ def is_windows():
"""


@pytest.fixture(scope="session", autouse=True)
def isolated_git():
"""
Don't use any of the existing Git config
NOTE: As the fixture is scoped to the session we don't have to restore the
original values.
"""
os.environ["GIT_CONFIG_GLOBAL"] = ""
os.environ["GIT_CONFIG_SYSTEM"] = ""


@pytest.fixture(autouse=True)
def do_not_use_real_user_dirs(monkeypatch, tmp_path):
"""
Expand Down

0 comments on commit 804e3a3

Please sign in to comment.