aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorAyman Bagabas <ayman.bagabas@gmail.com>2023-04-04 01:13:21 -0400
committerAyman Bagabas <ayman.bagabas@gmail.com>2023-04-17 17:43:46 -0400
commit9a5b08f5c32bad31a35a53c045ebf6c8409f8b2c (patch)
treeef6d49278f14de59481e8e49ac8503c309f534c6 /repository_test.go
parentb154dcce7059e4e02f8798db158b6a76ffc4a63e (diff)
downloadgo-git-9a5b08f5c32bad31a35a53c045ebf6c8409f8b2c.tar.gz
feat(clone): add mirror clone option
Clone remote as a mirror. This fetches all remote refs, implies bare repository, and sets the appropriate configs. Fixes: https://github.com/go-git/go-git/issues/293 Update options.go Co-authored-by: Paulo Gomes <paulo.gomes.uk@gmail.com> Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index 468ce33..ed3e7e6 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -189,6 +189,35 @@ func (s *RepositorySuite) TestCloneContext(c *C) {
c.Assert(err, Equals, context.Canceled)
}
+func (s *RepositorySuite) TestCloneMirror(c *C) {
+ r, err := Clone(memory.NewStorage(), nil, &CloneOptions{
+ URL: fixtures.Basic().One().URL,
+ Mirror: true,
+ })
+
+ c.Assert(err, IsNil)
+
+ refs, err := r.References()
+ var count int
+ refs.ForEach(func(r *plumbing.Reference) error { c.Log(r); count++; return nil })
+ c.Assert(err, IsNil)
+ // 6 refs total from github.com/git-fixtures/basic.git:
+ // - HEAD
+ // - refs/heads/master
+ // - refs/heads/branch
+ // - refs/pull/1/head
+ // - refs/pull/2/head
+ // - refs/pull/2/merge
+ c.Assert(count, Equals, 6)
+
+ cfg, err := r.Config()
+ c.Assert(err, IsNil)
+
+ c.Assert(cfg.Core.IsBare, Equals, true)
+ c.Assert(cfg.Remotes[DefaultRemoteName].Validate(), IsNil)
+ c.Assert(cfg.Remotes[DefaultRemoteName].Mirror, Equals, true)
+}
+
func (s *RepositorySuite) TestCloneWithTags(c *C) {
url := s.GetLocalRepositoryURL(
fixtures.ByURL("https://github.com/git-fixtures/tags.git").One(),