aboutsummaryrefslogtreecommitdiffstats
path: root/worktree_commit.go
diff options
context:
space:
mode:
Diffstat (limited to 'worktree_commit.go')
-rw-r--r--worktree_commit.go32
1 files changed, 31 insertions, 1 deletions
diff --git a/worktree_commit.go b/worktree_commit.go
index 5307b41..fc63d16 100644
--- a/worktree_commit.go
+++ b/worktree_commit.go
@@ -2,6 +2,7 @@ package git
import (
"io"
+ "os"
"path/filepath"
"strings"
@@ -186,11 +187,15 @@ func (h *commitIndexHelper) copyIndexEntryToStorage(e *index.Entry) error {
}
func (h *commitIndexHelper) doCopyIndexEntryToStorage(e *index.Entry) (err error) {
- fi, err := h.fs.Stat(e.Name)
+ fi, err := h.fs.Lstat(e.Name)
if err != nil {
return err
}
+ if fi.Mode()&os.ModeSymlink != 0 {
+ return h.doCopyIndexEntryFromSymlinkToStorage(e, fi)
+ }
+
obj := h.s.NewEncodedObject()
obj.SetType(plumbing.BlobObject)
obj.SetSize(fi.Size())
@@ -217,6 +222,31 @@ func (h *commitIndexHelper) doCopyIndexEntryToStorage(e *index.Entry) (err error
return err
}
+func (h *commitIndexHelper) doCopyIndexEntryFromSymlinkToStorage(e *index.Entry, fi os.FileInfo) error {
+ obj := h.s.NewEncodedObject()
+ obj.SetType(plumbing.BlobObject)
+ obj.SetSize(fi.Size())
+
+ writer, err := obj.Writer()
+ if err != nil {
+ return err
+ }
+
+ defer ioutil.CheckClose(writer, &err)
+
+ target, err := h.fs.Readlink(e.Name)
+ if err != nil {
+ return err
+ }
+
+ if _, err := writer.Write([]byte(target)); err != nil {
+ return err
+ }
+
+ _, err = h.s.SetEncodedObject(obj)
+ return err
+}
+
func (h *commitIndexHelper) copyTreeToStorageRecursive(parent string, t *object.Tree) (plumbing.Hash, error) {
for i, e := range t.Entries {
if e.Mode != filemode.Dir && !e.Hash.IsZero() {