Bind Git worktree helpers to a trusted executable

This commit is contained in:
Chris Bookholt
2026-07-01 07:45:11 -07:00
parent ec69e784c2
commit 2ca4f55c0d
9 changed files with 751 additions and 37 deletions
+31
View File
@@ -0,0 +1,31 @@
use std::path::Component;
use std::path::Path;
pub(crate) fn path_is_within(path: &Path, root: &Path) -> bool {
let mut path_components = path.components();
for root_component in root.components() {
let Some(path_component) = path_components.next() else {
return false;
};
if !components_equal(path_component, root_component) {
return false;
}
}
true
}
#[cfg(windows)]
fn components_equal(left: Component<'_>, right: Component<'_>) -> bool {
left.as_os_str()
.to_string_lossy()
.eq_ignore_ascii_case(&right.as_os_str().to_string_lossy())
}
#[cfg(not(windows))]
fn components_equal(left: Component<'_>, right: Component<'_>) -> bool {
left == right
}
#[cfg(test)]
#[path = "git_config_tests.rs"]
mod tests;