@@ -15,6 +15,68 @@ fn no_pathspecs_match_everything() -> crate::Result {
15
15
} )
16
16
. expect ( "matches" ) ;
17
17
assert_eq ! ( m. pattern. prefix_directory( ) , "" , "there is no prefix as none was given" ) ;
18
+ assert_eq ! (
19
+ m. sequence_number, 0 ,
20
+ "this is actually a fake pattern, as we have to match even though there isn't anything"
21
+ ) ;
22
+
23
+ assert ! ( search. can_match_relative_path( "anything" . into( ) , None ) ) ;
24
+
25
+ Ok ( ( ) )
26
+ }
27
+
28
+ #[ test]
29
+ fn simplified_search_respects_must_be_dir ( ) -> crate :: Result {
30
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ "a/b/" ] ) , None , Path :: new ( "" ) ) ?;
31
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , None ) ) ;
32
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , Some ( false ) ) ) ;
33
+ assert ! ( search. can_match_relative_path( "a" . into( ) , Some ( true ) ) ) ;
34
+ assert ! ( search. can_match_relative_path( "a/b" . into( ) , Some ( true ) ) ) ;
35
+
36
+ Ok ( ( ) )
37
+ }
38
+
39
+ #[ test]
40
+ fn simplified_search_respects_ignore_case ( ) -> crate :: Result {
41
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":(icase)foo/**/bar" ] ) , None , Path :: new ( "" ) ) ?;
42
+ assert ! ( search. can_match_relative_path( "Foo" . into( ) , None ) ) ;
43
+ assert ! ( search. can_match_relative_path( "foo" . into( ) , Some ( true ) ) ) ;
44
+ assert ! ( search. can_match_relative_path( "FOO/" . into( ) , Some ( true ) ) ) ;
45
+
46
+ Ok ( ( ) )
47
+ }
48
+
49
+ #[ test]
50
+ fn simplified_search_respects_all_excluded ( ) -> crate :: Result {
51
+ let search = gix_pathspec:: Search :: from_specs (
52
+ pathspecs ( & [ ":(exclude)a/file" , ":(exclude)b/file" ] ) ,
53
+ None ,
54
+ Path :: new ( "" ) ,
55
+ ) ?;
56
+ assert ! ( !search. can_match_relative_path( "b" . into( ) , None ) ) ;
57
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , None ) ) ;
58
+ assert ! ( search. can_match_relative_path( "c" . into( ) , None ) ) ;
59
+ assert ! ( search. can_match_relative_path( "c/" . into( ) , None ) ) ;
60
+
61
+ Ok ( ( ) )
62
+ }
63
+
64
+ #[ test]
65
+ fn simplified_search_handles_nil ( ) -> crate :: Result {
66
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":" ] ) , None , Path :: new ( "" ) ) ?;
67
+ assert ! ( search. can_match_relative_path( "a" . into( ) , None ) , "everything matches" ) ;
68
+ assert ! ( search. can_match_relative_path( "a" . into( ) , Some ( false ) ) ) ;
69
+ assert ! ( search. can_match_relative_path( "a" . into( ) , Some ( true ) ) ) ;
70
+ assert ! ( search. can_match_relative_path( "a/b" . into( ) , Some ( true ) ) ) ;
71
+
72
+ let search = gix_pathspec:: Search :: from_specs ( pathspecs ( & [ ":(exclude)" ] ) , None , Path :: new ( "" ) ) ?;
73
+ assert ! (
74
+ !search. can_match_relative_path( "a" . into( ) , None ) ,
75
+ "everything does not match"
76
+ ) ;
77
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , Some ( false ) ) ) ;
78
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , Some ( true ) ) ) ;
79
+ assert ! ( !search. can_match_relative_path( "a/b" . into( ) , Some ( true ) ) ) ;
18
80
19
81
Ok ( ( ) )
20
82
}
@@ -28,6 +90,15 @@ fn init_with_exclude() -> crate::Result {
28
90
"re-orded so that excluded are first"
29
91
) ;
30
92
assert_eq ! ( search. common_prefix( ) , "tests" ) ;
93
+ assert ! (
94
+ search. can_match_relative_path( "tests" . into( ) , Some ( true ) ) ,
95
+ "prefix matches"
96
+ ) ;
97
+ assert ! (
98
+ search. can_match_relative_path( "test" . into( ) , Some ( true ) ) ,
99
+ "prefix can also be shorter"
100
+ ) ;
101
+ assert ! ( !search. can_match_relative_path( "outside-of-tests" . into( ) , None ) ) ;
31
102
Ok ( ( ) )
32
103
}
33
104
@@ -47,6 +118,7 @@ fn no_pathspecs_respect_prefix() -> crate::Result {
47
118
. is_none( ) ,
48
119
"not the right prefix"
49
120
) ;
121
+ assert ! ( !search. can_match_relative_path( "hello" . into( ) , None ) ) ;
50
122
let m = search
51
123
. pattern_matching_relative_path ( "a/b" . into ( ) , None , & mut |_, _, _, _| unreachable ! ( "must not be called" ) )
52
124
. expect ( "match" ) ;
@@ -55,12 +127,16 @@ fn no_pathspecs_respect_prefix() -> crate::Result {
55
127
"a" ,
56
128
"the prefix directory matched verbatim"
57
129
) ;
130
+ assert ! ( search. can_match_relative_path( "a/" . into( ) , Some ( true ) ) ) ;
131
+ assert ! ( search. can_match_relative_path( "a" . into( ) , Some ( true ) ) ) ;
132
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , Some ( false ) ) ) ;
133
+ assert ! ( !search. can_match_relative_path( "a" . into( ) , None ) ) ;
58
134
59
135
Ok ( ( ) )
60
136
}
61
137
62
138
#[ test]
63
- fn prefixes_are_always_case_insensitive ( ) -> crate :: Result {
139
+ fn prefixes_are_always_case_sensitive ( ) -> crate :: Result {
64
140
let path = gix_testtools:: scripted_fixture_read_only ( "match_baseline_files.sh" ) ?. join ( "paths" ) ;
65
141
let items = baseline:: parse_paths ( path) ?;
66
142
@@ -108,6 +184,18 @@ fn prefixes_are_always_case_insensitive() -> crate::Result {
108
184
. collect ( ) ;
109
185
assert_eq ! ( actual, expected, "{spec} {prefix}" ) ;
110
186
}
187
+
188
+ let search = gix_pathspec:: Search :: from_specs (
189
+ gix_pathspec:: parse ( ":(icase)bar" . as_bytes ( ) , Default :: default ( ) ) ,
190
+ Some ( Path :: new ( "FOO" ) ) ,
191
+ Path :: new ( "" ) ,
192
+ ) ?;
193
+ assert ! (
194
+ !search. can_match_relative_path( "foo" . into( ) , Some ( true ) ) ,
195
+ "icase does not apply to the prefix"
196
+ ) ;
197
+ assert ! ( search. can_match_relative_path( "FOO" . into( ) , Some ( true ) ) ) ;
198
+ assert ! ( search. can_match_relative_path( "FOO/ba" . into( ) , Some ( true ) ) ) ;
111
199
Ok ( ( ) )
112
200
}
113
201
0 commit comments