History

git-discover: avoid shortening absolute paths

David Knaack committed 4 years ago

Commit 61065211 parent b2f56d52 files · +16 −1Browse files

Unified · Split

2 files
  1. git-discover/src/upwards.rs +1 −1
  2. git-discover/tests/upwards/mod.rs +15 −0
git-discover/src/upwards.rs+1−1
@@ -157,7 +157,7 @@ pub(crate) mod function { · 156 unmodified lines
157157 match filter_by_trust(&cursor)? {
158158 Some(trust) => {
159159 // TODO: test this more, it definitely doesn't find the shortest path to a directory
160− let path = if dir_made_absolute {
160+ let path = if dir_made_absolute && !directory.as_ref().is_absolute() {
161161 shorten_path_with_cwd(cursor, cwd)
162162 } else {
163163 cursor
git-discover/tests/upwards/mod.rs+15−0
@@ -259,6 +259,21 @@ fn cross_fs() -> crate::Result { · 258 unmodified lines
259259 Ok(())
260260 }
261261
262+#[test]
263+fn do_not_shorten_absolute_paths() -> crate::Result {
264+ let top_level_repo = repo_path()?.canonicalize().expect("repo path exists");
265+ let (repo_path, _trust) = git_discover::upwards(top_level_repo).expect("we can discover the repo");
266+
267+ match repo_path {
268+ git_discover::repository::Path::WorkTree(work_dir) => {
269+ assert!(work_dir.is_absolute());
270+ }
271+ _ => panic!("expected worktree path"),
272+ };
273+
274+ Ok(())
275+}
276+
262277 fn repo_path() -> crate::Result<PathBuf> {
263278 git_testtools::scripted_fixture_repo_read_only("make_basic_repo.sh")
264279 }