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

Implement a better heuristic for Git worktrees #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0x8000-0000
Copy link

The existing heuristic for handling worktrees assumes that one other
worktree contains a ".git" subdirectory with the Git database. This
heuristic fails when worktrees are attached to a bare repository.

The existing heuristic for handling worktrees assumes that one other
worktree contains a ".git" subdirectory with the Git database.  This
heuristic fails when worktrees are attached to a bare repository.
Copy link
Owner

@barisione barisione left a comment

Choose a reason for hiding this comment

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

How do worktrees work in this case? The “main” repo is bare and the other branches are normal directories?

This change seems to break a couple of tests: https://travis-ci.com/barisione/clang-format-hooks/jobs/234482995

In #13 somebody suggested the use of https://git-scm.com/docs/git-config#git-config-corehooksPath. Maybe we could conditionally use that (conditionally as some older git versions don't have it).

fi
fi

if [ -d "$top_dir/hooks" ]; then
Copy link
Owner

Choose a reason for hiding this comment

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

What if there's a directory called hooks in the repository?

@0x8000-0000
Copy link
Author

How do worktrees work in this case? The “main” repo is bare and the other branches are normal directories?

Correct. Just to make sure that random scripts don't go beserk editing the contents of the .git folder, we store that in a separate place as a bare repo, then add worktrees where the real editing is done.

This change seems to break a couple of tests: https://travis-ci.com/barisione/clang-format-hooks/jobs/234482995

I glanced at the errors, but it looked complicated so I didn't get a chance to try and debug it - I am traveling for the next two weeks.

In #13 somebody suggested the use of https://git-scm.com/docs/git-config#git-config-corehooksPath. Maybe we could conditionally use that (conditionally as some older git versions don't have it).

By default, that does not return anything (tried it both in a worktree and in a cloned repo). I believe it returns a value if it was set (in order to use the hooks from a custom place.)

@0x8000-0000
Copy link
Author

In #13 somebody suggested the use of https://git-scm.com/docs/git-config#git-config-corehooksPath. Maybe we could conditionally use that (conditionally as some older git versions don't have it).

By default, that does not return anything (tried it both in a worktree and in a cloned repo). I believe it returns a value if it was set (in order to use the hooks from a custom place.)

For completeness, I have tested it with git 2.23 on Linux.

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