diff options
Diffstat (limited to 'dotup_cli/src/utils.rs')
| -rw-r--r-- | dotup_cli/src/utils.rs | 20 |
1 files changed, 20 insertions, 0 deletions
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( | |||
| 160 | .map(|e| e.path()) | 160 | .map(|e| e.path()) |
| 161 | .partition(|p| p.is_dir())) | 161 | .partition(|p| p.is_dir())) |
| 162 | } | 162 | } |
| 163 | |||
| 164 | /// Checks if `path` is inside a git repository | ||
| 165 | pub fn path_is_in_git_repo(path: &Path) -> bool { | ||
| 166 | let mut path = if !path.is_absolute() { | ||
| 167 | dbg!(dotup::utils::weakly_canonical(path)) | ||
| 168 | } else { | ||
| 169 | path.to_owned() | ||
| 170 | }; | ||
| 171 | let recurse = path.pop(); | ||
| 172 | path.push(".git"); | ||
| 173 | if path.is_dir() { | ||
| 174 | return true; | ||
| 175 | } | ||
| 176 | if recurse { | ||
| 177 | path.pop(); | ||
| 178 | return path_is_in_git_repo(&path); | ||
| 179 | } else { | ||
| 180 | return false; | ||
| 181 | } | ||
| 182 | } | ||
