aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--repository.go8
-rw-r--r--repository_test.go10
2 files changed, 18 insertions, 0 deletions
diff --git a/repository.go b/repository.go
index 9dd35be..d954333 100644
--- a/repository.go
+++ b/repository.go
@@ -278,6 +278,14 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
if path, err = filepath.Abs(path); err != nil {
return nil, nil, err
}
+
+ pathinfo, err := os.Stat(path)
+ if !os.IsNotExist(err) {
+ if !pathinfo.IsDir() {
+ path = filepath.Dir(path)
+ }
+ }
+
var fs billy.Filesystem
var fi os.FileInfo
for {
diff --git a/repository_test.go b/repository_test.go
index 6a6ab9e..9433a3c 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -569,6 +569,11 @@ func (s *RepositorySuite) TestPlainOpenDetectDotGit(c *C) {
err = os.MkdirAll(subdir, 0755)
c.Assert(err, IsNil)
+ file := filepath.Join(subdir, "file.txt")
+ f, err := os.Create(file)
+ c.Assert(err, IsNil)
+ f.Close()
+
r, err := PlainInit(dir, false)
c.Assert(err, IsNil)
c.Assert(r, NotNil)
@@ -577,6 +582,11 @@ func (s *RepositorySuite) TestPlainOpenDetectDotGit(c *C) {
r, err = PlainOpenWithOptions(subdir, opt)
c.Assert(err, IsNil)
c.Assert(r, NotNil)
+
+ opt = &PlainOpenOptions{DetectDotGit: true}
+ r, err = PlainOpenWithOptions(file, opt)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
}
func (s *RepositorySuite) TestPlainOpenNotExistsDetectDotGit(c *C) {