Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 07c03d9

Browse files
authored
Merge pull request #984 from mcuadros/open-bare
repository: allow open non-bare repositories as bare
2 parents 236ae86 + 987c03a commit 07c03d9

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

repository.go

+4-9
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,6 @@ func Open(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
175175
return nil, err
176176
}
177177

178-
cfg, err := s.Config()
179-
if err != nil {
180-
return nil, err
181-
}
182-
183-
if !cfg.Core.IsBare && worktree == nil {
184-
return nil, ErrWorktreeNotProvided
185-
}
186-
187178
return newRepository(s, worktree), nil
188179
}
189180

@@ -335,6 +326,8 @@ func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Files
335326
// PlainClone a repository into the path with the given options, isBare defines
336327
// if the new repository will be bare or normal. If the path is not empty
337328
// ErrRepositoryAlreadyExists is returned.
329+
//
330+
// TODO(mcuadros): move isBare to CloneOptions in v5
338331
func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error) {
339332
return PlainCloneContext(context.Background(), path, isBare, o)
340333
}
@@ -346,6 +339,8 @@ func PlainClone(path string, isBare bool, o *CloneOptions) (*Repository, error)
346339
// The provided Context must be non-nil. If the context expires before the
347340
// operation is complete, an error is returned. The context only affects to the
348341
// transport operations.
342+
//
343+
// TODO(mcuadros): move isBare to CloneOptions in v5
349344
func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOptions) (*Repository, error) {
350345
r, err := PlainInit(path, isBare)
351346
if err != nil {

repository_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -143,16 +143,16 @@ func (s *RepositorySuite) TestOpenBare(c *C) {
143143
c.Assert(r, NotNil)
144144
}
145145

146-
func (s *RepositorySuite) TestOpenMissingWorktree(c *C) {
146+
func (s *RepositorySuite) TestOpenBareMissingWorktree(c *C) {
147147
st := memory.NewStorage()
148148

149149
r, err := Init(st, memfs.New())
150150
c.Assert(err, IsNil)
151151
c.Assert(r, NotNil)
152152

153153
r, err = Open(st, nil)
154-
c.Assert(err, Equals, ErrWorktreeNotProvided)
155-
c.Assert(r, IsNil)
154+
c.Assert(err, IsNil)
155+
c.Assert(r, NotNil)
156156
}
157157

158158
func (s *RepositorySuite) TestOpenNotExists(c *C) {
@@ -425,8 +425,8 @@ func (s *RepositorySuite) TestPlainOpenNotBare(c *C) {
425425
c.Assert(r, NotNil)
426426

427427
r, err = PlainOpen(filepath.Join(dir, ".git"))
428-
c.Assert(err, Equals, ErrWorktreeNotProvided)
429-
c.Assert(r, IsNil)
428+
c.Assert(err, IsNil)
429+
c.Assert(r, NotNil)
430430
}
431431

432432
func (s *RepositorySuite) testPlainOpenGitFile(c *C, f func(string, string) string) {

0 commit comments

Comments
 (0)