GitGuardian / ggshield

Find and fix 400+ types of hardcoded secrets and 70+ types of infrastructure-as-code misconfigurations.
https://gitguardian.com
MIT License
1.68k stars 150 forks source link

Fix parsing patches when the diff.noprefix git config option is set #970

Closed agateau-gg closed 1 month ago

agateau-gg commented 1 month ago

Context

If diff.noprefix is set in the git config, then our patch parser fails.

What has been done

Set the appropriate environment variables to ignore any git configuration.

Note: We used to ignore the config in our test suite, but this commit removes that to increase our chances of catching errors in case calls to git which do not go through git_shell.git() are added in the future (even if there should not be any).

Validation

# Enable the option globally
git config --global --add diff.noprefix true

mkdir repo
cd repo
git init
ggshield install -m local

echo t > test
git add test

# This fails with `main` and passes with this branch
git commit -m "test"

# Reset the option
git config --global --unset-all diff.noprefix

PR check list

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 91.74%. Comparing base (50b56bb) to head (c97aab6). Report is 2 commits behind head on main.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #970 +/- ## ======================================= Coverage 91.74% 91.74% ======================================= Files 178 178 Lines 7459 7461 +2 ======================================= + Hits 6843 6845 +2 Misses 616 616 ``` | [Flag](https://app.codecov.io/gh/GitGuardian/ggshield/pull/970/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/GitGuardian/ggshield/pull/970/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian) | `91.74% <100.00%> (+<0.01%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GitGuardian#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.