@@ -141,7 +141,9 @@ pub mod excludes {
141
141
142
142
///
143
143
pub mod attributes {
144
- /// The error returned by [`Worktree::attributes()`][crate::Worktree::attributes()].
144
+ use crate :: Worktree ;
145
+
146
+ /// The error returned by [`Worktree::attributes()`].
145
147
#[ derive( Debug , thiserror:: Error ) ]
146
148
#[ allow( missing_docs) ]
147
149
pub enum Error {
@@ -151,7 +153,7 @@ pub mod attributes {
151
153
CreateCache ( #[ from] crate :: repository:: attributes:: Error ) ,
152
154
}
153
155
154
- impl < ' repo > crate :: Worktree < ' repo > {
156
+ impl < ' repo > Worktree < ' repo > {
155
157
/// Configure a file-system cache checking if files below the repository are excluded or for querying their attributes.
156
158
///
157
159
/// This takes into consideration all the usual repository configuration, namely:
@@ -180,3 +182,58 @@ pub mod attributes {
180
182
}
181
183
}
182
184
}
185
+
186
+ ///
187
+ pub mod pathspec {
188
+ use crate :: bstr:: BStr ;
189
+ use crate :: config:: cache:: util:: ApplyLeniencyDefaultValue ;
190
+ use crate :: config:: tree:: gitoxide;
191
+ use crate :: Worktree ;
192
+
193
+ /// The error returned by [`Worktree::pathspec()`].
194
+ #[ derive( Debug , thiserror:: Error ) ]
195
+ #[ allow( missing_docs) ]
196
+ pub enum Error {
197
+ #[ error( transparent) ]
198
+ Init ( #[ from] crate :: pathspec:: init:: Error ) ,
199
+ #[ error( transparent) ]
200
+ OpenIndex ( #[ from] crate :: worktree:: open_index:: Error ) ,
201
+ }
202
+
203
+ impl < ' repo > Worktree < ' repo > {
204
+ /// Configure pathspecs `patterns` to be matched against, with pathspec attributes read from the worktree and then from the index
205
+ /// if needed.
206
+ ///
207
+ /// ### Deviation
208
+ ///
209
+ /// Pathspec attributes match case-insensitively by default if the underlying filesystem is configured that way.
210
+ pub fn pathspec (
211
+ & self ,
212
+ patterns : impl IntoIterator < Item = impl AsRef < BStr > > ,
213
+ ) -> Result < crate :: Pathspec < ' repo > , Error > {
214
+ let index = self . index ( ) ?;
215
+ let inherit_ignore_case = self
216
+ . parent
217
+ . config
218
+ . resolved
219
+ . boolean_by_key ( "gitoxide.pathspec.inheritIgnoreCase" )
220
+ . map ( |res| {
221
+ gitoxide:: Pathspec :: INHERIT_IGNORE_CASE
222
+ . enrich_error ( res)
223
+ . with_lenient_default_value (
224
+ self . parent . config . lenient_config ,
225
+ gitoxide:: Pathspec :: INHERIT_IGNORE_CASE_DEFAULT ,
226
+ )
227
+ } )
228
+ . transpose ( )
229
+ . map_err ( |err| Error :: Init ( crate :: pathspec:: init:: Error :: Defaults ( err. into ( ) ) ) ) ?
230
+ . unwrap_or ( gitoxide:: Pathspec :: INHERIT_IGNORE_CASE_DEFAULT ) ;
231
+ Ok ( self . parent . pathspec (
232
+ patterns,
233
+ inherit_ignore_case,
234
+ & index,
235
+ gix_worktree:: cache:: state:: attributes:: Source :: WorktreeThenIdMapping ,
236
+ ) ?)
237
+ }
238
+ }
239
+ }
0 commit comments