Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1084,6 +1084,17 @@ impl Repository {
}
}

/// Set the configuration file for this repository.
///
/// This configuration file will be used for all configuration queries involving this
/// repository.
pub fn set_config(&self, config: &Config) -> Result<(), Error> {
Copy link
Member

Choose a reason for hiding this comment

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

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah that makes sense. I was just wondering if you missed those API or there were bugs. Thanks for the clarification!

unsafe {
try_call!(raw::git_repository_set_config(self.raw(), config.raw()));
}
Ok(())
}

/// Get the value of a git attribute for a path as a string.
///
/// This function will return a special string if the attribute is set to a special value.
Expand Down Expand Up @@ -3539,7 +3550,7 @@ mod tests {
use crate::ObjectFormat;
use crate::{CherrypickOptions, MergeFileOptions};
use crate::{
ObjectType, Oid, Repository, ResetType, Signature, SubmoduleIgnore, SubmoduleUpdate,
Config, ObjectType, Oid, Repository, ResetType, Signature, SubmoduleIgnore, SubmoduleUpdate,
};

use std::ffi::OsStr;
Expand Down Expand Up @@ -4312,6 +4323,25 @@ bar
assert!(!config.get_bool("commit.gpgsign").unwrap());
}

#[test]
fn smoke_set_config() {
let (td, repo) = crate::test::repo_init();

let config = {
let config_file = td.path().join(".gitconfig");

t!(fs::write(&config_file, "[diff]\nnoPrefix = true"));

t!(Config::open(&config_file))
};

repo.set_config(&config).unwrap();

let config = repo.config().unwrap();

assert!(config.get_bool("diff.noPrefix").unwrap());
}

#[test]
fn smoke_merge_analysis_for_ref() -> Result<(), crate::Error> {
let (_td, repo) = graph_repo_init();
Expand Down