| 92 | } |
| 93 | |
| 94 | func InitWithOptions(s storage.Storer, worktree billy.Filesystem, options InitOptions) (*Repository, error) { |
| 95 | if err := initStorer(s); err != nil { |
| 96 | return nil, err |
| 97 | } |
| 98 | |
| 99 | if options.DefaultBranch == "" { |
| 100 | options.DefaultBranch = plumbing.Master |
| 101 | } |
| 102 | |
| 103 | if err := options.DefaultBranch.Validate(); err != nil { |
| 104 | return nil, err |
| 105 | } |
| 106 | |
| 107 | r := newRepository(s, worktree) |
| 108 | _, err := r.Reference(plumbing.HEAD, false) |
| 109 | switch err { |
| 110 | case plumbing.ErrReferenceNotFound: |
| 111 | case nil: |
| 112 | return nil, ErrRepositoryAlreadyExists |
| 113 | default: |
| 114 | return nil, err |
| 115 | } |
| 116 | |
| 117 | h := plumbing.NewSymbolicReference(plumbing.HEAD, options.DefaultBranch) |
| 118 | if err := s.SetReference(h); err != nil { |
| 119 | return nil, err |
| 120 | } |
| 121 | |
| 122 | if worktree == nil { |
| 123 | _ = r.setIsBare(true) |
| 124 | return r, nil |
| 125 | } |
| 126 | |
| 127 | return r, setWorktreeAndStoragePaths(r, worktree) |
| 128 | } |
| 129 | |
| 130 | func initStorer(s storer.Storer) error { |
| 131 | i, ok := s.(storer.Initializer) |