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

scmrepo git driver hard codes hooks directory #111

Open
liljenstolpe opened this issue Jul 6, 2022 · 2 comments
Open

scmrepo git driver hard codes hooks directory #111

liljenstolpe opened this issue Jul 6, 2022 · 2 comments

Comments

@liljenstolpe
Copy link

liljenstolpe commented Jul 6, 2022

I have an issue in iterative/dvc#7967, that appears is actually an issue with scmrepo.

In scmrepo, there is an assumption that hooks are in .git/hooks, and it is hardcoded as such (my guess is there might be other assumptions like that as well). That's all well and good, unless the repo happens to be cloned/integrated as a submodule. In that case, the '.git' directory is actually the parent repo's .git/modules/. Therefore, the hooks directory actually should be /.git/modules//hooks.

You can actually just use:

git rev-parse --git-path hooks

to find out whatever the hook directory is for a given repo (or any other path, btw). That saves you from having to build all of the logic depending on where things land.

Happy to propose some code, but this might be something that makes more sense to generalize

@pmrowla
Copy link
Contributor

pmrowla commented Jul 6, 2022

The issue here is that we cannot just directly call git rev-parse since we don't want to have a dependency on CLI git.

Basically what we really need is to implement the correct methods for getting GIT_DIR and GIT_COMMON_DIR in all of the scmrepo backends. Some of this functionality already exists in dulwich and libgit2/pygit2 but it gets more complicated when accounting for things like submodules and worktrees.

Then rather than the hard coded paths we would use the proper values for GIT_DIR in places like:

@cached_property
def hooks_dir(self):
from pathlib import Path
return Path(self.root_dir) / self.GIT_DIR / "hooks"

@liljenstolpe
Copy link
Author

Greetings, I agree, I should have been more specific - make a programatic call the same way that git rev-parse does. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants