History

fix: `gix attrs query` now shows attributes even for paths that aren't already tracked

Sebastian Thiel committed 3 years ago

Commit 760d4511 parent 6fb851b1 file · +22 −1Browse files

Unified · Split

gitoxide-core/src/repository/attributes/query.rs+22−1
@@ -53,22 +53,43 @@ pub(crate) mod function { · 52 unmodified lines
5353 }
5454 PathsOrPatterns::Patterns(patterns) => {
5555 let mut pathspec = repo.pathspec(
56− patterns,
56+ patterns.iter(),
5757 true,
5858 &index,
5959 gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
6060 .adjust_for_bare(repo.is_bare()),
6161 )?;
62+ let mut pathspec_matched_entry = false;
6263 for (path, _entry) in pathspec
6364 .index_entries_with_paths(&index)
6465 .ok_or_else(|| anyhow!("Pathspec didn't match a single path in the index"))?
6566 {
67+ pathspec_matched_entry = true;
6668 let entry = cache.at_entry(path, Some(false))?;
6769 if !entry.matching_attributes(&mut matches) {
6870 continue;
6971 }
7072 print_match(&matches, path, &mut out)?;
7173 }
74+
75+ if !pathspec_matched_entry {
76+ // TODO(borrowchk): this shouldn't be necessary at all, but `pathspec` stays borrowed mutably for some reason.
77+ // It's probably due to the strange lifetimes of `index_entries_with_paths()`.
78+ let pathspec = repo.pathspec(
79+ patterns.iter(),
80+ true,
81+ &index,
82+ gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
83+ .adjust_for_bare(repo.is_bare()),
84+ )?;
85+ for pattern in pathspec.search().patterns() {
86+ let entry = cache.at_entry(pattern.path(), Some(false))?;
87+ if !entry.matching_attributes(&mut matches) {
88+ continue;
89+ }
90+ print_match(&matches, pattern.path(), &mut out)?;
91+ }
92+ }
7293 }
7394 }
7495