History

Fix a test that assumed a non-worktree parent repo. (#544)

Ideally, it would be perfectly isolated, but for now it's easiest to just loosen the assumptions and hope that this is it, forver, and that the actual requirement is still validated from time to time.

Sebastian Thiel committed 4 years ago

Commit 19082291 parent 6c9d18b1 file · +22 −7Browse files

Unified · Split

git-discover/tests/upwards/mod.rs+22−7
@@ -82,17 +82,32 @@ fn from_dir_with_dot_dot() -> crate::Result { · 81 unmodified lines
8282 let working_dir = repo_path()?;
8383 let dir = working_dir.join("some/very/deeply/nested/subdir/../../../../../..");
8484 let (path, trust) = git_discover::upwards(&dir)?;
85− assert_eq!(path.kind(), Kind::WorkTree { linked_git_dir: None });
86− assert_eq!(
87− path.as_ref(),
88− std::path::Path::new(".."),
89− "there is only the minimal amount of relative path components to see this worktree"
90− );
9185 assert_ne!(
9286 path.as_ref().canonicalize()?,
9387 working_dir.canonicalize()?,
94− "a relative path that climbs above the test repo should yield the gitoxide repo"
88+ "a relative path that climbs above the test repo should yield the parent-gitoxide repo"
9589 );
90+ // If the parent repo is actually a main worktree, we can make more assertions. If it is not,
91+ // it will use an absolute paths and we have to bail.
92+ if path.as_ref() == std::path::Path::new("..") {
93+ assert_eq!(path.kind(), Kind::WorkTree { linked_git_dir: None });
94+ assert_eq!(
95+ path.as_ref(),
96+ std::path::Path::new(".."),
97+ "there is only the minimal amount of relative path components to see this worktree"
98+ );
99+ } else {
100+ assert!(
101+ path.as_ref().is_absolute(),
102+ "worktree paths are absolute and the parent repo is one"
103+ );
104+ assert!(matches!(
105+ path.kind(),
106+ Kind::WorkTree {
107+ linked_git_dir: Some(_)
108+ }
109+ ));
110+ }
96111 assert_eq!(trust, expected_trust());
97112 Ok(())
98113 }