diff options
author | Jakob Möller <jmoller@redhat.com> | 2024-08-21 10:08:58 +0200 |
---|---|---|
committer | Jakob Möller <jmoller@redhat.com> | 2024-08-21 12:01:29 +0200 |
commit | 36756c91730bb3ccd0982703c90760a3621caf28 (patch) | |
tree | 111cd2555585fb69d5a4ff241c6584dd377038ef | |
parent | 4fd9979d5c2940e72bdd6946fec21e02d959f0f6 (diff) | |
download | go-git-36756c91730bb3ccd0982703c90760a3621caf28.tar.gz |
plumbing: allow discovery of non bare repos in fsLoader
-rw-r--r-- | plumbing/transport/server/loader.go | 12 | ||||
-rw-r--r-- | plumbing/transport/server/loader_test.go | 34 |
2 files changed, 37 insertions, 9 deletions
diff --git a/plumbing/transport/server/loader.go b/plumbing/transport/server/loader.go index e7e2b07..f03a91c 100644 --- a/plumbing/transport/server/loader.go +++ b/plumbing/transport/server/loader.go @@ -40,8 +40,16 @@ func (l *fsLoader) Load(ep *transport.Endpoint) (storer.Storer, error) { return nil, err } - if _, err := fs.Stat("config"); err != nil { - return nil, transport.ErrRepositoryNotFound + var bare bool + if _, err := fs.Stat("config"); err == nil { + bare = true + } + + if !bare { + // do not use git.GitDirName due to import cycle + if _, err := fs.Stat(".git"); err != nil { + return nil, transport.ErrRepositoryNotFound + } } return filesystem.NewStorage(fs, cache.NewObjectLRUDefault()), nil diff --git a/plumbing/transport/server/loader_test.go b/plumbing/transport/server/loader_test.go index 88f0403..d478e65 100644 --- a/plumbing/transport/server/loader_test.go +++ b/plumbing/transport/server/loader_test.go @@ -10,11 +10,22 @@ import ( . "gopkg.in/check.v1" ) +type loaderSuiteRepo struct { + bare bool + + path string +} + type LoaderSuite struct { - RepoPath string + Repos map[string]loaderSuiteRepo } -var _ = Suite(&LoaderSuite{}) +var _ = Suite(&LoaderSuite{ + Repos: map[string]loaderSuiteRepo{ + "repo": {path: "repo.git"}, + "bare": {path: "bare.git", bare: true}, + }, +}) func (s *LoaderSuite) SetUpSuite(c *C) { if err := exec.Command("git", "--version").Run(); err != nil { @@ -22,8 +33,17 @@ func (s *LoaderSuite) SetUpSuite(c *C) { } dir := c.MkDir() - s.RepoPath = filepath.Join(dir, "repo.git") - c.Assert(exec.Command("git", "init", "--bare", s.RepoPath).Run(), IsNil) + + for key, repo := range s.Repos { + repo.path = filepath.Join(dir, repo.path) + if repo.bare { + c.Assert(exec.Command("git", "init", "--bare", repo.path).Run(), IsNil) + } else { + c.Assert(exec.Command("git", "init", repo.path).Run(), IsNil) + } + s.Repos[key] = repo + } + } func (s *LoaderSuite) endpoint(c *C, url string) *transport.Endpoint { @@ -45,13 +65,13 @@ func (s *LoaderSuite) TestLoadNonExistentIgnoreHost(c *C) { } func (s *LoaderSuite) TestLoad(c *C) { - sto, err := DefaultLoader.Load(s.endpoint(c, s.RepoPath)) + sto, err := DefaultLoader.Load(s.endpoint(c, s.Repos["repo"].path)) c.Assert(err, IsNil) c.Assert(sto, NotNil) } -func (s *LoaderSuite) TestLoadIgnoreHost(c *C) { - sto, err := DefaultLoader.Load(s.endpoint(c, s.RepoPath)) +func (s *LoaderSuite) TestLoadBare(c *C) { + sto, err := DefaultLoader.Load(s.endpoint(c, s.Repos["bare"].path)) c.Assert(err, IsNil) c.Assert(sto, NotNil) } |