Skip to content

Commit a899f74

Browse files
committed
Merge branch 'fix-input'
2 parents 995bc84 + 3bfe73e commit a899f74

File tree

8 files changed

+73
-13
lines changed

8 files changed

+73
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ jobs:
4848
runs-on: ubuntu-latest
4949
steps:
5050
- uses: actions/checkout@v3
51+
- uses: dtolnay/rust-toolchain@stable
5152
- uses: Swatinem/rust-cache@v2
5253
- name: Setup dependencies
5354
run:

gitoxide-core/src/repository/attributes/query.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,43 @@ pub(crate) mod function {
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

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

gix-index/tests/index/access.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,16 @@ fn prefixed_entries() {
152152
check_prefix(&file, "x", &["x"]);
153153
check_prefix(&file, "b", &["b"]);
154154
check_prefix(&file, "c", &["c"]);
155+
156+
assert_eq!(
157+
file.prefixed_entries_range("".into()),
158+
Some(0..11),
159+
"empty prefixes match everything"
160+
);
161+
assert!(
162+
file.prefixed_entries_range("foo".into()).is_none(),
163+
"there is no match for this prefix"
164+
);
155165
}
156166

157167
fn check_prefix(index: &gix_index::State, prefix: &str, expected: &[&str]) {

justfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ alias nt := nextest
1313
test: clippy check doc unit-tests journey-tests-pure journey-tests-small journey-tests-async journey-tests
1414

1515
# run all tests, without clippy, including journey tests, try building docs (and clear target on CI)
16-
ci-test: check doc unit-tests clear-target journey-tests-pure journey-tests-small journey-tests-async journey-tests
16+
ci-test: check doc clear-target unit-tests ci-journey-tests
17+
18+
# run all journey tests, but assure these are running after `cargo clean` (and workaround a just-issue of deduplicating targets)
19+
ci-journey-tests:
20+
just clear-target journey-tests-pure journey-tests-small journey-tests-async journey-tests
1721

1822
clear-target:
1923
cargo clean
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
1+
thread 'main' panicked at src/porcelain/main.rs:41:42:
2+
something went very wrong
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
thread 'main' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
1+
thread 'main' panicked at src/porcelain/main.rs:41:42:
2+
something went very wrong
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
[?1049h[?25lthread '<unnamed>' panicked at 'something went very wrong', src/porcelain/main.rs:41:42
1+
[?1049h[?25lthread '<unnamed>' panicked at src/porcelain/main.rs:41:42:
2+
something went very wrong
23
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
34
[?25h[?1049l

0 commit comments

Comments
 (0)