Skip to content

Commit

Permalink
git_status() gains parameter pathspec
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroen committed May 25, 2022
1 parent 553605e commit abc3d4d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 4 additions & 2 deletions R/commit.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}

Expand Down
4 changes: 3 additions & 1 deletion man/git_commit.Rd

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

7 changes: 6 additions & 1 deletion src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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},
Expand Down

0 comments on commit abc3d4d

Please sign in to comment.