Skip to content

Commit e418fb9

Browse files
authored
Merge pull request #12362 from Byron/fix3
Fix absorb file count by deduplicating it
2 parents db2611f + 0c2f505 commit e418fb9

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

crates/but/src/command/legacy/absorb.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use gitbutler_oplog::{
1010
OplogExt,
1111
entry::{OperationKind, SnapshotDetails},
1212
};
13+
use itertools::Itertools;
1314

1415
use crate::{CliId, IdMap, command::legacy::rub::parse_sources, id::UncommittedCliId, utils::OutputChannel};
1516
/// Amends changes into the appropriate commits where they belong.
@@ -188,7 +189,11 @@ fn display_absorption_plan(
188189
write_json: bool,
189190
) -> anyhow::Result<Option<JsonAbsorbOutput>> {
190191
// Count total files
191-
let total_files: usize = commit_absorptions.iter().map(|c| c.files.len()).sum();
192+
let total_files: usize = commit_absorptions
193+
.iter()
194+
.flat_map(|c| c.files.iter().map(|f| &f.path))
195+
.unique()
196+
.count();
192197

193198
// Handle empty case
194199
if commit_absorptions.is_empty() || total_files == 0 {

crates/but/tests/but/command/absorb.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn uncommitted_file() -> anyhow::Result<()> {
3434
.assert()
3535
.success()
3636
.stdout_eq(snapbox::str![[r#"
37-
Found 2 changed files to absorb:
37+
Found 1 changed file to absorb:
3838
3939
Absorbed to commit: f4ea7f8 a.txt
4040
(files locked to commit due to hunk range overlap)
@@ -309,7 +309,7 @@ Hint: run `but diff` to see uncommitted changes and `but stage <file>` to stage
309309
.assert()
310310
.success()
311311
.stdout_eq(snapbox::str![[r#"
312-
Found 2 changed files to absorb:
312+
Found 1 changed file to absorb:
313313
314314
Absorbed to commit: 889385c partial change to a.txt 2
315315
(files locked to commit due to hunk range overlap)
@@ -403,7 +403,7 @@ fn uncommitted_file_new() -> anyhow::Result<()> {
403403
.assert()
404404
.success()
405405
.stdout_eq(snapbox::str![[r#"
406-
Found 2 changed files to absorb:
406+
Found 1 changed file to absorb:
407407
408408
Created on top of commit: f4ea7f8 a.txt
409409
(files locked to commit due to hunk range overlap)
@@ -624,7 +624,7 @@ fn dry_run_new_shows_plan_without_changes() -> anyhow::Result<()> {
624624
.assert()
625625
.success()
626626
.stdout_eq(snapbox::str![[r#"
627-
Found 2 changed files to absorb:
627+
Found 1 changed file to absorb:
628628
629629
Created on top of commit: f4ea7f8 a.txt
630630
(files locked to commit due to hunk range overlap)
@@ -695,7 +695,7 @@ fn dry_run_shows_plan_without_changes() -> anyhow::Result<()> {
695695
.assert()
696696
.success()
697697
.stdout_eq(snapbox::str![[r#"
698-
Found 2 changed files to absorb:
698+
Found 1 changed file to absorb:
699699
700700
Absorbed to commit: f4ea7f8 a.txt
701701
(files locked to commit due to hunk range overlap)

0 commit comments

Comments
 (0)