Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvements to gix clean #1470

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ gitoxide-core-async-client = ["gitoxide-core/async-client", "futures-lite"]
[dependencies]
anyhow = "1.0.42"

gitoxide-core = { version = "^0.39.0", path = "gitoxide-core" }
gitoxide-core = { version = "^0.39.1", path = "gitoxide-core" }
gix-features = { version = "^0.38.2", path = "gix-features" }
gix = { version = "^0.64.0", path = "gix", default-features = false }
time = "0.3.23"
Expand Down
2 changes: 1 addition & 1 deletion gitoxide-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "gitoxide-core"
description = "The library implementing all capabilities of the gitoxide CLI"
repository = "https://github.com/Byron/gitoxide"
version = "0.39.0"
version = "0.39.1"
authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>"]
license = "MIT OR Apache-2.0"
edition = "2021"
Expand Down
13 changes: 11 additions & 2 deletions gix-dir/src/walk/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,17 @@ pub fn path(
),
);
}
if kind.map_or(false, |d| d.is_recursable_dir()) && out.pathspec_match.is_none() {
// we have patterns that didn't match at all, *yet*. We want to look inside.
if kind.map_or(false, |d| d.is_recursable_dir())
&& (out.pathspec_match.is_none()
|| worktree_relative_worktree_dirs.map_or(false, |worktrees| {
for_deletion.is_some()
&& worktrees
.iter()
.any(|dir| dir.starts_with_str(&*rela_path) && dir.get(rela_path.len()) == Some(&b'/'))
}))
{
// We have patterns that didn't match at all, *yet*, or there are contained worktrees.
// We want to look inside.
out.pathspec_match = Some(PathspecMatch::Prefix);
}
}
Expand Down
10 changes: 9 additions & 1 deletion gix-dir/tests/fixtures/many.sh
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,12 @@ git clone dir-with-tracked-file in-repo-worktree
(cd in-repo-worktree
git worktree add worktree
git worktree add -b other-worktree dir/worktree
)
)

git clone dir-with-tracked-file in-repo-hidden-worktree
(cd in-repo-hidden-worktree
echo '/hidden/' > .gitignore
mkdir -p hidden/subdir
touch hidden/file
git worktree add -b worktree-branch hidden/subdir/worktree
)
97 changes: 97 additions & 0 deletions gix-dir/tests/walk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4550,3 +4550,100 @@ fn in_repo_worktree() -> crate::Result {
);
Ok(())
}

#[test]
fn in_repo_hidden_worktree() -> crate::Result {
let root = fixture("in-repo-hidden-worktree");
let ((out, _root), entries) = collect(&root, None, |keep, ctx| walk(&root, ctx, options_emit_all(), keep));
assert_eq!(
out,
walk::Outcome {
read_dir_calls: 2,
returned_entries: entries.len(),
seen_entries: 4,
}
);
assert_eq!(
entries,
&[
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
entry(".gitignore", Untracked, File),
entry("dir/file", Tracked, File),
entry("hidden", Ignored(Expendable), Directory),
],
"if worktree information isn't provided, they would not be discovered in hidden directories"
);

let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
walk(
&root,
ctx,
walk::Options {
for_deletion: None,
worktree_relative_worktree_dirs: Some(&BTreeSet::from(["hidden/subdir/worktree".into()])),
..options_emit_all()
},
keep,
)
});
assert_eq!(
out,
walk::Outcome {
read_dir_calls: 2,
returned_entries: entries.len(),
seen_entries: 4,
}
);
assert_eq!(
entries,
&[
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
entry(".gitignore", Untracked, File),
entry("dir/file", Tracked, File),
entry("hidden", Ignored(Expendable), Directory),
],
"Without the intend to delete, the worktree remains hidden, which is what we want to see in a `status` for example"
);

for ignored_emission_mode in [Matching, CollapseDirectory] {
for deletion_mode in [
ForDeletionMode::IgnoredDirectoriesCanHideNestedRepositories,
ForDeletionMode::FindRepositoriesInIgnoredDirectories,
ForDeletionMode::FindNonBareRepositoriesInIgnoredDirectories,
] {
let ((out, _root), entries) = collect(&root, None, |keep, ctx| {
walk(
&root,
ctx,
walk::Options {
emit_ignored: Some(ignored_emission_mode),
for_deletion: Some(deletion_mode),
worktree_relative_worktree_dirs: Some(&BTreeSet::from(["hidden/subdir/worktree".into()])),
..options_emit_all()
},
keep,
)
});
assert_eq!(
out,
walk::Outcome {
read_dir_calls: 4,
returned_entries: entries.len(),
seen_entries: 5,
}
);
assert_eq!(
entries,
&[
entry_nokind(".git", Pruned).with_property(DotGit).with_match(Always),
entry(".gitignore", Untracked, File),
entry("dir/file", Tracked, File),
entry("hidden/file", Ignored(Expendable), File),
entry("hidden/subdir/worktree", Tracked, Repository).no_index_kind(),
],
"Worktrees within hidden directories are also detected and protected by counting them as tracked (like submodules)"
);
}
}
Ok(())
}
Loading