aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorSantiago M. Mola <santi@mola.io>2017-04-21 15:00:22 +0200
committerSantiago M. Mola <santi@mola.io>2017-04-27 11:00:51 +0200
commit4060f60af044ce085a097e12bf19cb3fdd123076 (patch)
treeaf10cdadc9adad7a5cb31e05e958d3b9078aec03 /repository_test.go
parent64cd72debb2a94a49de5ffd3c3a6bfd626df7340 (diff)
downloadgo-git-4060f60af044ce085a097e12bf19cb3fdd123076.tar.gz
add support for .git as file, fixes #348
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go87
1 files changed, 87 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index 77bfde2..fd8d405 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -272,6 +272,93 @@ func (s *RepositorySuite) TestPlainOpenNotBare(c *C) {
c.Assert(r, IsNil)
}
+func (s *RepositorySuite) testPlainOpenGitFile(c *C, f func(string, string) string) {
+ dir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ defer os.RemoveAll(dir)
+
+ r, err := PlainInit(dir, true)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
+
+ altDir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ defer os.RemoveAll(altDir)
+
+ err = ioutil.WriteFile(filepath.Join(altDir, ".git"), []byte(f(dir, altDir)), 0644)
+ c.Assert(err, IsNil)
+
+ r, err = PlainOpen(altDir)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
+}
+
+func (s *RepositorySuite) TestPlainOpenBareAbsoluteGitDirFile(c *C) {
+ s.testPlainOpenGitFile(c, func(dir, altDir string) string {
+ return fmt.Sprintf("gitdir: %s\n", dir)
+ })
+}
+
+func (s *RepositorySuite) TestPlainOpenBareAbsoluteGitDirFileNoEOL(c *C) {
+ s.testPlainOpenGitFile(c, func(dir, altDir string) string {
+ return fmt.Sprintf("gitdir: %s", dir)
+ })
+}
+
+func (s *RepositorySuite) TestPlainOpenBareRelativeGitDirFile(c *C) {
+ s.testPlainOpenGitFile(c, func(dir, altDir string) string {
+ dir, err := filepath.Rel(altDir, dir)
+ c.Assert(err, IsNil)
+ return fmt.Sprintf("gitdir: %s\n", dir)
+ })
+}
+
+func (s *RepositorySuite) TestPlainOpenBareRelativeGitDirFileNoEOL(c *C) {
+ s.testPlainOpenGitFile(c, func(dir, altDir string) string {
+ dir, err := filepath.Rel(altDir, dir)
+ c.Assert(err, IsNil)
+ return fmt.Sprintf("gitdir: %s\n", dir)
+ })
+}
+
+func (s *RepositorySuite) TestPlainOpenBareRelativeGitDirFileTrailingGarbage(c *C) {
+ dir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ defer os.RemoveAll(dir)
+
+ r, err := PlainInit(dir, true)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
+
+ altDir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ err = ioutil.WriteFile(filepath.Join(altDir, ".git"), []byte(fmt.Sprintf("gitdir: %s\nTRAILING", dir)), 0644)
+ c.Assert(err, IsNil)
+
+ r, err = PlainOpen(altDir)
+ c.Assert(err, Equals, ErrRepositoryNotExists)
+ c.Assert(r, IsNil)
+}
+
+func (s *RepositorySuite) TestPlainOpenBareRelativeGitDirFileBadPrefix(c *C) {
+ dir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ defer os.RemoveAll(dir)
+
+ r, err := PlainInit(dir, true)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
+
+ altDir, err := ioutil.TempDir("", "plain-open")
+ c.Assert(err, IsNil)
+ err = ioutil.WriteFile(filepath.Join(altDir, ".git"), []byte(fmt.Sprintf("xgitdir: %s\n", dir)), 0644)
+ c.Assert(err, IsNil)
+
+ r, err = PlainOpen(altDir)
+ c.Assert(err, ErrorMatches, ".*gitdir.*")
+ c.Assert(r, IsNil)
+}
+
func (s *RepositorySuite) TestPlainOpenNotExists(c *C) {
r, err := PlainOpen("/not-exists/")
c.Assert(err, Equals, ErrRepositoryNotExists)