|
1 | 1 | use gix_dir::{walk, EntryRef}; |
2 | 2 | use pretty_assertions::assert_eq; |
| 3 | +use std::collections::BTreeSet; |
3 | 4 | use std::sync::atomic::AtomicBool; |
4 | 5 |
|
5 | 6 | use crate::walk_utils::{ |
@@ -4493,3 +4494,59 @@ fn ignored_sub_repo() -> crate::Result { |
4493 | 4494 | } |
4494 | 4495 | Ok(()) |
4495 | 4496 | } |
| 4497 | + |
| 4498 | +#[test] |
| 4499 | +fn in_repo_worktree() -> crate::Result { |
| 4500 | + let root = fixture("in-repo-worktree"); |
| 4501 | + let ((out, _root), entries) = collect(&root, None, |keep, ctx| walk(&root, ctx, options_emit_all(), keep)); |
| 4502 | + assert_eq!( |
| 4503 | + out, |
| 4504 | + walk::Outcome { |
| 4505 | + read_dir_calls: 2, |
| 4506 | + returned_entries: entries.len(), |
| 4507 | + seen_entries: 4, |
| 4508 | + } |
| 4509 | + ); |
| 4510 | + assert_eq!( |
| 4511 | + entries, |
| 4512 | + &[ |
| 4513 | + entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always), |
| 4514 | + entry("dir/file", Tracked, File), |
| 4515 | + entry("dir/worktree", Untracked, Repository), |
| 4516 | + entry("worktree", Untracked, Repository), |
| 4517 | + ], |
| 4518 | + "without passing worktree information, they count as untracked repositories, making them vulnerable" |
| 4519 | + ); |
| 4520 | + |
| 4521 | + let ((out, _root), entries) = collect(&root, None, |keep, ctx| { |
| 4522 | + walk( |
| 4523 | + &root, |
| 4524 | + ctx, |
| 4525 | + walk::Options { |
| 4526 | + worktree_relative_worktree_dirs: Some(&BTreeSet::from(["worktree".into(), "dir/worktree".into()])), |
| 4527 | + ..options_emit_all() |
| 4528 | + }, |
| 4529 | + keep, |
| 4530 | + ) |
| 4531 | + }); |
| 4532 | + assert_eq!( |
| 4533 | + out, |
| 4534 | + walk::Outcome { |
| 4535 | + read_dir_calls: 2, |
| 4536 | + returned_entries: entries.len(), |
| 4537 | + seen_entries: 4, |
| 4538 | + } |
| 4539 | + ); |
| 4540 | + assert_eq!( |
| 4541 | + entries, |
| 4542 | + &[ |
| 4543 | + entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always), |
| 4544 | + entry("dir/file", Tracked, File), |
| 4545 | + entry("dir/worktree", Tracked, Repository).no_index_kind(), |
| 4546 | + entry("worktree", Tracked, Repository).no_index_kind(), |
| 4547 | + ], |
| 4548 | + "But when worktree information is passed, it is identified as tracked to look similarly to a submodule.\ |
| 4549 | + What gives it away is that the index-kind is None, which is unusual for a tracked file." |
| 4550 | + ); |
| 4551 | + Ok(()) |
| 4552 | +} |
0 commit comments