8000 plumbing: allow discovery of non bare repos in fsLoader by jakobmoellerdev · Pull Request #1173 · go-git/go-git · GitHub
[go: up one dir, main page]

Skip to content

plumbing: allow discovery of non bare repos in fsLoader #1173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions plumbing/server/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
34 changes: 27 additions & 7 deletions plumbing/server/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,40 @@ 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 {
c.Skip("git command not found")
}

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 {
Expand All @@ -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)
}
Expand Down
Loading
0