From 970f99e7b42e96e49f5070aed2eca8e41458028a Mon Sep 17 00:00:00 2001
From: nzinfo
Date: Wed, 5 Feb 2025 16:35:58 +0800
Subject: [PATCH] add depth option
---
remote.go | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/remote.go b/remote.go
index a294ca23..e6694981 100644
--- a/remote.go
+++ b/remote.go
@@ -144,6 +144,11 @@ type FetchOptions struct {
// Proxy options to use for this fetch operation
ProxyOptions ProxyOptions
+
+ // Depth controls the depth of the fetch/clone operation.
+ // A value of 0 means no depth limit (fetch/clone everything).
+ // A positive value will limit the history to that number of commits.
+ Depth int
}
type RemoteConnectOptions struct {
@@ -685,7 +690,7 @@ func (c *RemoteCollection) Create(name string, url string) (*Remote, error) {
return remote, nil
}
-//CreateWithOptions Creates a repository object with extended options.
+// CreateWithOptions Creates a repository object with extended options.
func (c *RemoteCollection) CreateWithOptions(url string, option *RemoteCreateOptions) (*Remote, error) {
remote := &Remote{repo: c.repo}
@@ -991,6 +996,12 @@ func populateFetchOptions(copts *C.git_fetch_options, opts *FetchOptions, errorT
strings: makeCStringsFromStrings(opts.Headers),
}
populateProxyOptions(&copts.proxy_opts, &opts.ProxyOptions)
+
+ // Set depth if specified
+ if opts.Depth > 0 {
+ copts.depth = C.int(opts.Depth)
+ }
+
return copts
}