From 4915f5834dbb588836ad787e728cf4a81364f5af Mon Sep 17 00:00:00 2001 From: Felix Kollmann Date: Mon, 12 Mar 2018 15:03:36 +0100 Subject: Added support for non-symlink checkouts on Windows when elevated rights are missing This implementation mimicks the behavior of Git on Windows Signed-off-by: Felix Kollmann --- worktree.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'worktree.go') 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 } -- cgit