Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
##' see examples. Pass NULL to use the
##' \code{remote.<repository>.fetch} variable. Default is
##' \code{NULL}.
##' @param proxy Either \code{NULL} (the default) to disable proxy usage,
##' \code{TRUE} for automatic proxy detection, or a character string
##' with a proxy URL (for example, \code{"http://proxy.example.org:3128"}).
##' @return invisible list of class \code{git_transfer_progress}
##' with statistics from the fetch operation:
##' \describe{
Expand Down Expand Up @@ -96,9 +99,9 @@
##' summary(repo)
##' }
fetch <- function(repo = ".", name = NULL, credentials = NULL,
verbose = TRUE, refspec = NULL) {
verbose = TRUE, refspec = NULL, proxy = NULL) {
invisible(.Call(git2r_remote_fetch, lookup_repository(repo),
name, credentials, "fetch", verbose, refspec))
name, credentials, "fetch", verbose, refspec, proxy))
}

##' Get updated heads during the last fetch.
Expand Down
8 changes: 6 additions & 2 deletions R/push.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ get_upstream_name <- function(object) {
##' ssh key credentials, let this parameter be NULL (the default).
##' @param set_upstream Set the current local branch to track the
##' remote branch. Default is FALSE.
##' @param proxy Either \code{NULL} (the default) to disable proxy usage,
##' \code{TRUE} for automatic proxy detection, or a character string
##' with a proxy URL (for example, \code{"http://proxy.example.org:3128"}).
##' @return invisible(NULL)
##' @seealso \code{\link{cred_user_pass}}, \code{\link{cred_ssh_key}}
##' @export
Expand Down Expand Up @@ -98,7 +101,8 @@ push <- function(object = ".",
refspec = NULL,
force = FALSE,
credentials = NULL,
set_upstream = FALSE) {
set_upstream = FALSE,
proxy = NULL) {
if (is_branch(object)) {
name <- get_upstream_name(object)

Expand Down Expand Up @@ -126,7 +130,7 @@ push <- function(object = ".",
refspec <- tmp$refspec
}

.Call(git2r_push, object, name, refspec, credentials)
.Call(git2r_push, object, name, refspec, credentials, proxy)

if (isTRUE(set_upstream)) {
b <- repository_head(object)
Expand Down
9 changes: 6 additions & 3 deletions R/remote.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ remote_url <- function(repo = ".", remote = NULL) {
##' @param credentials The credentials for remote repository
##' access. Default is NULL. To use and query an ssh-agent for the
##' ssh key credentials, let this parameter be NULL (the default).
##' @param proxy Either \code{NULL} (the default) to disable proxy usage,
##' \code{TRUE} for automatic proxy detection, or a character string
##' with a proxy URL (for example, \code{"http://proxy.example.org:3128"}).
##' @return Character vector for each reference with the associated
##' commit IDs.
##' @export
Expand All @@ -120,7 +123,7 @@ remote_url <- function(repo = ".", remote = NULL) {
##' \dontrun{
##' remote_ls("https://github.com/ropensci/git2r")
##' }
remote_ls <- function(name = NULL, repo = NULL, credentials = NULL) {
remote_ls <- function(name = NULL, repo = NULL, credentials = NULL, proxy = NULL) {
if (is.null(repo)) {
ver <- libgit2_version()
if (ver$major == 0 && ver$minor < 27) {
Expand All @@ -132,5 +135,5 @@ remote_ls <- function(name = NULL, repo = NULL, credentials = NULL) {
repo <- lookup_repository(repo)
}

.Call(git2r_remote_ls, name, repo, credentials)
}
.Call(git2r_remote_ls, name, repo, credentials, proxy)
}
8 changes: 6 additions & 2 deletions R/repository.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ init <- function(path = ".", bare = FALSE, branch = NULL) {
##' access. Default is NULL. To use and query an ssh-agent for the
##' ssh key credentials, let this parameter be NULL (the default).
##' @param progress Show progress. Default is TRUE.
##' @param proxy Either \code{NULL} (the default) to disable proxy usage,
##' \code{TRUE} for automatic proxy detection, or a character string
##' with a proxy URL (for example, \code{"http://proxy.example.org:3128"}).
##' @return A \code{git_repository} object.
##' @seealso \link{repository}, \code{\link{cred_user_pass}},
##' \code{\link{cred_ssh_key}}
Expand Down Expand Up @@ -273,9 +276,10 @@ clone <- function(url,
branch = NULL,
checkout = TRUE,
credentials = NULL,
progress = TRUE) {
progress = TRUE,
proxy = NULL) {
.Call(git2r_clone, url, local_path, bare,
branch, checkout, credentials, progress)
branch, checkout, credentials, progress, proxy)
repository(local_path)
}

Expand Down
7 changes: 6 additions & 1 deletion man/clone.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/fetch.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion man/push.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion man/remote_ls.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/git2r.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static const R_CallMethodDef callMethods[] =
CALLDEF(git2r_branch_upstream_canonical_name, 1),
CALLDEF(git2r_checkout_path, 2),
CALLDEF(git2r_checkout_tree, 3),
CALLDEF(git2r_clone, 7),
CALLDEF(git2r_clone, 8),
CALLDEF(git2r_commit, 4),
CALLDEF(git2r_commit_parent_list, 1),
CALLDEF(git2r_commit_tree, 1),
Expand Down Expand Up @@ -109,18 +109,18 @@ static const R_CallMethodDef callMethods[] =
CALLDEF(git2r_odb_hash, 1),
CALLDEF(git2r_odb_hashfile, 1),
CALLDEF(git2r_odb_objects, 1),
CALLDEF(git2r_push, 4),
CALLDEF(git2r_push, 5),
CALLDEF(git2r_reference_dwim, 2),
CALLDEF(git2r_reference_list, 1),
CALLDEF(git2r_reflog_list, 2),
CALLDEF(git2r_remote_add, 3),
CALLDEF(git2r_remote_fetch, 6),
CALLDEF(git2r_remote_fetch, 7),
CALLDEF(git2r_remote_list, 1),
CALLDEF(git2r_remote_remove, 2),
CALLDEF(git2r_remote_rename, 3),
CALLDEF(git2r_remote_set_url, 3),
CALLDEF(git2r_remote_url, 2),
CALLDEF(git2r_remote_ls, 3),
CALLDEF(git2r_remote_ls, 4),
CALLDEF(git2r_repository_can_open, 1),
CALLDEF(git2r_repository_discover, 2),
CALLDEF(git2r_repository_fetch_heads, 1),
Expand Down
21 changes: 21 additions & 0 deletions src/git2r_arg.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,27 @@ git2r_arg_check_real(
return 0;
}

/**
* Check proxy argument
*
* proxy may be NULL, TRUE or a string
*
* @param arg the arg to check
* @return 0 if OK, else -1
*/
int attribute_hidden
git2r_arg_check_proxy(
SEXP arg)
{
if (Rf_isNull(arg))
return 0;
if (Rf_isLogical(arg) && 1 == Rf_length(arg) && NA_LOGICAL != LOGICAL(arg)[0])
return 0;
if (Rf_isString(arg) && 1 == Rf_length(arg) && NA_STRING != STRING_ELT(arg, 0))
return 0;
return -1;
}

/**
* Check repository argument
*
Expand Down
1 change: 1 addition & 0 deletions src/git2r_arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ int git2r_arg_check_integer_gte_zero(SEXP arg);
int git2r_arg_check_list(SEXP arg);
int git2r_arg_check_logical(SEXP arg);
int git2r_arg_check_note(SEXP arg);
int git2r_arg_check_proxy(SEXP arg);
int git2r_arg_check_repository(SEXP arg);
int git2r_arg_check_same_repo(SEXP arg1, SEXP arg2);
int git2r_arg_check_signature(SEXP arg);
Expand Down
19 changes: 18 additions & 1 deletion src/git2r_clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "git2r_clone.h"
#include "git2r_cred.h"
#include "git2r_error.h"
#include "git2r_proxy.h"
#include "git2r_transfer.h"

/**
Expand Down Expand Up @@ -76,6 +77,7 @@ git2r_clone_progress(
* @param checkout Checkout HEAD after the clone is complete.
* @param credentials The credentials for remote repository access.
* @param progress show progress
* @param proxy_val The proxy settings
* @return R_NilValue
*/
SEXP attribute_hidden
Expand All @@ -86,13 +88,15 @@ git2r_clone(
SEXP branch,
SEXP checkout,
SEXP credentials,
SEXP progress)
SEXP progress,
SEXP proxy_val)
{
int error;
git_repository *repository = NULL;
git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git2r_transfer_data payload = GIT2R_TRANSFER_DATA_INIT;
git_proxy_options proxy_opts = GIT_PROXY_OPTIONS_INIT;

if (git2r_arg_check_string(url))
git2r_error(__func__, NULL, "'url'", git2r_err_string_arg);
Expand All @@ -108,12 +112,25 @@ git2r_clone(
git2r_error(__func__, NULL, "'credentials'", git2r_err_credentials_arg);
if (git2r_arg_check_logical(progress))
git2r_error(__func__, NULL, "'progress'", git2r_err_logical_arg);
if (git2r_arg_check_proxy(proxy_val))
git2r_error(__func__, NULL, "'proxy_val'", git2r_err_proxy_arg);

if (LOGICAL(checkout)[0])
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
else
checkout_opts.checkout_strategy = GIT_CHECKOUT_NONE;

/* Initialize proxy options */
error = git2r_set_proxy_options(&proxy_opts, proxy_val);
if (error)
git2r_error(
__func__,
git_error_last(),
git2r_err_unable_to_set_proxy_options,
NULL);

clone_opts.fetch_opts.proxy_opts = proxy_opts;

clone_opts.checkout_opts = checkout_opts;
payload.credentials = credentials;
clone_opts.fetch_opts.callbacks.payload = &payload;
Expand Down
3 changes: 2 additions & 1 deletion src/git2r_clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ SEXP git2r_clone(
SEXP branch,
SEXP checkout,
SEXP credentials,
SEXP progress);
SEXP progress,
SEXP proxy_val);

#endif
3 changes: 3 additions & 0 deletions src/git2r_error.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const char git2r_err_ssl_cert_locations[] =
"Either 'filename' or 'path' may be 'NULL', but not both";
const char git2r_err_unexpected_config_level[] = "Unexpected config level";
const char git2r_err_unable_to_authenticate[] = "Unable to authenticate with supplied credentials";
const char git2r_err_unable_to_set_proxy_options[] = "Unable to set proxy options";

/**
* Error messages specific to argument checking
Expand All @@ -55,6 +56,8 @@ const char git2r_err_commit_stash_arg[] =
"must be an S3 class git_commit or an S3 class git_stash";
const char git2r_err_credentials_arg[] =
"must be an S3 class with credentials";
const char git2r_err_proxy_arg[] =
"must be either 1) NULL, or 2) TRUE or 3) a character vector";
const char git2r_err_diff_arg[] =
"Invalid diff parameters";
const char git2r_err_fetch_heads_arg[] =
Expand Down
2 changes: 2 additions & 0 deletions src/git2r_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ extern const char git2r_err_revparse_single[];
extern const char git2r_err_ssl_cert_locations[];
extern const char git2r_err_unexpected_config_level[];
extern const char git2r_err_unable_to_authenticate[];
extern const char git2r_err_unable_to_set_proxy_options[];

/**
* Error messages specific to argument checking
Expand All @@ -49,6 +50,7 @@ extern const char git2r_err_branch_arg[];
extern const char git2r_err_commit_arg[];
extern const char git2r_err_commit_stash_arg[];
extern const char git2r_err_credentials_arg[];
extern const char git2r_err_proxy_arg[];
extern const char git2r_err_diff_arg[];
extern const char git2r_err_fetch_heads_arg[];
extern const char git2r_err_filename_arg[];
Expand Down
Loading
Loading