aboutsummaryrefslogtreecommitdiffstats
path: root/repository_test.go
diff options
context:
space:
mode:
authorenverbisevac <enver@bisevac.com>2023-10-06 02:54:20 +0200
committerenverbisevac <enver@bisevac.com>2023-10-08 00:40:30 +0200
commit479d3e952e75d6e41b71a81cc9a92dec792825ba (patch)
treed2cfec4017f7a1aadd295cb900046fe34c90a39b /repository_test.go
parentced662e9db6667069a5255446425ec40d388f7e1 (diff)
downloadgo-git-479d3e952e75d6e41b71a81cc9a92dec792825ba.tar.gz
git: clone --shared implemented
Diffstat (limited to 'repository_test.go')
-rw-r--r--repository_test.go96
1 files changed, 96 insertions, 0 deletions
diff --git a/repository_test.go b/repository_test.go
index 3154f1d..f6839b6 100644
--- a/repository_test.go
+++ b/repository_test.go
@@ -9,6 +9,7 @@ import (
"os"
"os/exec"
"os/user"
+ "path"
"path/filepath"
"regexp"
"strings"
@@ -791,6 +792,101 @@ func (s *RepositorySuite) TestPlainClone(c *C) {
c.Assert(cfg.Branches["master"].Name, Equals, "master")
}
+func (s *RepositorySuite) TestPlainCloneBareAndShared(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ remote := s.GetBasicLocalRepositoryURL()
+
+ r, err := PlainClone(dir, true, &CloneOptions{
+ URL: remote,
+ Shared: true,
+ })
+ c.Assert(err, IsNil)
+
+ altpath := path.Join(dir, "objects", "info", "alternates")
+ _, err = os.Stat(altpath)
+ c.Assert(err, IsNil)
+
+ data, err := os.ReadFile(altpath)
+ c.Assert(err, IsNil)
+
+ line := path.Join(remote, GitDirName, "objects") + "\n"
+ c.Assert(string(data), Equals, line)
+
+ cfg, err := r.Config()
+ c.Assert(err, IsNil)
+ c.Assert(cfg.Branches, HasLen, 1)
+ c.Assert(cfg.Branches["master"].Name, Equals, "master")
+}
+
+func (s *RepositorySuite) TestPlainCloneShared(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ remote := s.GetBasicLocalRepositoryURL()
+
+ r, err := PlainClone(dir, false, &CloneOptions{
+ URL: remote,
+ Shared: true,
+ })
+ c.Assert(err, IsNil)
+
+ altpath := path.Join(dir, GitDirName, "objects", "info", "alternates")
+ _, err = os.Stat(altpath)
+ c.Assert(err, IsNil)
+
+ data, err := os.ReadFile(altpath)
+ c.Assert(err, IsNil)
+
+ line := path.Join(remote, GitDirName, "objects") + "\n"
+ c.Assert(string(data), Equals, line)
+
+ cfg, err := r.Config()
+ c.Assert(err, IsNil)
+ c.Assert(cfg.Branches, HasLen, 1)
+ c.Assert(cfg.Branches["master"].Name, Equals, "master")
+}
+
+func (s *RepositorySuite) TestPlainCloneSharedHttpShouldReturnError(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ remote := "http://somerepo"
+
+ _, err := PlainClone(dir, false, &CloneOptions{
+ URL: remote,
+ Shared: true,
+ })
+ c.Assert(err, Equals, ErrAlternatePathNotSupported)
+}
+
+func (s *RepositorySuite) TestPlainCloneSharedHttpsShouldReturnError(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ remote := "https://somerepo"
+
+ _, err := PlainClone(dir, false, &CloneOptions{
+ URL: remote,
+ Shared: true,
+ })
+ c.Assert(err, Equals, ErrAlternatePathNotSupported)
+}
+
+func (s *RepositorySuite) TestPlainCloneSharedSSHShouldReturnError(c *C) {
+ dir, clean := s.TemporalDir()
+ defer clean()
+
+ remote := "ssh://somerepo"
+
+ _, err := PlainClone(dir, false, &CloneOptions{
+ URL: remote,
+ Shared: true,
+ })
+ c.Assert(err, Equals, ErrAlternatePathNotSupported)
+}
+
func (s *RepositorySuite) TestPlainCloneWithRemoteName(c *C) {
dir, clean := s.TemporalDir()
defer clean()