@@ -262,15 +262,21 @@ The keyword arguments are:
262262 * `remoteurl::AbstractString=""`: the URL of `remote`. If not specified,
263263 will be assumed based on the given name of `remote`.
264264 * `refspecs=AbstractString[]`: determines properties of the fetch.
265+ * `depth::Integer=0`: limit fetching to the specified number of commits from the tip
266+ of each remote branch. `0` indicates a full fetch (the default).
267+ Use `Consts.FETCH_DEPTH_UNSHALLOW` to fetch all missing data from a shallow clone.
268+ Note: depth is, at the time of writing, only supported for network protocols (http, https, git, ssh), not for local filesystem paths.
269+ (https://github.com/libgit2/libgit2/issues/6634)
265270 * `credentials=nothing`: provides credentials and/or settings when authenticating against
266271 a private `remote`.
267272 * `callbacks=Callbacks()`: user provided callbacks and payloads.
268273
269- Equivalent to `git fetch [<remoteurl>|<repo>] [<refspecs>]`.
274+ Equivalent to `git fetch [--depth <depth>] [ <remoteurl>|<repo>] [<refspecs>]`.
270275"""
271276function fetch (repo:: GitRepo ; remote:: AbstractString = " origin" ,
272277 remoteurl:: AbstractString = " " ,
273278 refspecs:: Vector{<:AbstractString} = AbstractString[],
279+ depth:: Integer = 0 ,
274280 credentials:: Creds = nothing ,
275281 callbacks:: Callbacks = Callbacks ())
276282 rmt = if isempty (remoteurl)
@@ -290,7 +296,12 @@ function fetch(repo::GitRepo; remote::AbstractString="origin",
290296
291297 result = try
292298 remote_callbacks = RemoteCallbacks (callbacks)
293- fo = FetchOptions (callbacks= remote_callbacks)
299+ @static if LibGit2. VERSION >= v " 1.7.0"
300+ fo = FetchOptions (callbacks= remote_callbacks, depth= Cuint (depth))
301+ else
302+ depth != 0 && throw (ArgumentError (" Depth parameter for fetch requires libgit2 >= 1.7.0" ))
303+ fo = FetchOptions (callbacks= remote_callbacks)
304+ end
294305 fetch (rmt, refspecs, msg= " from $(url (rmt)) " , options= fo)
295306 catch err
296307 if isa (err, GitError) && err. code === Error. EAUTH
@@ -539,11 +550,16 @@ The keyword arguments are:
539550 * `remote_cb::Ptr{Cvoid}=C_NULL`: a callback which will be used to create the remote
540551 before it is cloned. If `C_NULL` (the default), no attempt will be made to create
541552 the remote - it will be assumed to already exist.
553+ * `depth::Integer=0`: create a shallow clone with a history truncated to the
554+ specified number of commits. `0` indicates a full clone (the default).
555+ Use `Consts.FETCH_DEPTH_UNSHALLOW` to fetch all missing data from a shallow clone.
556+ Note: shallow clones are, at the time of writing, only supported for network protocols (http, https, git, ssh), not for local filesystem paths.
557+ (https://github.com/libgit2/libgit2/issues/6634)
542558 * `credentials::Creds=nothing`: provides credentials and/or settings when authenticating
543559 against a private repository.
544560 * `callbacks::Callbacks=Callbacks()`: user provided callbacks and payloads.
545561
546- Equivalent to `git clone [-b <branch>] [--bare] <repo_url> <repo_path>`.
562+ Equivalent to `git clone [-b <branch>] [--bare] [--depth <depth>] <repo_url> <repo_path>`.
547563
548564# Examples
549565```julia
@@ -552,12 +568,15 @@ repo1 = LibGit2.clone(repo_url, "test_path")
552568repo2 = LibGit2.clone(repo_url, "test_path", isbare=true)
553569julia_url = "https://github.com/JuliaLang/julia"
554570julia_repo = LibGit2.clone(julia_url, "julia_path", branch="release-0.6")
571+ # Shallow clone with only the most recent commit
572+ shallow_repo = LibGit2.clone(repo_url, "shallow_path", depth=1)
555573```
556574"""
557575function clone (repo_url:: AbstractString , repo_path:: AbstractString ;
558576 branch:: AbstractString = " " ,
559577 isbare:: Bool = false ,
560578 remote_cb:: Ptr{Cvoid} = C_NULL ,
579+ depth:: Integer = 0 ,
561580 credentials:: Creds = nothing ,
562581 callbacks:: Callbacks = Callbacks ())
563582 cred_payload = reset! (CredentialPayload (credentials))
@@ -573,7 +592,12 @@ function clone(repo_url::AbstractString, repo_path::AbstractString;
573592 lbranch = Base. cconvert (Cstring, branch)
574593 GC. @preserve lbranch begin
575594 remote_callbacks = RemoteCallbacks (callbacks)
576- fetch_opts = FetchOptions (callbacks= remote_callbacks)
595+ @static if LibGit2. VERSION >= v " 1.7.0"
596+ fetch_opts = FetchOptions (callbacks= remote_callbacks, depth= Cuint (depth))
597+ else
598+ depth != 0 && throw (ArgumentError (" Shallow clone (depth parameter) requires libgit2 >= 1.7.0" ))
599+ fetch_opts = FetchOptions (callbacks= remote_callbacks)
600+ end
577601 clone_opts = CloneOptions (
578602 bare = Cint (isbare),
579603 checkout_branch = isempty (lbranch) ? Cstring (C_NULL ) : Base. unsafe_convert (Cstring, lbranch),
0 commit comments