tests: force gitoxide to not load config nor use "main" as default branch

AFAIK, there's no global config state for gitoxide. We can use
Config::isolated() in tests, but GitBackend should load config files in a
normal way.

https://docs.rs/gix/0.55.2/gix/open/permissions/struct.Config.html#method.isolated
https://docs.rs/gix/0.55.2/gix/init/constant.DEFAULT_BRANCH_NAME.html
This commit is contained in:
Yuya Nishihara 2023-10-31 18:45:59 +09:00
parent f5a61dc2b7
commit 9a86b77e38

View file

@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
use std::env;
use std::fs::{self, OpenOptions};
use std::io::{Read, Write};
use std::path::{Path, PathBuf};
@ -58,6 +59,16 @@ pub fn hermetic_libgit2() {
git2::opts::set_search_path(git2::ConfigLevel::XDG, "").unwrap();
git2::opts::set_search_path(git2::ConfigLevel::ProgramData, "").unwrap();
});
// Prevent GitBackend from loading user and system configurations. For
// gitoxide API use in tests, Config::isolated() is probably better.
env::set_var("GIT_CONFIG_SYSTEM", "/dev/null");
env::set_var("GIT_CONFIG_GLOBAL", "/dev/null");
// gitoxide uses "main" as the default branch name, whereas git and libgit2
// uses "master".
env::set_var("GIT_CONFIG_KEY_0", "init.defaultBranch");
env::set_var("GIT_CONFIG_VALUE_0", "master");
env::set_var("GIT_CONFIG_COUNT", "1");
}
pub fn new_temp_dir() -> TempDir {