The upwards search for the repository directory takes a directory as input and then walks through the parents. It turns out that it was broken when the repository was the same as the working directory. The code checked when the directory components had been stripped to "", in case the directory was replaced with `cwd.parent()`, so the loop missed to check `cwd` itself. If the input directory was "./something", then "." was checked which then succeeded.
Unified · Split
| @@ -168,7 +168,7 @@ pub(crate) mod function { · 167 unmodified lines | |||
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | } | 170 | } |
| 171 | if cursor.parent().is_some_and(|p| p.as_os_str().is_empty()) { | 171 | if cursor.as_os_str().is_empty() || cursor.as_os_str() == OsStr::new(".") { |
| 172 | cursor = cwd.to_path_buf(); | 172 | cursor = cwd.to_path_buf(); |
| 173 | dir_made_absolute = true; | 173 | dir_made_absolute = true; |
| 174 | } | 174 | } |
| @@ -3,6 +3,23 @@ use std::path::{Path, PathBuf}; · 2 unmodified lines | |||
| 3 | use gix_discover::upwards::Options; | 3 | use gix_discover::upwards::Options; |
| 4 | use serial_test::serial; | 4 | use serial_test::serial; |
| 5 | 5 | ||
| 6 | #[test] | ||
| 7 | #[serial] | ||
| 8 | fn in_cwd_upwards_from_nested_dir() -> gix_testtools::Result { | ||
| 9 | let repo = gix_testtools::scripted_fixture_read_only("make_basic_repo.sh")?; | ||
| 10 | |||
| 11 | let _keep = gix_testtools::set_current_dir(repo)?; | ||
| 12 | for dir in ["subdir", "some/very/deeply/nested/subdir"] { | ||
| 13 | let (repo_path, _trust) = gix_discover::upwards(Path::new(dir))?; | ||
| 14 | assert_eq!( | ||
| 15 | repo_path.kind(), | ||
| 16 | gix_discover::repository::Kind::WorkTree { linked_git_dir: None }, | ||
| 17 | ); | ||
| 18 | assert_eq!(repo_path.as_ref(), Path::new(".")); | ||
| 19 | } | ||
| 20 | Ok(()) | ||
| 21 | } | ||
| 22 | |||
| 6 | #[test] | 23 | #[test] |
| 7 | #[serial] | 24 | #[serial] |
| 8 | fn upwards_bare_repo_with_index() -> gix_testtools::Result { | 25 | fn upwards_bare_repo_with_index() -> gix_testtools::Result { |
| @@ -48,7 +65,7 @@ fn in_cwd_upwards_nonbare_repo_without_index() -> gix_testtools::Result { · 39 unmodified lines | |||
| 48 | fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Result { | 65 | fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Result { |
| 49 | let repo = gix_testtools::scripted_fixture_read_only("make_basic_repo.sh")?; | 66 | let repo = gix_testtools::scripted_fixture_read_only("make_basic_repo.sh")?; |
| 50 | 67 | ||
| 51 | let _keep = gix_testtools::set_current_dir(repo.join("subdir"))?; | 68 | let _keep = gix_testtools::set_current_dir(repo.join("some"))?; |
| 52 | let cwd = std::env::current_dir()?; | 69 | let cwd = std::env::current_dir()?; |
| 53 | 70 | ||
| 54 | for (search_dir, ceiling_dir_component) in [ | 71 | for (search_dir, ceiling_dir_component) in [ |
| @@ -56,6 +73,8 @@ fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Re · 1 unmodified line | |||
| 56 | (".", "./.."), | 73 | (".", "./.."), |
| 57 | ("./.", "./.."), | 74 | ("./.", "./.."), |
| 58 | (".", "./does-not-exist/../.."), | 75 | (".", "./does-not-exist/../.."), |
| 76 | ("./././very/deeply/nested/subdir", ".."), | ||
| 77 | ("very/deeply/nested/subdir", ".."), | ||
| 59 | ] { | 78 | ] { |
| 60 | let ceiling_dir = cwd.join(ceiling_dir_component); | 79 | let ceiling_dir = cwd.join(ceiling_dir_component); |
| 61 | let (repo_path, _trust) = gix_discover::upwards_opts( | 80 | let (repo_path, _trust) = gix_discover::upwards_opts( |
| @@ -91,7 +110,16 @@ fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Re · 29 unmodified lines | |||
| 91 | ) | 110 | ) |
| 92 | .unwrap_err(); | 111 | .unwrap_err(); |
| 93 | 112 | ||
| 94 | assert!(matches!(err, gix_discover::upwards::Error::NoMatchingCeilingDir)); | 113 | if Path::new(search_dir).parent() == Some(Path::new(".")) |
| 114 | || Path::new(search_dir).parent() == Some(Path::new("")) | ||
| 115 | { | ||
| 116 | assert!(matches!(err, gix_discover::upwards::Error::NoMatchingCeilingDir)); | ||
| 117 | } else { | ||
| 118 | assert!(matches!( | ||
| 119 | err, | ||
| 120 | gix_discover::upwards::Error::NoGitRepositoryWithinCeiling { .. } | ||
| 121 | )); | ||
| 122 | } | ||
| 95 | } | 123 | } |
| 96 | 124 | ||
| 97 | Ok(()) | 125 | Ok(()) |