Skip to content

feat: Add unset argument to git_config_set() and git_config_global_set() - #273

Merged
jeroen merged 9 commits into
r-lib:mainfrom
iofarm:git-config-unset
May 28, 2026
Merged

feat: Add unset argument to git_config_set() and git_config_global_set()#273
jeroen merged 9 commits into
r-lib:mainfrom
iofarm:git-config-unset

Conversation

@iofarm

@iofarm iofarm commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Proposal to resolve #264 by adding an unset argument to git_config_set() and git_config_global_set(). This would allow removing specific values of multivalued config variables. In conjunction with #261 (merged), this allows full manipulation of multivalued config variables.

Example usage is demonstrated in test-config.R ("multivar, local, custom config roundtrip"). A different interface for unsetting values might be more intuitive - I'm open to suggestions.

In addition: Because libgit2 uses regular expressions to match config values to delete, and it may be linked against different regex engines on different machines, this PR also patches libgit2_config() to report the regex engine in $regex_backend. Because git_libgit2_feature_backend() was only added in libgit2 1.9, this is reported as "unknown" if the libgit2 version is older.

@iofarm
iofarm marked this pull request as ready for review April 21, 2026 17:46

@maelle maelle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

Comment thread R/config.R Outdated
Comment thread R/config.R Outdated
Comment thread R/config.R Outdated
#' expression `value`, equivalent `git config --unset`. If `TRUE` and
#' `value == NULL`, delete all entries for `name`, equivalent to
#' `git config --unset-all`.
git_config_set <- function(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why an argument rather than another function? I was thinking that git_config_set(unset = TRUE) sounds weird.

@iofarm iofarm Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of an oxymoron for sure. I can think of two other interfaces that might be more intuitive:

  1. Adding two new functions, git_config_unset() and git_config_global_unset()
  2. Instead of an unset argument, add an argument named, say, replace which takes a regular expression. Existing values matching replace would be replaced with the new value, which could be set to NULL to remove those existing values. Then instead of git_config_set(value = "ccc", unset = TRUE), one could use git_config_set(value = NULL, replace = "ccc"), which seems more clear.

Personally, I like option 2 better, since it uses the same syntax for deleting config var values as before (i.e., value = NULL; it's more similar to the libgit2 API; and there are fewer functions to keep track of. I'd be happy to amend the PR to take whichever approach you think is best, and address your other comments then too. Thank you for taking the time to review!

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @iofarm!

@jeroen what's your take?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iofarm let's go with option 1 if that's ok with you. Not so close to Git, but maybe more intuitive?

Adding two new functions, git_config_unset() and git_config_global_unset()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, I've added commits to implement option 1

Comment thread R/config.R Outdated
Comment thread R/config.R Outdated
Comment thread src/config.c Outdated
@iofarm
iofarm marked this pull request as draft April 23, 2026 13:26
@iofarm
iofarm marked this pull request as ready for review May 5, 2026 00:47

@maelle maelle left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!!

Comment thread R/config.R Outdated
Comment thread R/config.R Outdated
Comment thread R/config.R
Comment thread tests/testthat/test-config.R Outdated
@jeroen

jeroen commented May 28, 2026

Copy link
Copy Markdown
Member

Thanks you for the contribution.

This implementation is too complex for my taste. Most users don't know what a regex/engine is and just want to unset a single value. Advanced users that do want to unset specific values based on a regex, probably understand that they should use portable regex, not something engine specific. It is out of scope for us to get into technical details of this.

I'll simplify this PR a bit to the essence.

@jeroen
jeroen force-pushed the git-config-unset branch 3 times, most recently from b0168a2 to 1c05177 Compare May 28, 2026 14:35
@jeroen
jeroen force-pushed the git-config-unset branch from 1c05177 to 64a4662 Compare May 28, 2026 14:59
@jeroen
jeroen merged commit 654c236 into r-lib:main May 28, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Interface to set multivalued config variables

3 participants