Skip to content

Commit 213d2dc

Browse files
committed
Find path of repo root when in a Cargo workspace
1 parent f071fd2 commit 213d2dc

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pgvectorscale/src/access_method/upgrade_test.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,14 @@ pub mod tests {
5555

5656
// Convert the file path to an absolute path
5757
let current_dir = std::env::current_dir().unwrap();
58-
let mut absolute_path = std::path::Path::new(&current_dir).join(current_file);
59-
absolute_path = absolute_path.ancestors().nth(4).unwrap().to_path_buf();
58+
let absolute_path_full = std::path::Path::new(&current_dir).join(current_file);
59+
let mut absolute_path = None;
60+
for ancestor in absolute_path_full.ancestors() {
61+
if std::fs::exists(ancestor.join(".git")).unwrap() {
62+
absolute_path = Some(ancestor.to_path_buf());
63+
}
64+
}
65+
let absolute_path = absolute_path.expect("Couldn't find root directory");
6066

6167
let temp_dir = tempfile::tempdir().unwrap();
6268
let temp_path = temp_dir.path();

0 commit comments

Comments
 (0)