@@ -3,6 +3,23 @@ use std::path::{Path, PathBuf};
3
3
use gix_discover:: upwards:: Options ;
4
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( "." ) , "{dir}" ) ;
19
+ }
20
+ Ok ( ( ) )
21
+ }
22
+
6
23
#[ test]
7
24
#[ serial]
8
25
fn upwards_bare_repo_with_index ( ) -> gix_testtools:: Result {
@@ -48,18 +65,21 @@ fn in_cwd_upwards_nonbare_repo_without_index() -> gix_testtools::Result {
48
65
fn upwards_with_relative_directories_and_optional_ceiling ( ) -> gix_testtools:: Result {
49
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
69
let cwd = std:: env:: current_dir ( ) ?;
53
70
54
71
for ( search_dir, ceiling_dir_component) in [
55
72
( "." , ".." ) ,
56
73
( "." , "./.." ) ,
57
74
( "./." , "./.." ) ,
58
75
( "." , "./does-not-exist/../.." ) ,
76
+ ( "./././very/deeply/nested/subdir" , ".." ) ,
77
+ ( "very/deeply/nested/subdir" , ".." ) ,
59
78
] {
79
+ let search_dir = Path :: new ( search_dir) ;
60
80
let ceiling_dir = cwd. join ( ceiling_dir_component) ;
61
81
let ( repo_path, _trust) = gix_discover:: upwards_opts (
62
- search_dir. as_ref ( ) ,
82
+ search_dir,
63
83
Options {
64
84
ceiling_dirs : vec ! [ ceiling_dir] ,
65
85
..Default :: default ( )
@@ -68,12 +88,12 @@ fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Re
68
88
. expect ( "ceiling dir should allow us to discover the repo" ) ;
69
89
assert_repo_is_current_workdir ( repo_path, Path :: new ( ".." ) ) ;
70
90
71
- let ( repo_path, _trust) = gix_discover :: upwards_opts ( search_dir . as_ref ( ) , Default :: default ( ) )
72
- . expect ( "without ceiling dir we see the same" ) ;
91
+ let ( repo_path, _trust) =
92
+ gix_discover :: upwards_opts ( search_dir , Default :: default ( ) ) . expect ( "without ceiling dir we see the same" ) ;
73
93
assert_repo_is_current_workdir ( repo_path, Path :: new ( ".." ) ) ;
74
94
75
95
let ( repo_path, _trust) = gix_discover:: upwards_opts (
76
- search_dir. as_ref ( ) ,
96
+ search_dir,
77
97
Options {
78
98
ceiling_dirs : vec ! [ PathBuf :: from( ".." ) ] ,
79
99
..Default :: default ( )
@@ -83,15 +103,22 @@ fn upwards_with_relative_directories_and_optional_ceiling() -> gix_testtools::Re
83
103
assert_repo_is_current_workdir ( repo_path, Path :: new ( ".." ) ) ;
84
104
85
105
let err = gix_discover:: upwards_opts (
86
- search_dir. as_ref ( ) ,
106
+ search_dir,
87
107
Options {
88
108
ceiling_dirs : vec ! [ PathBuf :: from( "." ) ] ,
89
109
..Default :: default ( )
90
110
} ,
91
111
)
92
112
. unwrap_err ( ) ;
93
113
94
- assert ! ( matches!( err, gix_discover:: upwards:: Error :: NoMatchingCeilingDir ) ) ;
114
+ if search_dir. parent ( ) == Some ( "." . as_ref ( ) ) || search_dir. parent ( ) == Some ( "" . as_ref ( ) ) {
115
+ assert ! ( matches!( err, gix_discover:: upwards:: Error :: NoMatchingCeilingDir ) ) ;
116
+ } else {
117
+ assert ! ( matches!(
118
+ err,
119
+ gix_discover:: upwards:: Error :: NoGitRepositoryWithinCeiling { .. }
120
+ ) ) ;
121
+ }
95
122
}
96
123
97
124
Ok ( ( ) )
0 commit comments