[Windows] Hooks for submodules that are configured outside the submodule repository lead to error in PurePath.relative_to · Issue #1999 · gitpython-developers/GitPython · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

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

Open
@visq

Description

@visq

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]

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.