Skip to content

Commit

Permalink
Fix initial change listing with statuses
Browse files Browse the repository at this point in the history
Fix VCS events since listing to include currently untracked files.

Test Plan: cargo test

Pull Request: #351
  • Loading branch information
yamadapc committed Feb 20, 2025
1 parent ebd0e35 commit 11802bb
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion crates/atlaspack_vcs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,41 @@ pub fn get_changed_files_from_git(
old_commit: &git2::Commit<'_>,
new_commit: &git2::Commit<'_>,
) -> anyhow::Result<Vec<FileChangeEvent>> {
let mut changed_files = Vec::new();

// list current dirty files
tracing::debug!("Listing dirty files");
let mut status_options = git2::StatusOptions::new();

status_options.include_ignored(false);
status_options.include_untracked(true);
status_options.include_unmodified(false);

let statuses = repo.statuses(Some(&mut status_options))?;
statuses.iter().for_each(|entry| {
let path = entry.path().unwrap();
let status = entry.status();
let mut change_type = FileChangeType::Update;
if status.is_wt_deleted() {
change_type = FileChangeType::Delete;
} else if status.is_wt_new() {
change_type = FileChangeType::Create;
}
changed_files.push(FileChangeEvent {
path: repo_path.join(path),
change_type,
})
});

tracing::debug!("Calculating git diff");
let mut diff_options = DiffOptions::new();

let diff = repo.diff_tree_to_tree(
Some(&old_commit.tree()?),
Some(&new_commit.tree()?),
Some(&mut diff_options),
)?;

let mut changed_files = Vec::new();
diff.foreach(
&mut |delta, _| {
if let Some(new_file_path) = delta.new_file().path() {
Expand Down

0 comments on commit 11802bb

Please sign in to comment.