Skip to content

Commit

Permalink
Ignore submodules for changed file picker
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI committed Jan 24, 2023
1 parent df420eb commit bb97f55
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions helix-vcs/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,18 @@ impl Git {
let head_tree = repo.head_commit()?.tree()?;

let mut head_tree_files = vec![];
traverse_tree(&head_tree, repo, PathBuf::new(), &mut head_tree_files)?;
let mut submodule_paths = vec![PathBuf::from(".git")];
traverse_tree(
&head_tree,
repo,
PathBuf::new(),
&mut head_tree_files,
&mut submodule_paths,
)?;

submodule_paths
.iter_mut()
.for_each(|path| *path = work_dir.join(&path));

let mut head_tree_set = HashSet::new();

Expand Down Expand Up @@ -173,7 +184,12 @@ impl Git {
for entry in WalkBuilder::new(work_dir)
.hidden(false)
.ignore(false)
.filter_entry(|entry| entry.file_name() != ".git")
.filter_entry(move |entry| {
entry.file_name() != ".git"
&& !submodule_paths
.iter()
.any(|submodule| entry.path().starts_with(submodule))
})
.build()
{
let entry = entry?;
Expand Down Expand Up @@ -336,6 +352,7 @@ fn traverse_tree(
repo: &Repository,
base: PathBuf,
all_files: &mut Vec<GitFileMeta>,
submodules: &mut Vec<PathBuf>,
) -> Result<()> {
for entry in tree.iter() {
let entry = entry?;
Expand All @@ -346,10 +363,13 @@ fn traverse_tree(
EntryMode::Tree => {
let obj = repo.find_object(entry.id())?;
let new_tree = obj.try_into_tree()?;
traverse_tree(&new_tree, repo, new_base, all_files)?;
traverse_tree(&new_tree, repo, new_base, all_files, submodules)?;
}
EntryMode::Commit => {
anyhow::bail!("broken tree: unexpected entry type");
// Submodules not supported yet. We return the path so that the fs walk can ignore
// them.
// TODO: support option for recursively looking into submodules
submodules.push(new_base);
}
EntryMode::Link => {
all_files.push(GitFileMeta {
Expand Down

0 comments on commit bb97f55

Please sign in to comment.