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
53 }53 }
54 PathsOrPatterns::Patterns(patterns) => {54 PathsOrPatterns::Patterns(patterns) => {
55 let mut pathspec = repo.pathspec(55 let mut pathspec = repo.pathspec(
56 patterns,56 patterns.iter(),
57 true,57 true,
58 &index,58 &index,
59 gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping59 gix::worktree::stack::state::attributes::Source::WorktreeThenIdMapping
60 .adjust_for_bare(repo.is_bare()),60 .adjust_for_bare(repo.is_bare()),
61 )?;61 )?;
62 let mut pathspec_matched_entry = false;
62 for (path, _entry) in pathspec63 for (path, _entry) in pathspec
63 .index_entries_with_paths(&index)64 .index_entries_with_paths(&index)
64 .ok_or_else(|| anyhow!("Pathspec didn't match a single path in the index"))?65 .ok_or_else(|| anyhow!("Pathspec didn't match a single path in the index"))?
65 {66 {
67 pathspec_matched_entry = true;
66 let entry = cache.at_entry(path, Some(false))?;68 let entry = cache.at_entry(path, Some(false))?;
67 if !entry.matching_attributes(&mut matches) {69 if !entry.matching_attributes(&mut matches) {
68 continue;70 continue;
69 }71 }
70 print_match(&matches, path, &mut out)?;72 print_match(&matches, path, &mut out)?;
71 }73 }
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 }
72 }93 }
73 }94 }
74 95