Skip to content

Conversation

@GG-HH
Copy link
Collaborator

@GG-HH GG-HH commented Nov 14, 2025

Fixes #1143

Context

Trying to fix error #1143

What has been done

In case the git hooks path is the husky path, add the ggshield command in the husky configuration file

Validation

See issue

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.

@GG-HH GG-HH requested a review from a team as a code owner November 14, 2025 17:49
@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 84.21053% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.94%. Comparing base (edac2af) to head (0e73973).
⚠️ Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
ggshield/cmd/install.py 84.21% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1150      +/-   ##
==========================================
- Coverage   91.97%   91.94%   -0.03%     
==========================================
  Files         144      144              
  Lines        6202     6221      +19     
==========================================
+ Hits         5704     5720      +16     
- Misses        498      501       +3     
Flag Coverage Δ
unittests 91.94% <84.21%> (-0.03%) ⬇️

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.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@GG-HH GG-HH self-assigned this Nov 14, 2025
@GG-HH GG-HH changed the title draft: feat(install): allow to install hook locally with husky feat(install): allow to install hook locally with husky Nov 17, 2025
return hooks_path


def get_local_hooks_path() -> Optional[Path]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having both get_local_hook_dir_path() and get_local_hooks_path() is confusing. Maybe name this one get_hooks_path_from_local_git_config() (a bit long, but unambiguous)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed to get_git_local_hooks_path, wdyt ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like you renamed it 😅. I would prefer my proposal but I can live with yours.

from tests.repository import Repository


def test_install_local_detects_husky(tmp_path: Path) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect a functional test to use Husky for real. Is it doable?

I think if you replace the use of run_ggshield() with a call to install_local() then this code can become a unit test for install_local().

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A functional test with husky feels a bit heavy as it would introduce the need for npm and husky. As you suggested, I moved to a unit test

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that could be heavy indeed, though functional tests are allowed to be heavy. I am OK with turning it into a unit test, but... it does not look like you did it.

Change function name to get hook
Move functional test to unit test
Copy link
Collaborator Author

@GG-HH GG-HH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the first review!

return hooks_path


def get_local_hooks_path() -> Optional[Path]:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed to get_git_local_hooks_path, wdyt ?

from tests.repository import Repository


def test_install_local_detects_husky(tmp_path: Path) -> None:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A functional test with husky feels a bit heavy as it would introduce the need for npm and husky. As you suggested, I moved to a unit test

@GG-HH
Copy link
Collaborator Author

GG-HH commented Dec 12, 2025

Hello @agateau-gg have you had the opportunity to proof read again my code ?

return hooks_path


def get_local_hooks_path() -> Optional[Path]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not look like you renamed it 😅. I would prefer my proposal but I can live with yours.

from tests.repository import Repository


def test_install_local_detects_husky(tmp_path: Path) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that could be heavy indeed, though functional tests are allowed to be heavy. I am OK with turning it into a unit test, but... it does not look like you did it.

@GG-HH GG-HH force-pushed the gg-hh/1143/husky_install branch from 4cfbc12 to 0e73973 Compare December 15, 2025 12:54
Copy link
Collaborator

@agateau-gg agateau-gg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@agateau-gg agateau-gg enabled auto-merge December 15, 2025 12:59
@agateau-gg agateau-gg merged commit 716c2c9 into main Dec 15, 2025
28 of 30 checks passed
@agateau-gg agateau-gg deleted the gg-hh/1143/husky_install branch December 15, 2025 12: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.

ggshield install isn't working with Husky

5 participants