diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-30 11:27:42 +0100 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-01-30 11:27:42 +0100 |
commit | 677a596cdb534f485ff8d9488e05855387a6ef00 (patch) | |
tree | 8ac7334d3635a20821d07b8a76b7c4bd21578109 | |
parent | d24e1e9a69c2082763db51959121d3936e621658 (diff) | |
download | go-git-677a596cdb534f485ff8d9488e05855387a6ef00.tar.gz |
Worktree correct FileMode at index entries
-rw-r--r-- | plumbing/object/tree.go | 22 | ||||
-rw-r--r-- | worktree.go | 21 | ||||
-rw-r--r-- | worktree_test.go | 6 |
3 files changed, 33 insertions, 16 deletions
diff --git a/plumbing/object/tree.go b/plumbing/object/tree.go index b7681f3..e197310 100644 --- a/plumbing/object/tree.go +++ b/plumbing/object/tree.go @@ -19,11 +19,11 @@ const ( maxTreeDepth = 1024 startingStackSize = 8 - fileMode = 0100644 - executableMode = 0100755 - submoduleMode = 0160000 - symlinkMode = 0120000 - treeMode = 0040000 + FileMode os.FileMode = 0100644 + ExecutableMode os.FileMode = 0100755 + SubmoduleMode os.FileMode = 0160000 + SymlinkMode os.FileMode = 0120000 + TreeMode os.FileMode = 0040000 ) // New errors defined by this package. @@ -243,14 +243,14 @@ func (t *Tree) decodeFileMode(mode string) (os.FileMode, error) { } m := os.FileMode(fm) - switch fm { - case fileMode: + switch os.FileMode(fm) { + case FileMode: m = 0644 - case executableMode: + case ExecutableMode: m = 0755 - case treeMode: + case TreeMode: m = m | os.ModeDir - case symlinkMode: + case SymlinkMode: m = m | os.ModeSymlink } @@ -375,7 +375,7 @@ func (w *TreeWalker) Next() (name string, entry TreeEntry, err error) { return } - if entry.Mode == submoduleMode { + if entry.Mode == SubmoduleMode { err = nil continue } 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 diff --git a/worktree_test.go b/worktree_test.go index 163df7b..55c0078 100644 --- a/worktree_test.go +++ b/worktree_test.go @@ -5,6 +5,7 @@ import ( "os" "gopkg.in/src-d/go-git.v4/plumbing/format/index" + "gopkg.in/src-d/go-git.v4/plumbing/object" . "gopkg.in/check.v1" "srcd.works/go-billy.v1/memory" @@ -70,8 +71,7 @@ func (s *WorktreeSuite) TestCheckoutIndexMemory(c *C) { c.Assert(idx.Entries, HasLen, 9) c.Assert(idx.Entries[0].Hash.String(), Equals, "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88") c.Assert(idx.Entries[0].Name, Equals, ".gitignore") - // in memoryfs the perms are not supported - c.Assert(idx.Entries[0].Mode, Equals, os.FileMode(0)) + c.Assert(idx.Entries[0].Mode, Equals, object.FileMode) c.Assert(idx.Entries[0].ModifiedAt.IsZero(), Equals, false) c.Assert(idx.Entries[0].Size, Equals, uint32(189)) @@ -104,7 +104,7 @@ func (s *WorktreeSuite) TestCheckoutIndexOS(c *C) { c.Assert(idx.Entries, HasLen, 9) c.Assert(idx.Entries[0].Hash.String(), Equals, "32858aad3c383ed1ff0a0f9bdf231d54a00c9e88") c.Assert(idx.Entries[0].Name, Equals, ".gitignore") - c.Assert(idx.Entries[0].Mode, Equals, os.FileMode(0644)) + c.Assert(idx.Entries[0].Mode, Equals, object.FileMode) c.Assert(idx.Entries[0].ModifiedAt.IsZero(), Equals, false) c.Assert(idx.Entries[0].Size, Equals, uint32(189)) |