aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Gomes <pjbgf@linux.com>2023-05-04 22:44:14 +0100
committerGitHub <noreply@github.com>2023-05-04 22:44:14 +0100
commit1dbd729a387edb61c89f088cd68040085e6c81bb (patch)
tree81a8abeb928fbe07cf75eaf12705e57009c41077
parent2f3db9de0c31de26303eb389b3f3133f7aa67a04 (diff)
parentecc9fe45b6261492c0cfdcdb1ff4e642252d6694 (diff)
downloadgo-git-1dbd729a387edb61c89f088cd68040085e6c81bb.tar.gz
Merge pull request #754 from matejrisek/feature/submodule-clone-depth
git: Add Depth to SubmoduleUpdateOptions
-rw-r--r--options.go3
-rw-r--r--submodule.go3
-rw-r--r--submodule_test.go29
3 files changed, 34 insertions, 1 deletions
diff --git a/options.go b/options.go
index 84744c7..3d75e03 100644
--- a/options.go
+++ b/options.go
@@ -300,6 +300,9 @@ type SubmoduleUpdateOptions struct {
RecurseSubmodules SubmoduleRescursivity
// Auth credentials, if required, to use with the remote repository.
Auth transport.AuthMethod
+ // Depth limit fetching to the specified number of commits from the tip of
+ // each remote branch history.
+ Depth int
}
var (
diff --git a/submodule.go b/submodule.go
index a202a9b..b0c4169 100644
--- a/submodule.go
+++ b/submodule.go
@@ -243,7 +243,7 @@ func (s *Submodule) fetchAndCheckout(
ctx context.Context, r *Repository, o *SubmoduleUpdateOptions, hash plumbing.Hash,
) error {
if !o.NoFetch {
- err := r.FetchContext(ctx, &FetchOptions{Auth: o.Auth})
+ err := r.FetchContext(ctx, &FetchOptions{Auth: o.Auth, Depth: o.Depth})
if err != nil && err != NoErrAlreadyUpToDate {
return err
}
@@ -265,6 +265,7 @@ func (s *Submodule) fetchAndCheckout(
err := r.FetchContext(ctx, &FetchOptions{
Auth: o.Auth,
RefSpecs: []config.RefSpec{refSpec},
+ Depth: o.Depth,
})
if err != nil && err != NoErrAlreadyUpToDate && err != ErrExactSHA1NotSupported {
return err
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)
+}