From 0992c36733f58750da93921041424fd09f0158ed Mon Sep 17 00:00:00 2001 From: diogo464 Date: Tue, 8 Feb 2022 09:19:19 +0000 Subject: snapshot before removal --- dotup_cli/src/utils.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'dotup_cli/src/utils.rs') diff --git a/dotup_cli/src/utils.rs b/dotup_cli/src/utils.rs index be9f3a9..b9a76a7 100644 --- a/dotup_cli/src/utils.rs +++ b/dotup_cli/src/utils.rs @@ -160,3 +160,23 @@ pub fn collect_read_dir_split( .map(|e| e.path()) .partition(|p| p.is_dir())) } + +/// Checks if `path` is inside a git repository +pub fn path_is_in_git_repo(path: &Path) -> bool { + let mut path = if !path.is_absolute() { + dbg!(dotup::utils::weakly_canonical(path)) + } else { + path.to_owned() + }; + let recurse = path.pop(); + path.push(".git"); + if path.is_dir() { + return true; + } + if recurse { + path.pop(); + return path_is_in_git_repo(&path); + } else { + return false; + } +} -- cgit