Expose git_repository_set_config function#1208
Conversation
| /// | ||
| /// This configuration file will be used for all configuration queries involving this | ||
| /// repository. | ||
| pub fn set_config(&self, config: &Config) -> Result<(), Error> { |
There was a problem hiding this comment.
Yeah, this is useful for complete config isolation, but for your specific (the diff.noPrefix issue), shouldn't repo.config()?.set_bool("diff.noPrefix", false) help with that? That would override the global setting without removing all other inherited config.
Before merging, could you clarify why that didn't work? If it is a separate bug we might want to fix it.
There was a problem hiding this comment.
It works but it's very specific to running the software on my machine.
Rather than relying on Git's defaults, I have to unset everything that may be different in a particular environment like diff.context, diff.mnemonicPrefix etc.
So, yes, it works but I would prefer the ability to not load any configuration.
There was a problem hiding this comment.
Yeah that makes sense. I was just wondering if you missed those API or there were bugs. Thanks for the clarification!
On my local machine, I set
diff.noPrefixto true in my global Git configuration.This can interfere with software that uses git2. For instance, running
cargo testin this repository causes thediff::tests::format_email_simpletest to fail as it's expecting lines with the "a/" and "b/" prefixes:git2-rs/src/diff.rs
Lines 1694 to 1695 in 62e83e2
There's a couple of workarounds available:
I can prevent the global configuration from loading by using
git2::opts::set_search_pathand pointing it at a non-existent path. The downside is that it is itself a global option.I can (probably) use
git2::DiffOptionsto undo my local environment. This is a bit verbose but a great solution in many cases to ensure predictabilityI'm proposing exposing the
git_repository_set_configfunction to allow setting configuration for a particular repository instance. This gives the user full control of which configuration to load.