@@ -57,23 +57,44 @@ pub fn query(
57
57
}
58
58
}
59
59
PathsOrPatterns :: Patterns ( patterns) => {
60
- for ( path, _entry) in repo
61
- . pathspec (
62
- patterns. into_iter ( ) ,
63
- repo. work_dir ( ) . is_some ( ) ,
64
- & index,
65
- gix:: worktree:: stack:: state:: attributes:: Source :: WorktreeThenIdMapping
66
- . adjust_for_bare ( repo. is_bare ( ) ) ,
67
- ) ?
60
+ let mut pathspec_matched_something = false ;
61
+ let mut pathspec = repo. pathspec (
62
+ patterns. iter ( ) ,
63
+ repo. work_dir ( ) . is_some ( ) ,
64
+ & index,
65
+ gix:: worktree:: stack:: state:: attributes:: Source :: WorktreeThenIdMapping . adjust_for_bare ( repo. is_bare ( ) ) ,
66
+ ) ?;
67
+
68
+ for ( path, _entry) in pathspec
68
69
. index_entries_with_paths ( & index)
69
70
. ok_or_else ( || anyhow ! ( "Pathspec didn't yield any entry" ) ) ?
70
71
{
72
+ pathspec_matched_something = true ;
71
73
let entry = cache. at_entry ( path, Some ( false ) ) ?;
72
74
let match_ = entry
73
75
. matching_exclude_pattern ( )
74
76
. and_then ( |m| ( show_ignore_patterns || !m. pattern . is_negative ( ) ) . then_some ( m) ) ;
75
77
print_match ( match_, path, & mut out) ?;
76
78
}
79
+
80
+ if !pathspec_matched_something {
81
+ // TODO(borrowchk): this shouldn't be necessary at all, but `pathspec` stays borrowed mutably for some reason.
82
+ // It's probably due to the strange lifetimes of `index_entries_with_paths()`.
83
+ let pathspec = repo. pathspec (
84
+ patterns. iter ( ) ,
85
+ repo. work_dir ( ) . is_some ( ) ,
86
+ & index,
87
+ gix:: worktree:: stack:: state:: attributes:: Source :: WorktreeThenIdMapping
88
+ . adjust_for_bare ( repo. is_bare ( ) ) ,
89
+ ) ?;
90
+ for pattern in pathspec. search ( ) . patterns ( ) {
91
+ let entry = cache. at_entry ( pattern. path ( ) , None ) ?;
92
+ let match_ = entry
93
+ . matching_exclude_pattern ( )
94
+ . and_then ( |m| ( show_ignore_patterns || !m. pattern . is_negative ( ) ) . then_some ( m) ) ;
95
+ print_match ( match_, pattern. path ( ) , & mut out) ?;
96
+ }
97
+ }
77
98
}
78
99
}
79
100
0 commit comments