Skip to content

git: changed rev-parse option for Git 2.25 changes to --show-toplevel - #1727

Merged
asottile merged 1 commit into
pre-commit:masterfrom
mrogaski:1610_git_toplevel_relpath
Dec 7, 2020
Merged

asottile merged 1 commit into
pre-commit:masterfrom
mrogaski:1610_git_toplevel_relpath

Conversation

@mrogaski

@mrogaski mrogaski commented Dec 7, 2020 •

Copy link
Copy Markdown
Contributor

Resolves #1610

Git 2.25 introduced a change to "rev-parse --show-toplevel" that exposed underlying volumes for Windows drives mapped with SUBST. We use "rev-parse --show-cdup" to get the appropriate path, but must perform an extra check to see if we are in the .git directory.

@mrogaski

mrogaski commented Dec 7, 2020

Copy link
Copy Markdown
Contributor Author

This is for #1610. I used pathlib for the path comparisons in the get_root function to ensure the same failure modes.

Comment thread pre_commit/git.py Outdated
import logging
import os.path
import sys
from pathlib import Path

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer not to use pathlib

you can do the same without it via os.path.commonpath:

root = os.path.realpath(root)
git_dir = os.path.realpath(git_dir)
if os.path.commonpath(root, git_dir) == git_dir:
    ...

@asottile asottile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Git 2.25 introduced a change to "rev-parse --show-toplevel" that exposed underlying volumes for Windows drives mapped with SUBST.  We use "rev-parse --show-cdup" to get the appropriate path, but must perform an extra check to see if we are in the .git directory.
@asottile
asottile merged commit eacf4c8 into pre-commit:master Dec 7, 2020
@mrogaski
mrogaski deleted the 1610_git_toplevel_relpath branch December 8, 2020 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants