Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ggshield install -m global #978

Merged
merged 2 commits into from
Oct 15, 2024
Merged

Fix ggshield install -m global #978

merged 2 commits into from
Oct 15, 2024

Conversation

agateau-gg
Copy link
Collaborator

@agateau-gg agateau-gg commented Oct 10, 2024

Context

The fix from 1.32.1 to ignore the user git configuration when running git commands broke ggshield install -m global because this command modifies the global git config so it must not ignore the user git configuration.

This is #972.

What has been done

  • Add a ignore_git_config optional argument to git_shell.git(), which defaults to True. Set it to False in calls from cmd.install.
  • Make install_global() install the git hooks in a sub-directory of the dir returned by get_data_dir(), this is required to be able to have tests which fail in the situation of 1.32.1.
  • Rework test_install to be able to reproduce the bug. Add more tests.

Best reviewed commit by commit.

Validation

Run ggshield install -m global. It should not crash anymore.

PR check list

  • As much as possible, the changes include tests (unit and/or functional)
  • If the changes affect the end user (new feature, behavior change, bug fix) then the PR has a changelog entry (see doc/dev/getting-started.md). If the changes do not affect the end user, then the skip-changelog label has been added to the PR.

Copy link

codecov bot commented Oct 10, 2024

Codecov Report

Attention: Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.

Project coverage is 91.58%. Comparing base (56f53ee) to head (039f554).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
ggshield/core/dirs.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #978      +/-   ##
==========================================
+ Coverage   91.49%   91.58%   +0.08%     
==========================================
  Files         180      180              
  Lines        7597     7605       +8     
==========================================
+ Hits         6951     6965      +14     
+ Misses        646      640       -6     
Flag Coverage Δ
unittests 91.58% <92.85%> (+0.08%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@agateau-gg agateau-gg force-pushed the agateau/fix-install-global branch from e77d22f to 917752f Compare October 15, 2024 13:46
This wraps `platformdirs.user_data_dir()`. It's going to be used as the
place to store our global git hook.

Changing the place of the global git hook is required to make the code
testable. It is also going to fix the fact that having the global git
hooks created in $HOME/.git/hooks was weird: for 99% of our users, $HOME is
not a git repository.
@agateau-gg agateau-gg force-pushed the agateau/fix-install-global branch from 917752f to e397c7a Compare October 15, 2024 14:26
Problem: the fix from 1.32.1 to ignore the user git configuration when
running git commands broke `ggshield install -m global` because this
command modifies the global git config so it must not ignore the user git
configuration.

Solution:
- Add a `ignore_git_config` optional argument to `git_shell.git()`, which
  defaults to True. Set it to False in calls from cmd.install.
- Make `install_global()` install the git hooks in a sub-directory of the
  dir returned by `get_data_dir()`, this is required to be able to have
  tests which fail in the situation of 1.32.1.
- Rework test_install to be able to reproduce the bug. Add more tests.

chore: add changelog entry
@agateau-gg agateau-gg force-pushed the agateau/fix-install-global branch from e397c7a to 039f554 Compare October 15, 2024 14:48
@agateau-gg agateau-gg enabled auto-merge October 15, 2024 14:49
@agateau-gg agateau-gg merged commit 91ae9cf into main Oct 15, 2024
28 checks passed
@agateau-gg agateau-gg deleted the agateau/fix-install-global branch October 15, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants