r-lib / gert

Simple git client for R
https://docs.ropensci.org/gert/
Other
148 stars 32 forks source link

Add depth argument to git_clone #169

Closed mbreshock closed 2 years ago

mbreshock commented 2 years ago

We would like to be able to specify a depth flag in the git_clone function, similar to this issue raised with the cli package here: https://github.com/cli/cli/issues/1456. If possible, please add a depth argument to your git functions to allow users to specify how many versions are cloned.

This can be done in the command line like so: gh repo clone [repo] [directory] -- --depth 1

Original:

function (url, path = NULL, branch = NULL, password = askpass,
ssh_key = NULL, bare = FALSE, mirror = FALSE, verbose = interactive())
{
stopifnot(is.character(url))
if (!length(path))
path <- file.path(getwd(), basename(url))
stopifnot(is.character(path))
stopifnot(is.null(branch) || is.character(branch))
verbose <- as.logical(verbose)
path <- normalizePath(path.expand(path), mustWork = FALSE)
host <- url_to_host(url)
key_cb <- make_key_cb(ssh_key, host = host, password = password)
cred_cb <- make_cred_cb(password = password, verbose = verbose)
repo <- .Call(R_git_repository_clone, url, path, branch,
key_cb, cred_cb, bare, mirror, verbose)
git_repo_path(repo)
}

Proposed:

function (url, path = NULL, branch = NULL, password = askpass,
ssh_key = NULL, bare = FALSE, mirror = FALSE, verbose = interactive(), depth = NULL)
{
stopifnot(is.character(url))
if (!length(path))
path <- file.path(getwd(), basename(url))
stopifnot(is.character(path))
stopifnot(is.null(branch) || is.character(branch))
verbose <- as.logical(verbose)
path <- normalizePath(path.expand(path), mustWork = FALSE)
host <- url_to_host(url)
key_cb <- make_key_cb(ssh_key, host = host, password = password)
cred_cb <- make_cred_cb(password = password, verbose = verbose)
depth <- if(depth != NULL){as.integer(depth)}
repo <- .Call(R_git_repository_clone, url, path, branch,
key_cb, cred_cb, bare, mirror, verbose, depth)
# would add line here that makes sense when depth is null
git_repo_path(repo)
}

usage:

git_clone(url = https://github.com/rstudio/rmarkdown.git, depth = 5)
jeroen commented 2 years ago

This is a duplicate of https://github.com/r-lib/gert/issues/101. Sadly this is still not supported in libgit2 :(

mbreshock commented 2 years ago

Ah, sorry, should have reviewed the closed issues first. Thanks for the quick reply!