Skip to content

Commit

Permalink
feat: allow using InitOptions with PlainInitWithOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThinkChaos committed Sep 15, 2023
1 parent 4f8d298 commit 90b4c84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ type PlainOpenOptions struct {
func (o *PlainOpenOptions) Validate() error { return nil }

type PlainInitOptions struct {
InitOptions
// Determines if the repository will have a worktree (non-bare) or not (bare).
Bare bool
ObjectFormat formatcfg.ObjectFormat
Expand Down
2 changes: 1 addition & 1 deletion repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, err

s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())

r, err := Init(s, wt)
r, err := InitWithOptions(s, wt, opts.InitOptions)
if err != nil {
return nil, err
}
Expand Down
13 changes: 11 additions & 2 deletions repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,14 +523,23 @@ func (s *RepositorySuite) TestPlainInitWithOptions(c *C) {
defer clean()

r, err := PlainInitWithOptions(dir, &PlainInitOptions{
Bare: true,
InitOptions: InitOptions{
DefaultBranch: "refs/heads/foo",
},
Bare: false,
})
c.Assert(err, IsNil)
c.Assert(r, NotNil)

cfg, err := r.Config()
c.Assert(err, IsNil)
c.Assert(cfg.Core.IsBare, Equals, true)
c.Assert(cfg.Core.IsBare, Equals, false)

createCommit(c, r)

ref, err := r.Head()
c.Assert(err, IsNil)
c.Assert(ref.Name().String(), Equals, "refs/heads/foo")
}

func (s *RepositorySuite) TestPlainInitAlreadyExists(c *C) {
Expand Down

0 comments on commit 90b4c84

Please sign in to comment.