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

[bug] Git Hooks not working when using Git Worktrees #1756

Open
b-dreissigacker opened this issue Dec 16, 2024 · 2 comments
Open

[bug] Git Hooks not working when using Git Worktrees #1756

b-dreissigacker opened this issue Dec 16, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@b-dreissigacker
Copy link

Describe the bug

When using Git Worktrees the Git Hooks are not set up properly.

Steps to reproduce

Expected behavior

The pre-commit hook should run.

Additional context
Before using moon to manage the Git Hooks I had some hooks in my project set up with husky(https://github.com/typicode/husky) which was working properly with git worktree.

@b-dreissigacker b-dreissigacker added the bug Something isn't working label Dec 16, 2024
@milesj
Copy link
Collaborator

milesj commented Dec 17, 2024

@b-dreissigacker I've never used git worktrees. Can you describe where hooks are supposed to go in the worktree if not the root .git folder?

@b-dreissigacker
Copy link
Author

To be honest, I'm still pretty new to using git worktrees, too. I've been using it for about 2 months now.

There is no .git folder in the root of the repo, but content that is normally in the .git folder there instead, the hooks folder with the example hooks too.

If you create a new worktree folder for a branch, it doesn't contain a .git folder either, just a .git file with a key gitdir and an absolute path to the repo root folder.

for example:

/home/benjamin/repos/example/branchname/.git:

gitdir: /home/benjamin/repos/example/branchname

I assume you can tell that the folder you are in is a worktree folder because the .git folder is a file with the gitdir field and I assume you can just put the hooks in the hooks folder in the root folder.

Btw the git root command points to the root of the branch folder when I use git worktree and not to the root of the repo.

I hope this helps, let me know if there is anything else I should test/try out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants