make sure session/wd git-tree only contains wd files

This commit is contained in:
Nikita Galaiko 2023-03-15 10:07:27 +01:00
parent fb7522463a
commit 711c10ee25
No known key found for this signature in database
GPG Key ID: EBAB54E845BA519D
2 changed files with 13 additions and 1 deletions

View File

@ -522,6 +522,11 @@ pub fn list_files(
if "wd".eq(entry_path.to_str().unwrap()) {
return git2::TreeWalkResult::Ok;
}
if entry.kind() == Some(git2::ObjectType::Tree) {
return git2::TreeWalkResult::Ok;
}
let blob = entry.to_object(repo).and_then(|obj| obj.peel_to_blob());
let content = blob.map(|blob| blob.content().to_vec());
@ -707,7 +712,9 @@ fn build_wd_tree(repo: &git2::Repository, project: &projects::Project) -> Result
// and the session files
let commit = reference.peel_to_commit()?;
let tree = commit.tree()?;
wd_index.read_tree(&tree)?;
let wd_tree_entry = tree.get_name("wd").unwrap();
let wd_tree = repo.find_tree(wd_tree_entry.id())?;
wd_index.read_tree(&wd_tree)?;
let session_wd_files = fs::list_files(project.wd_path()).with_context(|| {
format!("failed to list files in {}", project.wd_path().display())

View File

@ -158,6 +158,11 @@ fn test_flow() {
None,
)
.unwrap();
if i == 0 {
assert_eq!(files.len(), 0);
} else {
assert_eq!(files.len(), 1);
}
let base_file = files.get(&relative_file_path.to_str().unwrap().to_string());
let mut text: Vec<char> = match base_file {