Skip to content

Commit 6fb851b

Browse files
committed
fix: gix exclude query now also displays paths that don't match existing index entries.
1 parent 357ba13 commit 6fb851b

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

gitoxide-core/src/repository/exclude.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,44 @@ pub fn query(
5757
}
5858
}
5959
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
6869
.index_entries_with_paths(&index)
6970
.ok_or_else(|| anyhow!("Pathspec didn't yield any entry"))?
7071
{
72+
pathspec_matched_something = true;
7173
let entry = cache.at_entry(path, Some(false))?;
7274
let match_ = entry
7375
.matching_exclude_pattern()
7476
.and_then(|m| (show_ignore_patterns || !m.pattern.is_negative()).then_some(m));
7577
print_match(match_, path, &mut out)?;
7678
}
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+
}
7798
}
7899
}
79100

0 commit comments

Comments
 (0)