diff --git a/NEWS b/NEWS index 6503a17..ffbc783 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +1.7.0 + - git_status() gains parameter pathspec + 1.6.0 - We recommend at least libgit2 1.0 now - Windows: update to libgit2 1.4.2 diff --git a/R/commit.R b/R/commit.R index ae59d4a..db4f2ce 100644 --- a/R/commit.R +++ b/R/commit.R @@ -153,10 +153,12 @@ git_rm <- function(files, repo = '.'){ #' @useDynLib gert R_git_status_list #' @param staged return only staged (TRUE) or unstaged files (FALSE). #' Use `NULL` or `NA` to show both (default). -git_status <- function(staged = NULL, repo = '.'){ +#' @param pathspec character vector with paths to match +git_status <- function(staged = NULL, pathspec = NULL, repo = '.'){ repo <- git_open(repo) staged <- as.logical(staged) - df <- .Call(R_git_status_list, repo, staged) + pathspec <- as.character(pathspec) + df <- .Call(R_git_status_list, repo, staged, pathspec) df[order(df$file), ,drop = FALSE] } diff --git a/man/git_commit.Rd b/man/git_commit.Rd index 8f1ad25..18cf177 100644 --- a/man/git_commit.Rd +++ b/man/git_commit.Rd @@ -29,7 +29,7 @@ git_add(files, force = FALSE, repo = ".") git_rm(files, repo = ".") -git_status(staged = NULL, repo = ".") +git_status(staged = NULL, pathspec = NULL, repo = ".") git_conflicts(repo = ".") @@ -64,6 +64,8 @@ Use \code{"."} to stage all changed files.} \item{staged}{return only staged (TRUE) or unstaged files (FALSE). Use \code{NULL} or \code{NA} to show both (default).} +\item{pathspec}{character vector with paths to match} + \item{max}{lookup at most latest n parent commits} \item{after}{date or timestamp: only include commits starting this date} diff --git a/src/files.c b/src/files.c index 45e6d40..a4abc35 100644 --- a/src/files.c +++ b/src/files.c @@ -165,7 +165,7 @@ static void extract_entry_data(const git_status_entry *file, char *status, char } } -SEXP R_git_status_list(SEXP ptr, SEXP show_staged){ +SEXP R_git_status_list(SEXP ptr, SEXP show_staged, SEXP path_spec){ git_status_list *list = NULL; git_repository *repo = get_git_repository(ptr); git_status_options opts = GIT_STATUS_OPTIONS_INIT; @@ -174,6 +174,11 @@ SEXP R_git_status_list(SEXP ptr, SEXP show_staged){ } else { opts.show = Rf_asLogical(show_staged) ? GIT_STATUS_SHOW_INDEX_ONLY : GIT_STATUS_SHOW_WORKDIR_ONLY; } + if(Rf_length(path_spec)){ + git_strarray *pathspec = files_to_array(path_spec); + git_strarray_copy(&opts.pathspec, pathspec); + git_strarray_free(pathspec); + } opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_RENAMES_HEAD_TO_INDEX | GIT_STATUS_OPT_SORT_CASE_SENSITIVELY; diff --git a/src/init.c b/src/init.c index 010a31b..52e8cf5 100644 --- a/src/init.c +++ b/src/init.c @@ -69,7 +69,7 @@ extern SEXP R_git_stash_list(SEXP); extern SEXP R_git_stash_pop(SEXP, SEXP); extern SEXP R_git_stash_save(SEXP, SEXP, SEXP, SEXP, SEXP); extern SEXP R_git_stat_files(SEXP, SEXP, SEXP); -extern SEXP R_git_status_list(SEXP, SEXP); +extern SEXP R_git_status_list(SEXP, SEXP, SEXP); extern SEXP R_git_submodule_info(SEXP, SEXP); extern SEXP R_git_submodule_init(SEXP, SEXP, SEXP); extern SEXP R_git_submodule_list(SEXP); @@ -141,7 +141,7 @@ static const R_CallMethodDef CallEntries[] = { {"R_git_stash_pop", (DL_FUNC) &R_git_stash_pop, 2}, {"R_git_stash_save", (DL_FUNC) &R_git_stash_save, 5}, {"R_git_stat_files", (DL_FUNC) &R_git_stat_files, 3}, - {"R_git_status_list", (DL_FUNC) &R_git_status_list, 2}, + {"R_git_status_list", (DL_FUNC) &R_git_status_list, 3}, {"R_git_submodule_info", (DL_FUNC) &R_git_submodule_info, 2}, {"R_git_submodule_init", (DL_FUNC) &R_git_submodule_init, 3}, {"R_git_submodule_list", (DL_FUNC) &R_git_submodule_list, 1},