Skip to content

Commit

Permalink
tests: force gitoxide to not load config nor use "main" as default br…
Browse files Browse the repository at this point in the history
…anch

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
  • Loading branch information
yuja committed Oct 31, 2023
1 parent aa4d385 commit 58e6a2d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/testutils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 58e6a2d

Please sign in to comment.