diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-03-12 15:30:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-12 15:30:49 +0100 |
commit | 71e37414308043c18b9263ea8b18f296345b3e54 (patch) | |
tree | 9c39915df072451fbfde8da2367765797e50bafb /worktree.go | |
parent | 1d28459504251497e0ce6132a0fadd5eb44ffd22 (diff) | |
parent | 4915f5834dbb588836ad787e728cf4a81364f5af (diff) | |
download | go-git-71e37414308043c18b9263ea8b18f296345b3e54.tar.gz |
Merge pull request #778 from konsorten/fix-windows-symlink3
Worktree.Checkout: handling of symlink on Windows
Diffstat (limited to 'worktree.go')
-rw-r--r-- | worktree.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/worktree.go b/worktree.go index 394dce4..d2cb29a 100644 --- a/worktree.go +++ b/worktree.go @@ -554,6 +554,22 @@ func (w *Worktree) checkoutFileSymlink(f *object.File) (err error) { } err = w.Filesystem.Symlink(string(bytes), f.Name) + + // On windows, this might fail. + // Follow Git on Windows behavior by writing the link as it is. + if err != nil && isSymlinkWindowsNonAdmin(err) { + mode, _ := f.Mode.ToOSFileMode() + + to, err := w.Filesystem.OpenFile(f.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, mode.Perm()) + if err != nil { + return err + } + + defer ioutil.CheckClose(to, &err) + + _, err = to.Write(bytes) + return err + } return } |