Skip to content

Commit 2a32c59

Browse files
authored
Merge branch 'main' into aheadbehind
2 parents b2c5300 + a407a09 commit 2a32c59

12 files changed

Lines changed: 104 additions & 31 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ Encoding: UTF-8
3434
Roxygen: list(markdown = TRUE)
3535
SystemRequirements: libgit2 (>= 1.0): libgit2-devel (rpm) or libgit2-dev (deb)
3636
Language: en-US
37-
Config/roxygen2/version: 8.0.0.9000
37+
Config/roxygen2/version: 8.0.0

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ export(git_config_get)
3232
export(git_config_global)
3333
export(git_config_global_get)
3434
export(git_config_global_set)
35+
export(git_config_global_unset)
3536
export(git_config_local_get)
3637
export(git_config_set)
38+
export(git_config_unset)
3739
export(git_conflicts)
3840
export(git_diff)
3941
export(git_diff_patch)
@@ -128,6 +130,7 @@ useDynLib(gert,R_git_commit_log)
128130
useDynLib(gert,R_git_commit_stats)
129131
useDynLib(gert,R_git_config_list)
130132
useDynLib(gert,R_git_config_set)
133+
useDynLib(gert,R_git_config_unset)
131134
useDynLib(gert,R_git_conflict_list)
132135
useDynLib(gert,R_git_create_branch)
133136
useDynLib(gert,R_git_delete_branch)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# gert (development version)
22

3+
- Add `git_config_global_unset()` and `git_config_unset()` (@iofarm, #273)
34
- Add `git_restore()` function (#259)
45
- Add `git_config_get()`, `git_config_local_get()`, and `git_config_global_get()` to retrieve a single named config option, returning `NULL` if unset (#267).
56
- `git_clone()` without a `path` argument now clones into a directory named after the

R/config.R

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#' Get or set Git configuration
22
#'
33
#' @description
4-
#' Get or set Git options, as `git config` does on the command line. **Global**
5-
#' settings affect all of a user's Git operations (`git config --global`),
6-
#' whereas **local** settings are scoped to a specific repository (`git config
7-
#' --local`). When both exist, local options always win.
4+
#' Get, set, or unset Git options, as `git config` does on the command line.
5+
#' **Global** settings affect all of a user's Git operations
6+
#' (`git config --global`), whereas **local** settings are scoped to a specific
7+
#' repository (`git config --local`). When both exist, local options always win.
88
#'
99
#' ```{r echo = FALSE, results = "asis"}
1010
#' dat <- data.frame(
11-
#' local = c("`git_config()`", "`git_config_get()`", "`git_config_local_get()`", "`git_config_set()`"),
12-
#' global = c("`git_config_global()`", "`git_config_get()`", "`git_config_global_get()`", "`git_config_global_set()`"),
13-
#' row.names = c("get all", "get one (local+global)", "get one (local or global only)", "set")
11+
#' local = c("`git_config()`", "`git_config_get()`", "`git_config_local_get()`", "`git_config_set()`", "`git_config_unset()`"),
12+
#' global = c("`git_config_global()`", "`git_config_get()`", "`git_config_global_get()`", "`git_config_global_set()`", "`git_config_global_unset()`"),
13+
#' row.names = c("get all", "get one (local+global)", "get one (local or global only)", "set", "unset")
1414
#' )
1515
#' knitr::kable(dat, col.names = paste0("**", colnames(dat), "**"))
1616
#' ```
@@ -28,6 +28,8 @@
2828
#' * `git_config_set()`, `git_config_global_set()`: The previous value(s) of
2929
#' `name` in local or global config, respectively. If this option was
3030
#' previously unset, returns `NULL`. Returns invisibly.
31+
#' * `git_config_unset()`, `git_config_global_unset()`: The previous value(s) of
32+
#' `name` that were unset. Returns invisibly.
3133
#'
3234
#' @note All entries in the `name` column are automatically normalised to
3335
#' lowercase (see
@@ -146,6 +148,21 @@ git_config_global_set <- function(name, value, add = FALSE) {
146148
}
147149
}
148150

151+
#' @export
152+
#' @rdname git_config
153+
#' @useDynLib gert R_git_config_unset
154+
#' @param pattern optional regular expression, for matching values to unset in
155+
#' case of multiple values
156+
git_config_unset <- function(name, pattern = NULL, repo = '.'){
157+
.Call(R_git_config_unset, git_open(repo), name, pattern)
158+
}
159+
160+
#' @export
161+
#' @rdname git_config
162+
git_config_global_unset <- function(name, pattern = NULL){
163+
.Call(R_git_config_unset, NULL, name, pattern)
164+
}
165+
149166
#' Show libgit2 version and capabilities
150167
#'
151168
#' `libgit2_config()` reveals which version of libgit2 gert is using and which

R/roxygen2.R

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@ git_links <- function() {
44
base_url <- "https://libgit2.org/docs/reference/main/%s/index.html"
55
dat <- as.data.frame(
66
rbind(
7-
c("branch", sprintf(base_url, "branch")),
7+
c("branch", sprintf(base_url, "branch")),
88
c("cherrypick", sprintf(base_url, "cherrypick")),
9-
c("checkout", sprintf(base_url, "checkout")),
10-
c("clone", sprintf(base_url, "clone")),
11-
c("commit", sprintf(base_url, "commit")),
12-
c("config", sprintf(base_url, "config")),
13-
c("diff", sprintf(base_url, "diff")),
14-
c("graph", sprintf(base_url, "graph")),
15-
c("ignore", sprintf(base_url, "ignore")),
16-
c("index", sprintf(base_url, "index")),
17-
c("merge", sprintf(base_url, "merge")),
18-
c("rebase", sprintf(base_url, "rebase")),
19-
c("remote", sprintf(base_url, "remote")),
9+
c("checkout", sprintf(base_url, "checkout")),
10+
c("clone", sprintf(base_url, "clone")),
11+
c("commit", sprintf(base_url, "commit")),
12+
c("config", sprintf(base_url, "config")),
13+
c("diff", sprintf(base_url, "diff")),
14+
c("graph", sprintf(base_url, "graph")),
15+
c("ignore", sprintf(base_url, "ignore")),
16+
c("index", sprintf(base_url, "index")),
17+
c("merge", sprintf(base_url, "merge")),
18+
c("rebase", sprintf(base_url, "rebase")),
19+
c("remote", sprintf(base_url, "remote")),
2020
c("repository", sprintf(base_url, "repository")),
21-
c("reset", sprintf(base_url, "reset")),
22-
c("revert", sprintf(base_url, "revert")),
23-
c("signature", sprintf(base_url, "signature")),
24-
c("stash", sprintf(base_url, "stash")),
25-
c("status", sprintf(base_url, "status")),
26-
c("tag", sprintf(base_url, "tag")),
27-
c("worktree", sprintf(base_url, "worktree"))
21+
c("reset", sprintf(base_url, "reset")),
22+
c("revert", sprintf(base_url, "revert")),
23+
c("signature", sprintf(base_url, "signature")),
24+
c("stash", sprintf(base_url, "stash")),
25+
c("status", sprintf(base_url, "status")),
26+
c("submodule", sprintf(base_url, "submodule")),
27+
c("tag", sprintf(base_url, "tag")),
28+
c("worktree", sprintf(base_url, "worktree"))
2829
),
2930
stringsAsFactors = FALSE
3031
)

R/submodules.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#' @rdname git_submodule
88
#' @inheritParams git_open
99
#' @useDynLib gert R_git_submodule_list
10+
#' @git submodule
1011
git_submodule_list <- function(repo = '.') {
1112
repo <- git_open(repo)
1213
.Call(R_git_submodule_list, repo)

man/git_config.Rd

Lines changed: 16 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git_submodule.Rd

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,21 @@ SEXP R_git_config_set(SEXP ptr, SEXP name, SEXP value, SEXP add){
104104
git_config_free(cfg);
105105
return R_NilValue;
106106
}
107+
108+
SEXP R_git_config_unset(SEXP ptr, SEXP name, SEXP pattern){
109+
git_config *cfg = NULL;
110+
const char *cname = CHAR(STRING_ELT(name, 0));
111+
if(Rf_isNull(ptr)) {
112+
bail_if(git_config_open_default(&cfg), "git_config_open_default");
113+
} else {
114+
bail_if(git_repository_config(&cfg, get_git_repository(ptr)),"git_repository_config");
115+
}
116+
if(Rf_length(pattern)){
117+
const char *cpattern = CHAR(STRING_ELT(pattern, 0));
118+
bail_if(git_config_delete_multivar(cfg, cname, cpattern), "git_config_delete_multivar");
119+
} else {
120+
bail_if(git_config_delete_entry(cfg, cname), "git_config_delete_entry");
121+
}
122+
git_config_free(cfg);
123+
return R_NilValue;
124+
}

src/init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ extern SEXP R_git_commit_log(SEXP, SEXP, SEXP, SEXP, SEXP);
3131
extern SEXP R_git_commit_stats(SEXP, SEXP);
3232
extern SEXP R_git_config_list(SEXP);
3333
extern SEXP R_git_config_set(SEXP, SEXP, SEXP, SEXP);
34+
extern SEXP R_git_config_unset(SEXP, SEXP, SEXP);
3435
extern SEXP R_git_conflict_list(SEXP);
3536
extern SEXP R_git_create_branch(SEXP, SEXP, SEXP, SEXP, SEXP);
3637
extern SEXP R_git_delete_branch(SEXP, SEXP);
@@ -116,6 +117,7 @@ static const R_CallMethodDef CallEntries[] = {
116117
{"R_git_commit_stats", (DL_FUNC) &R_git_commit_stats, 2},
117118
{"R_git_config_list", (DL_FUNC) &R_git_config_list, 1},
118119
{"R_git_config_set", (DL_FUNC) &R_git_config_set, 4},
120+
{"R_git_config_unset", (DL_FUNC) &R_git_config_unset, 3},
119121
{"R_git_conflict_list", (DL_FUNC) &R_git_conflict_list, 1},
120122
{"R_git_create_branch", (DL_FUNC) &R_git_create_branch, 5},
121123
{"R_git_delete_branch", (DL_FUNC) &R_git_delete_branch, 2},

0 commit comments

Comments
 (0)