aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorThinkChaos <ThinkChaos@users.noreply.github.com>2023-05-31 11:58:44 -0400
committerThinkChaos <ThinkChaos@users.noreply.github.com>2023-09-15 12:44:52 -0400
commit1ad7d8dd024abca82779e2dfdff69d9712161ab8 (patch)
tree118147884c5d0c76734b2a6a338d086377c32110 /repository.go
parente24e0f714c4ecaf086b5783f099a885e6a2c9a1a (diff)
downloadgo-git-1ad7d8dd024abca82779e2dfdff69d9712161ab8.tar.gz
git: add `PlainInitOptions.Bare`
Refactor `PlainInit` to call `PlainInitWithOptions`
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go23
1 files changed, 12 insertions, 11 deletions
diff --git a/repository.go b/repository.go
index 3154ac0..e94fc48 100644
--- a/repository.go
+++ b/repository.go
@@ -235,9 +235,19 @@ func CloneContext(
// if the repository will have worktree (non-bare) or not (bare), if the path
// is not empty ErrRepositoryAlreadyExists is returned.
func PlainInit(path string, isBare bool) (*Repository, error) {
+ return PlainInitWithOptions(path, &PlainInitOptions{
+ Bare: isBare,
+ })
+}
+
+func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, error) {
+ if opts == nil {
+ opts = &PlainInitOptions{}
+ }
+
var wt, dot billy.Filesystem
- if isBare {
+ if opts.Bare {
dot = osfs.New(path)
} else {
wt = osfs.New(path)
@@ -246,15 +256,6 @@ func PlainInit(path string, isBare bool) (*Repository, error) {
s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
- return Init(s, wt)
-}
-
-func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, error) {
- wt := osfs.New(path)
- dot, _ := wt.Chroot(GitDirName)
-
- s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
-
r, err := Init(s, wt)
if err != nil {
return nil, err
@@ -265,7 +266,7 @@ func PlainInitWithOptions(path string, opts *PlainInitOptions) (*Repository, err
return nil, err
}
- if opts != nil {
+ if opts.ObjectFormat != "" {
if opts.ObjectFormat == formatcfg.SHA256 && hash.CryptoType != crypto.SHA256 {
return nil, ErrSHA256NotSupported
}