From 5e8e011f6537e6822350a16a243db5802d4151e6 Mon Sep 17 00:00:00 2001 From: Daniel Martí Date: Wed, 14 Mar 2018 16:32:48 +0000 Subject: add PlainOpen variant to find .git in parent dirs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is the git tool's behavior that people are used to; if one runs a git command in a repository's subdirectory, git still works. Fixes #765. Signed-off-by: Daniel Martí --- repository_test.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'repository_test.go') diff --git a/repository_test.go b/repository_test.go index f39f358..4765a53 100644 --- a/repository_test.go +++ b/repository_test.go @@ -407,6 +407,36 @@ func (s *RepositorySuite) TestPlainOpenNotExists(c *C) { c.Assert(r, IsNil) } +func (s *RepositorySuite) TestPlainOpenDetectDotGit(c *C) { + dir, err := ioutil.TempDir("", "plain-open") + c.Assert(err, IsNil) + defer os.RemoveAll(dir) + + subdir := filepath.Join(dir, "a", "b") + err = os.MkdirAll(subdir, 0755) + c.Assert(err, IsNil) + + r, err := PlainInit(dir, false) + c.Assert(err, IsNil) + c.Assert(r, NotNil) + + opt := &PlainOpenOptions{DetectDotGit: true} + r, err = PlainOpenWithOptions(subdir, opt) + c.Assert(err, IsNil) + c.Assert(r, NotNil) +} + +func (s *RepositorySuite) TestPlainOpenNotExistsDetectDotGit(c *C) { + dir, err := ioutil.TempDir("", "plain-open") + c.Assert(err, IsNil) + defer os.RemoveAll(dir) + + opt := &PlainOpenOptions{DetectDotGit: true} + r, err := PlainOpenWithOptions(dir, opt) + c.Assert(err, Equals, ErrRepositoryNotExists) + c.Assert(r, IsNil) +} + func (s *RepositorySuite) TestPlainClone(c *C) { r, err := PlainClone(c.MkDir(), false, &CloneOptions{ URL: s.GetBasicLocalRepositoryURL(), -- cgit