aboutsummaryrefslogtreecommitdiffstats
path: root/submodule_test.go
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-08-05 10:20:38 +0100
committerGitHub <noreply@github.com>2023-08-05 10:20:38 +0100
commite6f68d2e4cd1bc4447126816c7c27e1fc2098e30 (patch)
tree15c5e333b93641f9eadcb4bf4b34c338135f7a23 /submodule_test.go
parent5882d60fb7ccd4cfc0fe69286aa96e198c9d1eb0 (diff)
parent4ec6b3f4fa9cdfe8f10d0953ac7d398d01a90f17 (diff)
downloadgo-git-e6f68d2e4cd1bc4447126816c7c27e1fc2098e30.tar.gz
Merge branch 'master' into jc/commit-ammend
Diffstat (limited to 'submodule_test.go')
-rw-r--r--submodule_test.go71
1 files changed, 61 insertions, 10 deletions
diff --git a/submodule_test.go b/submodule_test.go
index 4bae544..0e88391 100644
--- a/submodule_test.go
+++ b/submodule_test.go
@@ -2,11 +2,13 @@ package git
import (
"context"
- "os"
"path/filepath"
"testing"
+ "github.com/go-git/go-billy/v5/memfs"
+ "github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
+ "github.com/go-git/go-git/v5/storage/memory"
fixtures "github.com/go-git/go-git-fixtures/v4"
. "gopkg.in/check.v1"
@@ -15,7 +17,7 @@ import (
type SubmoduleSuite struct {
BaseSuite
Worktree *Worktree
- path string
+ clean func()
}
var _ = Suite(&SubmoduleSuite{})
@@ -23,8 +25,8 @@ var _ = Suite(&SubmoduleSuite{})
func (s *SubmoduleSuite) SetUpTest(c *C) {
path := fixtures.ByTag("submodule").One().Worktree().Root()
- dir, clean := s.TemporalDir()
- defer clean()
+ var dir string
+ dir, s.clean = s.TemporalDir()
r, err := PlainClone(filepath.Join(dir, "worktree"), false, &CloneOptions{
URL: path,
@@ -35,13 +37,10 @@ func (s *SubmoduleSuite) SetUpTest(c *C) {
s.Repository = r
s.Worktree, err = r.Worktree()
c.Assert(err, IsNil)
-
- s.path = dir
}
-func (s *SubmoduleSuite) TearDownTest(c *C) {
- err := os.RemoveAll(s.path)
- c.Assert(err, IsNil)
+func (s *SubmoduleSuite) TearDownTest(_ *C) {
+ s.clean()
}
func (s *SubmoduleSuite) TestInit(c *C) {
@@ -198,7 +197,7 @@ func (s *SubmoduleSuite) TestSubmodulesInit(c *C) {
func (s *SubmoduleSuite) TestGitSubmodulesSymlink(c *C) {
f, err := s.Worktree.Filesystem.Create("badfile")
c.Assert(err, IsNil)
- defer f.Close()
+ defer func() { _ = f.Close() }()
err = s.Worktree.Filesystem.Remove(gitmodulesFile)
c.Assert(err, IsNil)
@@ -233,3 +232,55 @@ func (s *SubmoduleSuite) TestSubmodulesUpdateContext(c *C) {
err = sm.UpdateContext(ctx, &SubmoduleUpdateOptions{Init: true})
c.Assert(err, NotNil)
}
+
+func (s *SubmoduleSuite) TestSubmodulesFetchDepth(c *C) {
+ if testing.Short() {
+ c.Skip("skipping test in short mode.")
+ }
+
+ sm, err := s.Worktree.Submodule("basic")
+ c.Assert(err, IsNil)
+
+ err = sm.Update(&SubmoduleUpdateOptions{
+ Init: true,
+ Depth: 1,
+ })
+ c.Assert(err, IsNil)
+
+ r, err := sm.Repository()
+ c.Assert(err, IsNil)
+
+ lr, err := r.Log(&LogOptions{})
+ c.Assert(err, IsNil)
+
+ commitCount := 0
+ for _, err := lr.Next(); err == nil; _, err = lr.Next() {
+ commitCount++
+ }
+ c.Assert(err, IsNil)
+
+ c.Assert(commitCount, Equals, 1)
+}
+
+func (s *SubmoduleSuite) TestSubmoduleParseScp(c *C) {
+ repo := &Repository{
+ Storer: memory.NewStorage(),
+ wt: memfs.New(),
+ }
+ worktree := &Worktree{
+ Filesystem: memfs.New(),
+ r: repo,
+ }
+ submodule := &Submodule{
+ initialized: true,
+ c: nil,
+ w: worktree,
+ }
+
+ submodule.c = &config.Submodule{
+ URL: "git@github.com:username/submodule_repo",
+ }
+
+ _, err := submodule.Repository()
+ c.Assert(err, IsNil)
+}