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 | 87 | let max_height = if !ceiling_dirs.is_empty() { |
| 88 | 88 | // Ceiling directory discovery requires us to canonicalize the path |
| 89 | − is_canonicalized = true; | |
| 90 | − cursor = cursor | |
| 91 | − .canonicalize() | |
| 92 | − .map_err(|_| Error::InaccessibleDirectory { path: cursor })?; | |
| 93 | − Some(find_ceiling_height(&dir, ceiling_dirs)) | |
| 89 | + // TODO: this works nonetheless. Is a test missing? Or does 'absolutize()' do the job already? | |
| 90 | + // is_canonicalized = true; | |
| 91 | + // cursor = cursor | |
| 92 | + // .canonicalize() | |
| 93 | + // .map_err(|_| Error::InaccessibleDirectory { path: cursor })?; | |
| 94 | + find_ceiling_height(&cursor, ceiling_dirs) | |
| 94 | 95 | } else { |
| 95 | 96 | None |
| 96 | 97 | }; |
| 97 | 98 | |
| 98 | 99 | let mut current_height = 0; |
| 99 | 100 | 'outer: loop { |
| 100 | − // If we've reached the ceiling, stop looking. | |
| 101 | 101 | if max_height.map_or(false, |x| current_height > x) { |
| 102 | 102 | return Err(Error::NoGitRepositoryWithinCeiling { |
| 103 | 103 | path: dir.into_owned(), |
| @@ -156,6 +156,17 @@ pub(crate) mod function { · 52 unmodified lines | ||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 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 | 170 | if let Some(cwd) = cwd { |
| 160 | 171 | debug_assert_eq!(cursor.file_name().and_then(|f| f.to_str()), Some(".git")); |
| 161 | 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 | 191 | /// Find the number of components parenting the `base_path` before the first directory in `ceiling_dirs`. |
| 192 | 192 | /// `base_path` needs to be an absolute path. Non-absolute `ceiling_dirs` are discarded if `base_path` is absolute. |
| 193 | 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 | 195 | ceiling_dirs |
| 196 | 196 | .iter() |
| 197 | 197 | .filter_map(|ceiling_dir| { |
| @@ -201,7 +201,6 @@ pub(crate) mod function { · 3 unmodified lines | ||
| 201 | 201 | .map(|path_relative_to_ceiling| path_relative_to_ceiling.components().count()) |
| 202 | 202 | }) |
| 203 | 203 | .min() |
| 204 | − .unwrap_or_else(|| base_path.components().count()) | |
| 205 | 204 | } |
| 206 | 205 | |
| 207 | 206 | /// Find the location of the git repository directly in `directory` or in any of its parent directories, and provide |