+64
-31
lines changedFilter options
+64
-31
lines changed Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
1
1
#![allow(clippy::result_large_err)]
2
+
use gix_config::file::Metadata;
3
+
use gix_features::threading::OwnShared;
4
+
use gix_object::bstr::ByteSlice;
5
+
use gix_path::RelativePath;
6
+
use std::path::Path;
2
7
use std::{
3
8
borrow::Cow,
4
9
collections::{btree_map::Entry, BTreeMap},
5
10
ffi::OsStr,
6
11
path::PathBuf,
7
12
};
8
13
9
-
use gix_features::threading::OwnShared;
10
-
use gix_object::bstr::ByteSlice;
11
-
use gix_path::RelativePath;
12
-
13
14
use super::{Error, Options};
14
15
use crate::{
15
16
bstr::BString,
@@ -257,26 +258,32 @@ impl ThreadSafeRepository {
257
258
// core.worktree might be used to overwrite the worktree directory
258
259
if !config.is_bare {
259
260
let mut key_source = None;
261
+
fn assure_config_is_from_current_repo(
262
+
section: &gix_config::file::Metadata,
263
+
git_dir: &Path,
264
+
current_dir: &Path,
265
+
filter_config_section: &mut fn(&Metadata) -> bool,
266
+
) -> bool {
267
+
if !filter_config_section(section) {
268
+
return false;
269
+
}
270
+
// ignore worktree settings that aren't from our repository. This can happen
271
+
// with worktrees of submodules for instance.
272
+
section
273
+
.path
274
+
.as_deref()
275
+
.and_then(|p| gix_path::normalize(p.into(), current_dir))
276
+
.is_some_and(|config_path| config_path.starts_with(git_dir))
277
+
}
260
278
let worktree_path = config
261
279
.resolved
262
-
.path_filter(Core::WORKTREE, {
263
-
|section| {
264
-
if !filter_config_section(section) {
265
-
return false;
266
-
}
267
-
// ignore worktree settings that aren't from our repository. This can happen
268
-
// with worktrees of submodules for instance.
269
-
let is_config_in_our_repo = section
270
-
.path
271
-
.as_deref()
272
-
.and_then(|p| gix_path::normalize(p.into(), current_dir))
273
-
.is_some_and(|config_path| config_path.starts_with(&git_dir));
274
-
if !is_config_in_our_repo {
275
-
return false;
276
-
}
280
+
.path_filter(Core::WORKTREE, |section| {
281
+
let res =
282
+
assure_config_is_from_current_repo(section, &git_dir, current_dir, &mut filter_config_section);
283
+
if res {
277
284
key_source = Some(section.source);
278
-
true
279
285
}
286
+
res
280
287
})
281
288
.zip(key_source);
282
289
if let Some((wt, key_source)) = worktree_path {
@@ -302,7 +309,9 @@ impl ThreadSafeRepository {
302
309
} else if !config.lenient_config
303
310
&& config
304
311
.resolved
305
-
.boolean_filter(Core::WORKTREE, &mut filter_config_section)
312
+
.boolean_filter(Core::WORKTREE, |section| {
313
+
assure_config_is_from_current_repo(section, &git_dir, current_dir, &mut filter_config_section)
314
+
})
306
315
.is_some()
307
316
{
308
317
return Err(Error::from(config::Error::ConfigTypedString(
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
1
1
#![allow(clippy::result_large_err)]
2
+
3
+
use gix::open::Permissions;
4
+
use gix::{Repository, ThreadSafeRepository};
5
+
use gix_sec::Permission;
6
+
use serial_test::serial;
7
+
8
+
pub fn named_subrepo_opts(
9
+
fixture: &str,
10
+
name: &str,
11
+
opts: gix::open::Options,
12
+
) -> std::result::Result<Repository, gix::open::Error> {
13
+
let repo_path = gix_testtools::scripted_fixture_read_only(fixture).unwrap().join(name);
14
+
Ok(ThreadSafeRepository::open_opts(repo_path, opts)?.to_thread_local())
15
+
}
16
+
2
17
mod with_overrides {
3
18
use std::borrow::Cow;
4
19
5
-
use gix::{Repository, ThreadSafeRepository};
20
+
use crate::named_subrepo_opts;
6
21
use gix_object::bstr::BStr;
7
22
use gix_sec::Permission;
8
23
use gix_testtools::Env;
9
24
use serial_test::serial;
10
25
11
-
pub fn named_subrepo_opts(
12
-
fixture: &str,
13
-
name: &str,
14
-
opts: gix::open::Options,
15
-
) -> std::result::Result<Repository, gix::open::Error> {
16
-
let repo_path = gix_testtools::scripted_fixture_read_only(fixture).unwrap().join(name);
17
-
Ok(ThreadSafeRepository::open_opts(repo_path, opts)?.to_thread_local())
18
-
}
19
-
20
26
#[test]
21
27
#[serial]
22
28
fn order_from_api_and_cli_and_environment() -> gix_testtools::Result {
@@ -264,3 +270,21 @@ mod with_overrides {
264
270
Cow::Borrowed(s.into())
265
271
}
266
272
}
273
+
274
+
#[test]
275
+
#[serial]
276
+
fn git_worktree_and_strict_config() -> gix_testtools::Result {
277
+
let _restore_env_on_drop = gix_testtools::Env::new().set("GIT_WORK_TREE", ".");
278
+
let _repo = named_subrepo_opts(
279
+
"make_empty_repo.sh",
280
+
"",
281
+
gix::open::Options::isolated()
282
+
.permissions({
283
+
let mut perm = Permissions::isolated();
284
+
perm.env.git_prefix = Permission::Allow;
285
+
perm
286
+
})
287
+
.strict_config(true),
288
+
)?;
289
+
Ok(())
290
+
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4