aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--file.go10
-rw-r--r--file_test.go1
-rw-r--r--tree.go15
-rw-r--r--tree_test.go1
4 files changed, 13 insertions, 14 deletions
diff --git a/file.go b/file.go
index 76ec962..35bbdc5 100644
--- a/file.go
+++ b/file.go
@@ -2,17 +2,19 @@ package git
import (
"bytes"
+ "os"
"strings"
)
// File represents git file objects.
type File struct {
Name string
+ Mode os.FileMode
Blob
}
-func newFile(name string, b *Blob) *File {
- return &File{Name: name, Blob: *b}
+func newFile(name string, m os.FileMode, b *Blob) *File {
+ return &File{Name: name, Mode: m, Blob: *b}
}
// Contents returns the contents of a file as a string.
@@ -57,13 +59,13 @@ func NewFileIter(r *Repository, t *Tree) *FileIter {
func (iter *FileIter) Next() (*File, error) {
for {
- name, _, obj, err := iter.w.Next()
+ name, entry, obj, err := iter.w.Next()
if err != nil {
return nil, err
}
if blob, ok := obj.(*Blob); ok {
- return newFile(name, blob), nil
+ return newFile(name, entry.Mode, blob), nil
}
}
}
diff --git a/file_test.go b/file_test.go
index aa3369a..2f457f4 100644
--- a/file_test.go
+++ b/file_test.go
@@ -58,6 +58,7 @@ func (s *SuiteFile) TestIter(c *C) {
expected := t.files[k]
file, err := iter.Next()
c.Assert(err, IsNil, Commentf("subtest %d, iter %d, err=%v", i, k, err))
+ c.Assert(file.Mode.String(), Equals, "-rw-r--r--")
c.Assert(file.Hash.IsZero(), Equals, false)
c.Assert(file.Hash, Equals, file.ID())
c.Assert(file.Name, Equals, expected.Name, Commentf("subtest %d, iter %d, name=%s, expected=%s", i, k, file.Name, expected.Hash))
diff --git a/tree.go b/tree.go
index 246bf8c..50f86e9 100644
--- a/tree.go
+++ b/tree.go
@@ -41,12 +41,12 @@ type TreeEntry struct {
// File returns the hash of the file identified by the `path` argument.
// The path is interpreted as relative to the tree receiver.
func (t *Tree) File(path string) (*File, error) {
- hash, err := t.findHash(path)
+ e, err := t.findEntry(path)
if err != nil {
return nil, ErrFileNotFound
}
- obj, err := t.r.Storage.Get(*hash)
+ obj, err := t.r.Storage.Get(e.Hash)
if err != nil {
if err == core.ObjectNotFoundErr {
return nil, ErrFileNotFound // a git submodule
@@ -61,10 +61,10 @@ func (t *Tree) File(path string) (*File, error) {
blob := &Blob{}
blob.Decode(obj)
- return newFile(path, blob), nil
+ return newFile(path, e.Mode, blob), nil
}
-func (t *Tree) findHash(path string) (*core.Hash, error) {
+func (t *Tree) findEntry(path string) (*TreeEntry, error) {
pathParts := strings.Split(path, "/")
var tree *Tree
@@ -75,12 +75,7 @@ func (t *Tree) findHash(path string) (*core.Hash, error) {
}
}
- entry, err := tree.entry(pathParts[0])
- if err != nil {
- return nil, err
- }
-
- return &entry.Hash, nil
+ return tree.entry(pathParts[0])
}
var errDirNotFound = errors.New("directory not found")
diff --git a/tree_test.go b/tree_test.go
index 09e255c..2b509f3 100644
--- a/tree_test.go
+++ b/tree_test.go
@@ -264,6 +264,7 @@ func (s *SuiteTree) TestFiles(c *C) {
iter := tree.Files()
defer iter.Close()
for file, err := iter.Next(); err == nil; file, err = iter.Next() {
+ c.Assert(file.Mode.String(), Equals, "-rw-r--r--")
output = append(output, file.Name)
}
sort.Strings(output)