aboutsummaryrefslogtreecommitdiffstats
path: root/worktree.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-30 11:27:42 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-01-30 11:27:42 +0100
commit677a596cdb534f485ff8d9488e05855387a6ef00 (patch)
tree8ac7334d3635a20821d07b8a76b7c4bd21578109 /worktree.go
parentd24e1e9a69c2082763db51959121d3936e621658 (diff)
downloadgo-git-677a596cdb534f485ff8d9488e05855387a6ef00.tar.gz
Worktree correct FileMode at index entries
Diffstat (limited to 'worktree.go')
-rw-r--r--worktree.go21
1 files changed, 19 insertions, 2 deletions
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