aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-10-15 11:16:42 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2018-10-15 11:16:42 +0200
commit987c03a3cef828894fabe4ffdcafd2a90e908e4a (patch)
treefe618979bcf565e093749f6b0886a735b62404d8
parentf69f5304328165153e452382f44aa2b41df36d0f (diff)
downloadgo-git-987c03a3cef828894fabe4ffdcafd2a90e908e4a.tar.gz
repository: allow open non-bare repositories as bare
Signed-off-by: Máximo Cuadros <mcuadros@gmail.com>
-rw-r--r--repository.go13
-rw-r--r--repository_test.go10
2 files changed, 9 insertions, 14 deletions
diff --git a/repository.go b/repository.go
index be1f057..08b822c 100644
--- a/repository.go
+++ b/repository.go
@@ -175,15 +175,6 @@ func Open(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
return nil, err
}
- cfg, err := s.Config()
- if err != nil {
- return nil, err
- }
-
- if !cfg.Core.IsBare && worktree == nil {
- return nil, ErrWorktreeNotProvided
- }
-
return newRepository(s, worktree), nil
}
@@ -335,6 +326,8 @@ func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Files
// PlainClone a repository into the path with the given options, isBare defines
// if the new repository will be bare or normal. If the path is not empty
// ErrRepositoryAlreadyExists is returned.
+//
+// TODO(mcuadros): move isBare to CloneOptions in v5
func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error) {
return PlainCloneContext(context.Background(), path, isBare, o)
}
@@ -346,6 +339,8 @@ func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error)
// The provided Context must be non-nil. If the context expires before the
// operation is complete, an error is returned. The context only affects to the
// transport operations.
+//
+// TODO(mcuadros): move isBare to CloneOptions in v5
func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOptions) (*Repository, error) {
r, err := PlainInit(path, isBare)
if err != nil {
diff --git a/repository_test.go b/repository_test.go
index 2710d9d..3179d51 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -143,7 +143,7 @@ func (s *RepositorySuite) TestOpenBare(c *C) {
c.Assert(r, NotNil)
}
-func (s *RepositorySuite) TestOpenMissingWorktree(c *C) {
+func (s *RepositorySuite) TestOpenBareMissingWorktree(c *C) {
st := memory.NewStorage()
r, err := Init(st, memfs.New())
@@ -151,8 +151,8 @@ func (s *RepositorySuite) TestOpenMissingWorktree(c *C) {
c.Assert(r, NotNil)
r, err = Open(st, nil)
- c.Assert(err, Equals, ErrWorktreeNotProvided)
- c.Assert(r, IsNil)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
}
func (s *RepositorySuite) TestOpenNotExists(c *C) {
@@ -425,8 +425,8 @@ func (s *RepositorySuite) TestPlainOpenNotBare(c *C) {
c.Assert(r, NotNil)
r, err = PlainOpen(filepath.Join(dir, ".git"))
- c.Assert(err, Equals, ErrWorktreeNotProvided)
- c.Assert(r, IsNil)
+ c.Assert(err, IsNil)
+ c.Assert(r, NotNil)
}
func (s *RepositorySuite) testPlainOpenGitFile(c *C, f func(string, string) string) {