55
66 "github.com/go-git/go-billy/v5/memfs"
77 "github.com/go-git/go-git/v5"
8- "github.com/go-git/go-git/v5/config"
9- "github.com/go-git/go-git/v5/plumbing"
10- "github.com/go-git/go-git/v5/plumbing/transport"
118 "github.com/go-git/go-git/v5/storage/memory"
129 "github.com/gov4git/lib4git/must"
1310)
@@ -28,78 +25,8 @@ type Cloned interface {
2825 Tree () * Tree
2926}
3027
31- func cloneOneNoProxy (ctx context.Context , addr Address ) Cloned {
32- return & clonedNoProxy {all : false , addr : addr , repo : cloneToMemoryOrInit (ctx , addr )}
33- }
34-
35- func cloneAllNoProxy (ctx context.Context , addr Address ) Cloned {
36- c := & clonedNoProxy {all : true , addr : addr , repo : cloneToMemoryOrInit (ctx , addr )}
37- c .Pull (ctx )
38- return c
39- }
40-
41- func cloneToMemoryOrInit (ctx context.Context , addr Address ) * Repository {
42- repo , err := must .Try1 (func () * Repository { return cloneToMemory (ctx , addr ) })
43- if err == nil {
44- return repo
45- }
46- _ , isNoBranch := err .(git.NoMatchingRefSpecError )
47- if ! isNoBranch && err != transport .ErrEmptyRemoteRepository && err != plumbing .ErrReferenceNotFound {
48- must .Panic (ctx , err )
49- }
50- repo = initInMemory (ctx )
51-
52- _ , err = repo .CreateRemote (& config.RemoteConfig {Name : Origin , URLs : []string {string (addr .Repo )}})
53- must .NoError (ctx , err )
54-
55- err = repo .CreateBranch (& config.Branch {Name : string (addr .Branch ), Remote : Origin })
56- must .NoError (ctx , err )
57-
58- ChangeDefaultBranch (ctx , repo , addr .Branch )
59-
60- return repo
61- }
62-
6328func initInMemory (ctx context.Context ) * Repository {
6429 repo , err := git .Init (memory .NewStorage (), memfs .New ())
6530 must .NoError (ctx , err )
6631 return repo
6732}
68-
69- func cloneToMemory (ctx context.Context , addr Address ) * Repository {
70- repo , err := git .CloneContext (ctx ,
71- memory .NewStorage (),
72- memfs .New (),
73- & git.CloneOptions {
74- URL : string (addr .Repo ),
75- Auth : GetAuth (ctx , addr .Repo ),
76- ReferenceName : plumbing .NewBranchReferenceName (string (addr .Branch )),
77- },
78- )
79- must .NoError (ctx , err )
80-
81- return repo
82- }
83-
84- type clonedNoProxy struct {
85- all bool
86- addr Address
87- repo * Repository
88- }
89-
90- func (x * clonedNoProxy ) Push (ctx context.Context ) {
91- PushOnce (ctx , x .repo , x .addr .Repo , mirrorRefSpecs )
92- }
93-
94- func (x * clonedNoProxy ) Pull (ctx context.Context ) {
95- PullOnce (ctx , x .repo , x .addr .Repo , clonePullRefSpecs (x .addr , x .all ))
96- }
97-
98- func (x * clonedNoProxy ) Repo () * Repository {
99- return x .repo
100- }
101-
102- func (x * clonedNoProxy ) Tree () * Tree {
103- t , _ := x .Repo ().Worktree ()
104- return t
105- }
0 commit comments