Skip to content

Commit 886d6b5

Browse files
committed
feat: checkout respects options for core.protectHFS and core.protectNTFS.
This also adds `gitoxide.core.protectWindows` as a way to enforce additional restrictions that are usually only available on Windows. Note that `core.protectNFS` is always enabled by default, just like [it is in Git](git/git@9102f95).
1 parent 1ca6a3c commit 886d6b5

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

gix/src/config/cache/access.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,35 @@ impl Cache {
271271
})
272272
}
273273

274+
fn protect_options(&self) -> Result<gix_validate::path::component::Options, config::boolean::Error> {
275+
const IS_WINDOWS: bool = cfg!(windows);
276+
const IS_MACOS: bool = cfg!(target_os = "macos");
277+
const ALWAYS_ON_FOR_SAFETY: bool = true;
278+
Ok(gix_validate::path::component::Options {
279+
protect_windows: config::tree::gitoxide::Core::PROTECT_WINDOWS
280+
.enrich_error(
281+
self.resolved
282+
.boolean("gitoxide", Some("core".into()), "protectWindows")
283+
.unwrap_or(Ok(IS_WINDOWS)),
284+
)
285+
.with_lenient_default_value(self.lenient_config, IS_WINDOWS)?,
286+
protect_hfs: config::tree::Core::PROTECT_HFS
287+
.enrich_error(
288+
self.resolved
289+
.boolean("core", None, "protectHFS")
290+
.unwrap_or(Ok(IS_MACOS)),
291+
)
292+
.with_lenient_default_value(self.lenient_config, IS_MACOS)?,
293+
protect_ntfs: config::tree::Core::PROTECT_NTFS
294+
.enrich_error(
295+
self.resolved
296+
.boolean("core", None, "protectNTFS")
297+
.unwrap_or(Ok(ALWAYS_ON_FOR_SAFETY)),
298+
)
299+
.with_lenient_default_value(self.lenient_config, ALWAYS_ON_FOR_SAFETY)?,
300+
})
301+
}
302+
274303
/// Collect everything needed to checkout files into a worktree.
275304
/// Note that some of the options being returned will be defaulted so safe settings, the caller might have to override them
276305
/// depending on the use-case.
@@ -310,7 +339,7 @@ impl Cache {
310339
};
311340
Ok(gix_worktree_state::checkout::Options {
312341
filter_process_delay,
313-
validate: Default::default(), // TODO: derive these from configuration
342+
validate: self.protect_options()?,
314343
filters,
315344
attributes: self
316345
.assemble_attribute_globals(git_dir, attributes_source, self.attributes)?

gix/src/config/tree/sections/core.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ impl Core {
4444
/// Needs application to use [`env::args_os`][crate::env::args_os()] to conform all input paths before they are used.
4545
pub const PRECOMPOSE_UNICODE: keys::Boolean = keys::Boolean::new_boolean("precomposeUnicode", &config::Tree::CORE)
4646
.with_note("application needs to conform all program input by using gix::env::args_os()");
47+
/// The `core.protectHFS` key.
48+
pub const PROTECT_HFS: keys::Boolean = keys::Boolean::new_boolean("protectHFS", &config::Tree::CORE);
49+
/// The `core.protectNTFS` key.
50+
pub const PROTECT_NTFS: keys::Boolean = keys::Boolean::new_boolean("protectNTFS", &config::Tree::CORE);
4751
/// The `core.repositoryFormatVersion` key.
4852
pub const REPOSITORY_FORMAT_VERSION: keys::UnsignedInteger =
4953
keys::UnsignedInteger::new_unsigned_integer("repositoryFormatVersion", &config::Tree::CORE);
@@ -116,6 +120,8 @@ impl Section for Core {
116120
&Self::SYMLINKS,
117121
&Self::TRUST_C_TIME,
118122
&Self::WORKTREE,
123+
&Self::PROTECT_HFS,
124+
&Self::PROTECT_NTFS,
119125
&Self::ASKPASS,
120126
&Self::EXCLUDES_FILE,
121127
&Self::ATTRIBUTES_FILE,

gix/src/config/tree/sections/gitoxide.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ mod subsections {
103103
pub const USE_STDEV: keys::Boolean = keys::Boolean::new_boolean("useStdev", &Gitoxide::CORE)
104104
.with_note("A runtime version of the USE_STDEV build flag.");
105105

106+
/// The `gitoxide.core.protectWindows` key.
107+
pub const PROTECT_WINDOWS: keys::Boolean = keys::Boolean::new_boolean("protectWindows", &Gitoxide::CORE)
108+
.with_note("enable protections that are enabled by default on Windows");
109+
106110
/// The `gitoxide.core.shallowFile` key.
107111
pub const SHALLOW_FILE: keys::Path = keys::Path::new_path("shallowFile", &Gitoxide::CORE)
108112
.with_environment_override("GIT_SHALLOW_FILE")
@@ -142,6 +146,7 @@ mod subsections {
142146
&Self::USE_NSEC,
143147
&Self::USE_STDEV,
144148
&Self::SHALLOW_FILE,
149+
&Self::PROTECT_WINDOWS,
145150
&Self::FILTER_PROCESS_DELAY,
146151
&Self::EXTERNAL_COMMAND_STDERR,
147152
&Self::REFS_NAMESPACE,

src/plumbing/progress.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,6 @@ static GIT_CONFIG: &[Record] = &[
9494
config: "core.loosecompression",
9595
usage: Planned("")
9696
},
97-
Record {
98-
config: "core.protectHFS",
99-
usage: Planned("relevant for checkout on MacOS, and possibly on networked drives")
100-
},
101-
Record {
102-
config: "core.protectNTFS",
103-
usage: Planned("relevant for checkout on Windows, and possibly networked drives")
104-
},
10597
Record {
10698
config: "core.sparseCheckout",
10799
usage: Planned("we want to support huge repos and be the fastest in doing so")

0 commit comments

Comments
 (0)