-
-
Notifications
You must be signed in to change notification settings - Fork 320
Correctly resolve git hooks directory using git rev-parse
#991
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
base: main
Are you sure you want to change the base?
Conversation
|
Tangential, but this doesn't work with |
commit: |
Thanks for the PR!
We do have https://github.com/webpro-nl/knip/blob/main/packages/knip/test/plugins/lefthook-v1.test.ts + https://github.com/webpro-nl/knip/tree/main/packages/knip/fixtures/plugins/lefthook-v1 to prevent regression for regular |
|
Which now fails because it depended on the old static behavior... OK, let me look at it and see if I can come up with a test |
|
@webpro The tests are fairly ugly, but that is because git hook paths are resolved at knip import time, and do not resolve relatively to the |
|
Leaving aside the biome formatting issue, this probably fails because the tests do not have execution isolation. Running only the lefthook test on its own works fine. So there is a module import that happens earlier, and the incorrect paths get cached here: knip/packages/knip/src/plugins/lefthook/index.ts Lines 16 to 18 in 529a734
This is not easy to fix, unless plugin |
| const gitHookPaths = getGitHookPaths(); | ||
|
|
||
| return ['lefthook.yml', ...gitHookPaths]; | ||
| }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a workaround for configs getting calculated way too early with a static process.cwd()
|
How about adding a separate Actions workflow to assert git worktrees work properly? Could that simplify things, or maybe you have other ideas? |
|
You mean, go down to a terminal to execute the worktree tests instead of trying to run them within the test runner? I think that would work well. There must be some best practices around doing that, I'll look around at some tools that need to manipulate git repositories at how they do their tests and come back to this. |
|
There don't even necessarily need to be a test runner per se, only shell commands to set up the situation, add some files perhaps (maybe prepare a fixtures folder for this, but without a |
|
Yep! Will look into doing that if not tomorrow by the end of the week. Thanks for helping me get this to a good state! |
e764138 to
d4c7379
Compare
ea72d80 to
7787123
Compare
|
Is there still interest in finishing this PR? No worries if not, but I'm going to clean things up a bit around here. |
|
I definitely want to push this through, as it's still a problem in my day-to-day work. It just seemed daunting every time I thought to return to it, as writing the correct tests seems quite complicated, even though the underlying fix is so straightforward: 2fe0a85 But please, keep it open for a while longer, and I'll make a best effort to get this fixed properly. |
|
Sure, no hurries, just wanted to check if it's still interesting/relevant. |
5a2d249 to
6bd250a
Compare
362f1be to
a8931d6
Compare
0cb770b to
4a08731
Compare
|
Hey @webpro, I added a workflow that verifies worktree behavor and can correctly fail: This PR is good for re-review. Let me know if you'd like me to improve this PR in any way before it's good for merge, and thank you for the patience! |
|
Huh, wonder what causes these failures, tests were running fine locally. Will investigate. |
Fixes #990
There is no reasonable way to add tests for this, as far as I can figure.