diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2017-05-04 10:17:15 +0200 |
commit | b8b61e74469e0d2662e7d690eee14893f91fe259 (patch) | |
tree | 1933fe53200d98ad2c557d034609408641ce2900 /repository_test.go | |
parent | 40fa5882a2c73f8c075403b7ec85870f04deda07 (diff) | |
parent | e80cdbabb92a1ec35ffad536f52d3ff04b548fd1 (diff) | |
download | go-git-b8b61e74469e0d2662e7d690eee14893f91fe259.tar.gz |
Merge branch 'master' of github.com:src-d/go-git into commit
Diffstat (limited to 'repository_test.go')
-rw-r--r-- | repository_test.go | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/repository_test.go b/repository_test.go index 77bfde2..deb3f58 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) @@ -301,7 +388,7 @@ func (s *RepositorySuite) TestPlainCloneWithRecurseSubmodules(c *C) { path := fixtures.ByTag("submodule").One().Worktree().Base() r, err := PlainClone(dir, false, &CloneOptions{ - URL: fmt.Sprintf("file://%s", path), + URL: path, RecurseSubmodules: DefaultSubmoduleRecursionDepth, }) @@ -591,7 +678,7 @@ func (s *RepositorySuite) TestPullProgressWithRecursion(c *C) { r, _ := PlainInit(dir, false) r.CreateRemote(&config.RemoteConfig{ Name: DefaultRemoteName, - URL: fmt.Sprintf("file://%s", path), + URL: path, }) err = r.Pull(&PullOptions{ @@ -607,7 +694,7 @@ func (s *RepositorySuite) TestPullAdd(c *C) { path := fixtures.Basic().ByTag("worktree").One().Worktree().Base() r, err := Clone(memory.NewStorage(), nil, &CloneOptions{ - URL: fmt.Sprintf("file://%s", filepath.Join(path, ".git")), + URL: filepath.Join(path, ".git"), }) c.Assert(err, IsNil) @@ -642,7 +729,7 @@ func (s *RepositorySuite) TestPushToEmptyRepository(c *C) { c.Assert(err, IsNil) dstFs := fixtures.ByTag("empty").One().DotGit() - url := fmt.Sprintf("file://%s", dstFs.Base()) + url := dstFs.Base() r, err := Open(sto, srcFs) c.Assert(err, IsNil) |