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

[Windows] Hooks for submodules that are configured outside the submodule repository lead to error in PurePath.relative_to #1999

Open
visq opened this issue Jan 21, 2025 · 0 comments

Comments

@visq
Copy link

visq commented Jan 21, 2025

Issue: Repo.Index.commit fails during execution of post-commit hook
Root Cause: The .git config does not reside inside the submodule repository in the problematic setup.

    Repo/SubmoduleA$ cat .git
    gitdir: ../.git/modules/SubmoduleA

However, this is expected by the commit hook on windows:

    if sys.platform == "win32" and not _has_file_extension(hp):
        # Windows only uses extensions to determine how to open files
        # (doesn't understand shebangs). Try using bash to run the hook.
        relative_hp = Path(hp).relative_to(index.repo.working_dir).as_posix()
        cmd = ["bash.exe", relative_hp]

Reproduce: Track files with git-lfs and have the hooks outside the repository directory

Fix:

    if sys.platform == "win32" and not _has_file_extension(hp):
        # Windows only uses extensions to determine how to open files
        # (doesn't understand shebangs). Try using bash to run the hook.
        relative_hp = Path(hp).relative_to(index.repo.working_dir, walk_up=True).as_posix()
        cmd = ["bash.exe", relative_hp]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants