File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,10 @@ impl<'a> Platform<'a> {
1313
1414 /// See if the currently set entry is excluded as per exclude and git-ignore files.
1515 ///
16+ /// Note that this threats both classes, [*trashable*](gix_ignore::Kind::Expendable) and [*precious*](gix_ignore::Kind::Precious)
17+ /// as equal. If you need to differentiate, use [`matching_exclude_pattern()`](Self::matching_exclude_pattern)
18+ /// or [`excluded_kind()`](Self::excluded_kind).
19+ ///
1620 /// # Panics
1721 ///
1822 /// If the cache was configured without exclude patterns.
@@ -21,6 +25,16 @@ impl<'a> Platform<'a> {
2125 . map_or ( false , |m| !m. pattern . is_negative ( ) )
2226 }
2327
28+ /// See if a non-negative ignore-pattern matches and obtain the kind of exclude, or return `None`
29+ /// if the path isn't excluded.
30+ ///
31+ /// This is similar to [`is_excluded()`](Self::is_excluded), but provides details that are useful to
32+ /// decide what to do with the excluded item.
33+ pub fn excluded_kind ( & self ) -> Option < gix_ignore:: Kind > {
34+ self . matching_exclude_pattern ( )
35+ . and_then ( |m| ( !m. pattern . is_negative ( ) ) . then_some ( m. kind ) )
36+ }
37+
2438 /// Check all exclude patterns to see if the currently set path matches any of them.
2539 ///
2640 /// Note that this pattern might be negated, and means this path in included.
Original file line number Diff line number Diff line change @@ -105,6 +105,7 @@ impl Ignore {
105105 let match_ = gix_ignore:: search:: Match {
106106 pattern : & mapping. pattern ,
107107 sequence_number : mapping. sequence_number ,
108+ kind : mapping. value ,
108109 source,
109110 } ;
110111 if mapping. pattern . is_negative ( ) {
Original file line number Diff line number Diff line change @@ -76,6 +76,12 @@ fn exclude_by_dir_is_handled_just_like_git() {
7676 expected_pattern, "tld/" ,
7777 "each entry matches on the main directory exclude, ignoring negations entirely"
7878 ) ;
79+ // TODO: adjust baseline to also include precious files.
80+ assert_eq ! (
81+ match_. kind,
82+ gix_ignore:: Kind :: Expendable ,
83+ "for now all patterns are expendable until precious files are supported by git"
84+ ) ;
7985 assert_eq ! ( line, 2 ) ;
8086 assert_eq ! ( source, ".gitignore" ) ;
8187 }
@@ -134,6 +140,14 @@ fn check_against_baseline() -> crate::Result {
134140 ( Some ( m) , Some ( ( source_file, line, pattern) ) ) => {
135141 assert_eq ! ( m. pattern. to_string( ) , pattern) ;
136142 assert_eq ! ( m. sequence_number, line) ;
143+ // TODO: adjust baseline to also include precious files.
144+ if !m. pattern . is_negative ( ) {
145+ assert_eq ! (
146+ m. kind,
147+ platform. excluded_kind( ) . expect( "it matches" ) ,
148+ "both values agree, no matter which method is used"
149+ ) ;
150+ }
137151 // Paths read from the index are relative to the repo, and they don't exist locally due tot skip-worktree
138152 if m. source . map_or ( false , std:: path:: Path :: exists) {
139153 assert_eq ! (
You can’t perform that action at this time.
0 commit comments