Play with code to see what's tested, and notice that one part might be missing a test.
Unified · Split
| @@ -86,18 +86,18 @@ pub(crate) mod function { · 85 unmodified lines | |||
| 86 | 86 | ||
| 87 | let max_height = if !ceiling_dirs.is_empty() { | 87 | let max_height = if !ceiling_dirs.is_empty() { |
| 88 | // Ceiling directory discovery requires us to canonicalize the path | 88 | // Ceiling directory discovery requires us to canonicalize the path |
| 89 | is_canonicalized = true; | 89 | // TODO: this works nonetheless. Is a test missing? Or does 'absolutize()' do the job already? |
| 90 | cursor = cursor | 90 | // is_canonicalized = true; |
| 91 | .canonicalize() | 91 | // cursor = cursor |
| 92 | .map_err(|_| Error::InaccessibleDirectory { path: cursor })?; | 92 | // .canonicalize() |
| 93 | Some(find_ceiling_height(&dir, ceiling_dirs)) | 93 | // .map_err(|_| Error::InaccessibleDirectory { path: cursor })?; |
| 94 | find_ceiling_height(&cursor, ceiling_dirs) | ||
| 94 | } else { | 95 | } else { |
| 95 | None | 96 | None |
| 96 | }; | 97 | }; |
| 97 | 98 | ||
| 98 | let mut current_height = 0; | 99 | let mut current_height = 0; |
| 99 | 'outer: loop { | 100 | 'outer: loop { |
| 100 | // If we've reached the ceiling, stop looking. | ||
| 101 | if max_height.map_or(false, |x| current_height > x) { | 101 | if max_height.map_or(false, |x| current_height > x) { |
| 102 | return Err(Error::NoGitRepositoryWithinCeiling { | 102 | return Err(Error::NoGitRepositoryWithinCeiling { |
| 103 | path: dir.into_owned(), | 103 | path: dir.into_owned(), |
| @@ -156,6 +156,17 @@ pub(crate) mod function { · 52 unmodified lines | |||
| 156 | } | 156 | } |
| 157 | 157 | ||
| 158 | fn shorten_path_with_cwd(cursor: PathBuf, cwd: Option<PathBuf>) -> PathBuf { | 158 | fn shorten_path_with_cwd(cursor: PathBuf, cwd: Option<PathBuf>) -> PathBuf { |
| 159 | fn comp_len(c: std::path::Component<'_>) -> usize { | ||
| 160 | use std::path::Component::*; | ||
| 161 | match c { | ||
| 162 | Prefix(p) => p.as_os_str().len(), | ||
| 163 | CurDir => 1, | ||
| 164 | ParentDir => 2, | ||
| 165 | Normal(p) => p.len(), | ||
| 166 | RootDir => 1, | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 159 | if let Some(cwd) = cwd { | 170 | if let Some(cwd) = cwd { |
| 160 | debug_assert_eq!(cursor.file_name().and_then(|f| f.to_str()), Some(".git")); | 171 | debug_assert_eq!(cursor.file_name().and_then(|f| f.to_str()), Some(".git")); |
| 161 | let parent = cursor.parent().expect(".git appended"); | 172 | let parent = cursor.parent().expect(".git appended"); |
| @@ -177,21 +188,10 @@ pub(crate) mod function { · 15 unmodified lines | |||
| 177 | } | 188 | } |
| 178 | } | 189 | } |
| 179 | 190 | ||
| 180 | fn comp_len(c: std::path::Component<'_>) -> usize { | ||
| 181 | use std::path::Component::*; | ||
| 182 | match c { | ||
| 183 | Prefix(p) => p.as_os_str().len(), | ||
| 184 | CurDir => 1, | ||
| 185 | ParentDir => 2, | ||
| 186 | Normal(p) => p.len(), | ||
| 187 | RootDir => 1, | ||
| 188 | } | ||
| 189 | } | ||
| 190 | |||
| 191 | /// Find the number of components parenting the `base_path` before the first directory in `ceiling_dirs`. | 191 | /// Find the number of components parenting the `base_path` before the first directory in `ceiling_dirs`. |
| 192 | /// `base_path` needs to be an absolute path. Non-absolute `ceiling_dirs` are discarded if `base_path` is absolute. | 192 | /// `base_path` needs to be an absolute path. Non-absolute `ceiling_dirs` are discarded if `base_path` is absolute. |
| 193 | // TODO: Handle this in a verbatim-path-prefix-neutral way on Windows (introduced by `path::canonicalize`). | 193 | // TODO: Handle this in a verbatim-path-prefix-neutral way on Windows (introduced by `path::canonicalize`). |
| 194 | fn find_ceiling_height(base_path: &Path, ceiling_dirs: &[PathBuf]) -> usize { | 194 | fn find_ceiling_height(base_path: &Path, ceiling_dirs: &[PathBuf]) -> Option<usize> { |
| 195 | ceiling_dirs | 195 | ceiling_dirs |
| 196 | .iter() | 196 | .iter() |
| 197 | .filter_map(|ceiling_dir| { | 197 | .filter_map(|ceiling_dir| { |
| @@ -201,7 +201,6 @@ pub(crate) mod function { · 3 unmodified lines | |||
| 201 | .map(|path_relative_to_ceiling| path_relative_to_ceiling.components().count()) | 201 | .map(|path_relative_to_ceiling| path_relative_to_ceiling.components().count()) |
| 202 | }) | 202 | }) |
| 203 | .min() | 203 | .min() |
| 204 | .unwrap_or_else(|| base_path.components().count()) | ||
| 205 | } | 204 | } |
| 206 | 205 | ||
| 207 | /// Find the location of the git repository directly in `directory` or in any of its parent directories, and provide | 206 | /// Find the location of the git repository directly in `directory` or in any of its parent directories, and provide |