aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorFelix Kollmann <fk@konsorten.de>2018-03-12 15:03:36 +0100
committerFelix Kollmann <fk@konsorten.de>2018-03-12 15:03:36 +0100
commit4915f5834dbb588836ad787e728cf4a81364f5af (patch)
tree9c39915df072451fbfde8da2367765797e50bafb /worktree.go
parent1d28459504251497e0ce6132a0fadd5eb44ffd22 (diff)
downloadgo-git-4915f5834dbb588836ad787e728cf4a81364f5af.tar.gz
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 <mail@fkollmann.de>
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go16
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
}