Skip to content

Commit

Permalink
add test to assure hasconfig is working on gix level as well.
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 7, 2024
1 parent 92558a1 commit d51aec9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 26 deletions.
Binary file modified gix/tests/fixtures/generated-archives/make_config_repos.tar
Binary file not shown.
17 changes: 17 additions & 0 deletions gix/tests/fixtures/make_config_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,20 @@ git init ssl-no-verify-enabled
git config http.sslVerify true
git config gitoxide.http.sslNoVerify true
)


git init --bare with-hasconfig
(cd with-hasconfig
cat >include-with-url <<-\EOF
[user]
name = "works"
email = "works@example.com"
EOF
cat >system.config <<-\EOF
[includeIf "hasconfig:remote.*.url:anyurl"]
path = "include-with-url"
EOF

echo $'[remote "any"]\n\turl=anyurl' >>config

)
61 changes: 35 additions & 26 deletions gix/tests/gix/repository/config/identity.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
use std::path::Path;

use crate::named_repo;
use crate::util::named_subrepo_opts;
use gix_sec::Permission;
use gix_testtools::Env;
use serial_test::serial;
use std::path::Path;

use crate::named_repo;
#[test]
#[serial]
fn author_included_by_hasconfig() -> crate::Result {
let repo = named_subrepo_opts("make_config_repos.sh", "with-hasconfig", gix::open::Options::isolated())?;
let _env = Env::new().set(
"GIT_CONFIG_SYSTEM",
repo.git_dir().join("system.config").display().to_string(),
);
let repo = gix::open_opts(repo.git_dir(), allow_system_options(repo.open_options().clone()))?;
let author = repo.author().expect("set in system config via include")?;
assert_eq!(author.name, "works");
assert_eq!(author.email, "works@example.com");
Ok(())
}

#[test]
#[serial]
Expand All @@ -29,17 +43,7 @@ fn author_and_committer_and_fallback() -> crate::Result {
.set("GIT_CONFIG_VALUE_0", work_dir.join("c.config").display().to_string());
let repo = gix::open_opts(
repo.git_dir(),
repo.open_options()
.clone()
.with(trust)
.permissions(gix::open::Permissions {
env: gix::open::permissions::Environment {
xdg_config_home: Permission::Deny,
home: Permission::Deny,
..gix::open::permissions::Environment::all()
},
..Default::default()
}),
allow_system_options(repo.open_options().clone().with(trust)),
)?;

assert_eq!(
Expand Down Expand Up @@ -147,18 +151,12 @@ fn author_from_different_config_sections() -> crate::Result {

let repo = gix::open_opts(
repo.git_dir(),
repo.open_options()
.clone()
.config_overrides(None::<&str>)
.with(gix_sec::Trust::Full)
.permissions(gix::open::Permissions {
env: gix::open::permissions::Environment {
xdg_config_home: Permission::Deny,
home: Permission::Deny,
..gix::open::permissions::Environment::all()
},
..Default::default()
}),
allow_system_options(
repo.open_options()
.clone()
.config_overrides(None::<&str>)
.with(gix_sec::Trust::Full),
),
)?;

assert_eq!(
Expand Down Expand Up @@ -191,3 +189,14 @@ fn author_from_different_config_sections() -> crate::Result {
);
Ok(())
}

fn allow_system_options(opts: gix::open::Options) -> gix::open::Options {
opts.permissions(gix::open::Permissions {
env: gix::open::permissions::Environment {
xdg_config_home: Permission::Deny,
home: Permission::Deny,
..gix::open::permissions::Environment::all()
},
..Default::default()
})
}

0 comments on commit d51aec9

Please sign in to comment.