Skip to content

fix for #26: strip "drive-folder" from path returned by git rev-parse#31

Open
supersonic-copycat wants to merge 2 commits intosnoyberg:masterfrom
supersonic-copycat:fix_err
Open

fix for #26: strip "drive-folder" from path returned by git rev-parse#31
supersonic-copycat wants to merge 2 commits intosnoyberg:masterfrom
supersonic-copycat:fix_err

Conversation

@supersonic-copycat
Copy link
Copy Markdown

Seems, like problems like #26 caused by different path handling.

Windows have two path separators, \ and /, former is preferred. Absolute path has drive letter prepended, but both separators can be used: both C:\path\to\repo\ and C:/path/to/repo are valid.
Tools from MSYS2 uses Unix-style path, where drive letter prepended like an ordinary directory, so they generally consume (and emit!) path like this /c/path/to/repo.

If Git is installed in MSYS2, git rev-parse --show-toplevel returns path like /c/path/to/repo. normalise replaces secondary separator with primary and makes path looks like \c\path\to\repo. readProcess implicitly prepends (though I have no proofs!) current drive letter path to be searched becomes C:\c\path\to\repo, and most likely it doesn't exist! (I tried to create repo at C:/c/path/to/repo/, and githash took info from it, not from C:/path/to/repo/!)

Quick solution is to strip drive folder from path. Since Windows allows '/' only as path separator and not in names, this should be pretty straightforward. But since 'Git for windows' returns path with correct reference to drive (C:/path/to/repo) we have to check not only platform we are running on (I did it with System.Info.os), but also the first symbol of path, to make sure we it's / and not drive letter already, so we won't corrupt path for folks whose git returns Windows-style path.

Also, WSL have to be considered, but I have no machine with it, so cannot test there.

if Git is installed in MSYS2, `git rev-parse --show-toplevel` returns
path like '/c/path/to/repo'. First directory is not a real one, but a
reference to drive. `normalise` converts this to '\\c\\path\\to\\repo',
and running command will prepend current drive letter, and as result
wrond path is to be searched -- 'C:\\c\\path\\to\\repo'!
Quick solution is to strip drive reference from path. Since Windows
allows '/' only as path separator and not in names, this should be
pretty straightforward. BUT! 'Git for windows' returns path with correct
reference to drive -- 'C:/path/to/repo'. So, we have to check not only
platform (I did it with System.Info.os), but the first symbol of path,
to make sure we are not corrupting path for folks using 'Git for windows'
actually, I forgot to do very essense of fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant