Skip to content
Permalink
Browse files

git: handle Windows junctions properly

On Windows, there is the concept of a junction point, which is a by-name
reference from the junction point to a directory using an absolute path.
Go's filepath.EvalSymlinks resolves this and provides a canonical path.
However, Git for Windows ignores them and provides a path containing
junctions, despite the fact that Unix versions of Git always provide an
absolute path.

When locking, we canonicalize paths on Windows before making them
relative to the root, meaning that if junctions are used, the lock path
contains a ".." component, which breaks unlocking. Canonicalize the
paths we get from Git so that we can be confident that lock paths will
be relative.

This case cannot, unfortunately, be easily tested in our testsuite,
since the Git Bash environment lacks support for invoking the system
mklink.exe utility, which is used to create junctions.
  • Loading branch information...
bk2204 committed Mar 12, 2019
1 parent b327ead commit 73a581fb7de97e83536f2a79ce3c069aa29e19b8
Showing with 5 additions and 1 deletion.
  1. +5 −1 git/git.go
@@ -626,7 +626,11 @@ func GitAndRootDirs() (string, string, error) {

func canonicalizeDir(path string) (string, error) {
if len(path) > 0 {
return filepath.Abs(path)
path, err := filepath.Abs(path)
if err != nil {
return "", err
}
return filepath.EvalSymlinks(path)
}
return "", nil
}

0 comments on commit 73a581f

Please sign in to comment.
You can’t perform that action at this time.