question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pre-commit fails for git >=2.25 if repo is on a Windows subst drive

See original GitHub issue

Cross reference for another issue with same apparent root cause: https://github.com/microsoft/vscode/issues/100274#issuecomment-646499795

Issue observed with pre-commit==2.7.1 and git 2.27. Issue resolved with downgrading git to 2.21 (I only have access to certain versions on my work machine).

Steps to recreate for pre-commit (some taken from the above cross-reference):

  • Install git >= 2.25 on Windows

  • Create a subst drive (mkdir C:\subst_dir && subst Z: C:\subst_dir)

  • Create a git repo in there (mkdir Z:\repo && cd /d Z:\repo && git init)

  • Add some python code, configure pre-commit, and run pre-commit.

Failure observed: An unexpected error has occurred: ValueError: path is on mount 'Z:', start on mount 'C:'

Diagnosis - it appears that the use of git rev-parse --show-toplevel in pre_commit.main.get_root() is suffering the same issue as seen in cross-referenced ticket; git will “see through” the subst command and rather than return a path on the subst-defined Z: drive, it will return the path from the C: drive. With this, after pre_commit.main._adjust_args_and_chdir() calls pre_commit.main.get_root() and does a chdir to the returned location, the following call to os.path.relpath(args.config) then fails with the ValueError as above, because it sees the path to the config file being on Z: but the current location being on C:.

Afraid I don’t have a suggested resolution but wanted to flag this up. I’m not too familiar with Windows systems and I’m a long way from Admin access on my work machine so opportunities for testing are limited; this was discovered as my scratch space for repos is a subst drive.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
mrogaskicommented, Dec 6, 2020

Using --show-cdup instead of --show-toplevel, as was suggested in the VSCode issue listed in the OP, is worth considering.

def get_root() -> str:
    try:
        root = cmd_output('git', 'rev-parse', '--show-cdup')[1].strip()
    except CalledProcessError:
        raise FatalError(
            'git failed. Is it installed, and are you in a Git repository '
            'directory?',
        )
    if not root:
        return os.getcwd()
    return root

The original failure mode (ie. issuing the command from in .git) will fail, but will be a non-zero return code from Git and be caught by CalledProcessError.

0reactions
jcameron73commented, Dec 12, 2020

I’ve pulled this into the project where the issue first arose and it’s working beautifully - thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git pre-commit hook is not running on Windows - Stack Overflow
Just tried that and now it comes up with an error when I try to commit: "error: cannot spawn .git/hooks/pre-commit: no such file...
Read more >
gitattributes Documentation - Git
These attributes affect how the contents stored in the repository are copied to the working tree files when commands such as git switch,...
Read more >
A Git client for Windows Version 2.13.0 - TortoiseGit
If you want to pre-populate the commit dialog with only ... It is often convenient to use a SUBST drive to access your...
Read more >
Change Log
System Volume Information" - Windows: possible error "the following file has ... Log window - Refresh: - internal error if repository is located...
Read more >
git commit failed with git-hook error - Visual Studio Feedback
Git commit in Team Explorer failed when git commit from the command line works fine. The error appeared in an info bar: Your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found