aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem
diff options
context:
space:
mode:
Diffstat (limited to 'storage/filesystem')
-rw-r--r--storage/filesystem/dotgit/dotgit.go11
-rw-r--r--storage/filesystem/dotgit/dotgit_test.go2
2 files changed, 12 insertions, 1 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index 503ce18..8c3896b 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -59,6 +59,9 @@ var (
// targeting a non-existing object. This usually means the repository
// is corrupt.
ErrSymRefTargetNotFound = errors.New("symbolic reference target not found")
+ // ErrIsDir is returned when a reference file is attempting to be read,
+ // but the path specified is a directory.
+ ErrIsDir = errors.New("reference path is a directory")
)
// Options holds configuration for the storage.
@@ -946,6 +949,14 @@ func (d *DotGit) addRefFromHEAD(refs *[]*plumbing.Reference) error {
func (d *DotGit) readReferenceFile(path, name string) (ref *plumbing.Reference, err error) {
path = d.fs.Join(path, d.fs.Join(strings.Split(name, "/")...))
+ st, err := d.fs.Stat(path)
+ if err != nil {
+ return nil, err
+ }
+ if st.IsDir() {
+ return nil, ErrIsDir
+ }
+
f, err := d.fs.Open(path)
if err != nil {
return nil, err
diff --git a/storage/filesystem/dotgit/dotgit_test.go b/storage/filesystem/dotgit/dotgit_test.go
index 403f5ff..519f601 100644
--- a/storage/filesystem/dotgit/dotgit_test.go
+++ b/storage/filesystem/dotgit/dotgit_test.go
@@ -118,7 +118,7 @@ func testSetRefs(c *C, dir *DotGit) {
c.Assert(err, IsNil)
_, err = dir.readReferenceFile(".", "refs/heads/feature")
- c.Assert(err, NotNil)
+ c.Assert(err, Equals, ErrIsDir)
ref, err = dir.Ref("refs/heads/foo")
c.Assert(err, IsNil)