From ecc9fe45b6261492c0cfdcdb1ff4e642252d6694 Mon Sep 17 00:00:00 2001 From: "matej.risek" Date: Thu, 4 May 2023 09:04:23 +0200 Subject: git: Add Depth to SubmoduleUpdateOptions --- submodule_test.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'submodule_test.go') diff --git a/submodule_test.go b/submodule_test.go index 4bae544..a8a0681 100644 --- a/submodule_test.go +++ b/submodule_test.go @@ -233,3 +233,32 @@ 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) +} -- cgit From b8dd39abcc9dd35808ec625a90a68c0ace4973e4 Mon Sep 17 00:00:00 2001 From: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> Date: Thu, 11 May 2023 11:17:04 +1000 Subject: git: Testing, Fix tests not cleaning temp folders Signed-off-by: Arieh Schneier <15041913+AriehSchneier@users.noreply.github.com> --- submodule_test.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'submodule_test.go') diff --git a/submodule_test.go b/submodule_test.go index a8a0681..92943e1 100644 --- a/submodule_test.go +++ b/submodule_test.go @@ -2,7 +2,6 @@ package git import ( "context" - "os" "path/filepath" "testing" @@ -15,7 +14,7 @@ import ( type SubmoduleSuite struct { BaseSuite Worktree *Worktree - path string + clean func() } var _ = Suite(&SubmoduleSuite{}) @@ -23,8 +22,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 +34,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 +194,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) -- cgit From 9706315a961c52184e2f9111883b08df6ac702b8 Mon Sep 17 00:00:00 2001 From: "matej.risek" Date: Mon, 5 Jun 2023 14:03:47 +0200 Subject: git: fix the issue with submodules having the SCP style URL fail due to the wrong URL parsing --- submodule_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'submodule_test.go') diff --git a/submodule_test.go b/submodule_test.go index a8a0681..a066af2 100644 --- a/submodule_test.go +++ b/submodule_test.go @@ -6,7 +6,10 @@ import ( "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" @@ -262,3 +265,26 @@ func (s *SubmoduleSuite) TestSubmodulesFetchDepth(c *C) { 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) +} -- cgit