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> {
13
13
14
14
/// See if the currently set entry is excluded as per exclude and git-ignore files.
15
15
///
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
+ ///
16
20
/// # Panics
17
21
///
18
22
/// If the cache was configured without exclude patterns.
@@ -21,6 +25,16 @@ impl<'a> Platform<'a> {
21
25
. map_or ( false , |m| !m. pattern . is_negative ( ) )
22
26
}
23
27
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
+
24
38
/// Check all exclude patterns to see if the currently set path matches any of them.
25
39
///
26
40
/// 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 {
105
105
let match_ = gix_ignore:: search:: Match {
106
106
pattern : & mapping. pattern ,
107
107
sequence_number : mapping. sequence_number ,
108
+ kind : mapping. value ,
108
109
source,
109
110
} ;
110
111
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() {
76
76
expected_pattern, "tld/" ,
77
77
"each entry matches on the main directory exclude, ignoring negations entirely"
78
78
) ;
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
+ ) ;
79
85
assert_eq ! ( line, 2 ) ;
80
86
assert_eq ! ( source, ".gitignore" ) ;
81
87
}
@@ -134,6 +140,14 @@ fn check_against_baseline() -> crate::Result {
134
140
( Some ( m) , Some ( ( source_file, line, pattern) ) ) => {
135
141
assert_eq ! ( m. pattern. to_string( ) , pattern) ;
136
142
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
+ }
137
151
// Paths read from the index are relative to the repo, and they don't exist locally due tot skip-worktree
138
152
if m. source . map_or ( false , std:: path:: Path :: exists) {
139
153
assert_eq ! (
You can’t perform that action at this time.
0 commit comments