From 677a596cdb534f485ff8d9488e05855387a6ef00 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Mon, 30 Jan 2017 11:27:42 +0100 Subject: Worktree correct FileMode at index entries --- worktree.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'worktree.go') diff --git a/worktree.go b/worktree.go index c786c95..8637f7b 100644 --- a/worktree.go +++ b/worktree.go @@ -81,7 +81,7 @@ func (w *Worktree) indexFile(f *object.File, idx *index.Index) error { e := index.Entry{ Hash: f.Hash, Name: f.Name, - Mode: fi.Mode(), + Mode: w.getMode(fi), ModifiedAt: fi.ModTime(), Size: uint32(fi.Size()), } @@ -142,7 +142,7 @@ func (w *Worktree) compareFileWithEntry(fi billy.FileInfo, e *index.Entry) (Stat return Modified, nil } - if fi.Mode().Perm() != e.Mode.Perm() { + if w.getMode(fi) != e.Mode { return Modified, nil } @@ -155,6 +155,23 @@ func (w *Worktree) compareFileWithEntry(fi billy.FileInfo, e *index.Entry) (Stat return Unmodified, nil } +func (w *Worktree) getMode(fi billy.FileInfo) os.FileMode { + if fi.Mode().IsDir() { + return object.TreeMode + } + + if fi.Mode()&os.ModeSymlink != 0 { + return object.SymlinkMode + } + + const modeExec = 0111 + if fi.Mode()&modeExec != 0 { + return object.ExecutableMode + } + + return object.FileMode +} + // Status current status of a Worktree type Status map[string]*FileStatus -- cgit