correctly handle empty file diffs

This commit is contained in:
Nikita Galaiko 2023-10-16 15:30:24 +02:00 committed by GitButler
parent 3e575482a9
commit c896d2b8f2
3 changed files with 13 additions and 5 deletions

View File

@ -94,6 +94,10 @@ fn hunks_by_filepath(
.expect("failed to get file name from diff")
});
if current_file_path.is_none() {
current_file_path = Some(file_path.to_path_buf());
}
let (hunk_id, new_start, new_lines, old_start, old_lines) = if let Some(hunk) = hunk {
(
format!(
@ -177,10 +181,10 @@ fn hunks_by_filepath(
// push the last hunk
if let Some(file_path) = current_file_path {
hunks_by_filepath.entry(file_path).or_default().push(Hunk {
old_start: current_old_start.unwrap(),
old_lines: current_old_lines.unwrap(),
new_start: current_new_start.unwrap(),
new_lines: current_new_lines.unwrap(),
old_start: current_old_start.unwrap_or_default(),
old_lines: current_old_lines.unwrap_or_default(),
new_start: current_new_start.unwrap_or_default(),
new_lines: current_new_lines.unwrap_or_default(),
diff: current_diff,
binary: current_binary,
});

View File

@ -593,10 +593,12 @@ pub fn list_virtual_branches(
let statuses = get_status_by_branch(gb_repository, project_repository)?;
for (branch, files) in &statuses {
dbg!(&files);
// check if head tree does not match target tree
// if so, we diff the head tree and the new write_tree output to see what is new and filter the hunks to just those
let vfiles =
calculate_non_commited_files(project_repository, branch, &default_target, files)?;
dbg!(&vfiles);
let repo = &project_repository.git_repository;
@ -1515,6 +1517,8 @@ fn get_applied_status(
.map(|branch| (branch.id, vec![]))
.collect();
dbg!(&hunks_by_filepath);
for branch in &mut virtual_branches {
if !branch.applied {
bail!("branch {} is not applied", branch.name);

View File

@ -294,7 +294,7 @@ mod conflicts {
.create_virtual_branch(&project_id, &BranchCreateRequest::default())
.await
.unwrap();
fs::write(repository.path().join("another_file.txt"), "virtual").unwrap();
fs::write(repository.path().join("another_file.txt"), "").unwrap();
let branches = controller.list_virtual_branches(&project_id).await.unwrap();
assert_eq!(branches.len(), 1);