aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-04-17 23:05:06 +0100
committerGitHub <noreply@github.com>2023-04-17 23:05:06 +0100
commit0a1c5ab118998a22ef88d8e6c42970197d77413c (patch)
tree68ee12567f4ab297639e31fe1ebcf666a77c5531 /repository.go
parent7cd387bd28a95590d9536b4344d4ff60b75d6590 (diff)
parent9a5b08f5c32bad31a35a53c045ebf6c8409f8b2c (diff)
downloadgo-git-0a1c5ab118998a22ef88d8e6c42970197d77413c.tar.gz
Merge pull request #735 from aymanbagabas/clone-mirror
git: add mirror clone option
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go14
1 files changed, 10 insertions, 4 deletions
diff --git a/repository.go b/repository.go
index 56ae976..e009c5d 100644
--- a/repository.go
+++ b/repository.go
@@ -444,6 +444,9 @@ func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOp
return nil, err
}
+ if o.Mirror {
+ isBare = true
+ }
r, err := PlainInit(path, isBare)
if err != nil {
return nil, err
@@ -851,9 +854,10 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
}
c := &config.RemoteConfig{
- Name: o.RemoteName,
- URLs: []string{o.URL},
- Fetch: r.cloneRefSpec(o),
+ Name: o.RemoteName,
+ URLs: []string{o.URL},
+ Fetch: r.cloneRefSpec(o),
+ Mirror: o.Mirror,
}
if _, err := r.CreateRemote(c); err != nil {
@@ -906,7 +910,7 @@ func (r *Repository) clone(ctx context.Context, o *CloneOptions) error {
return err
}
- if ref.Name().IsBranch() {
+ if !o.Mirror && ref.Name().IsBranch() {
branchRef := ref.Name()
branchName := strings.Split(string(branchRef), "refs/heads/")[1]
@@ -937,6 +941,8 @@ const (
func (r *Repository) cloneRefSpec(o *CloneOptions) []config.RefSpec {
switch {
+ case o.Mirror:
+ return []config.RefSpec{"+refs/*:refs/*"}
case o.ReferenceName.IsTag():
return []config.RefSpec{
config.RefSpec(fmt.Sprintf(refspecTag, o.ReferenceName.Short())),