Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(list): Pad arrow column for correct alignment

Maximilian Roos892b72a3f394
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index af3cff413..14d97166b 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -49,6 +49,10 @@ fn format_arrow_column(
// Reserve full space when behind is zero
segment.push_raw(" ".repeat(1 + widths.deleted_digits));
}
+
+ // Pad to total width if header is wider than data
+ // (e.g., "Commits" header = 7, but data "↓50" = 5)
+ segment.pad_to(widths.total);
} else {
segment.push_raw(" ".repeat(widths.total));
}
@@ -615,4 +619,38 @@ mod tests {
);
}
}
+
+ #[test]
+ fn test_arrow_column_with_header_wider_than_data() {
+ // Reproduces the actual bug: when header is wider than data
+ // - No ahead values (max_ahead_digits = 0)
+ // - Max behind is 50 (max_behind_digits = 2)
+ // - data_width = 1 + 0 + 1 + 1 + 2 = 5
+ // - header "Commits" = 7
+ // - total = max(5, 7) = 7
+ use super::super::layout::DiffWidths;
+ use super::format_arrow_column;
+ use worktrunk::styling::{ADDITION, DELETION};
+
+ let widths = DiffWidths {
+ total: 7, // To fit "Commits" header
+ added_digits: 0, // No ahead values
+ deleted_digits: 2, // Max behind is 50
+ };
+
+ let dim_deletion = DELETION.dimmed();
+
+ // Empty column should be 7 spaces
+ let empty = format_arrow_column(0, 0, &widths, ADDITION, dim_deletion);
+ assert_eq!(empty.width(), 7, "Empty column should be 7 spaces");
+
+ // Column with only behind should also be 7!
+ let behind_only = format_arrow_column(0, 50, &widths, ADDITION, dim_deletion);
+ assert_eq!(
+ behind_only.width(),
+ 7,
+ "Column with behind=50 should be 7 chars (currently {} - THIS IS THE BUG)",
+ behind_only.width()
+ );
+ }
}
diff --git a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
index 8ede48002..346e24235 100644
--- a/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__long_commit_message.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpbmtWq2/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpxMvUqA/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
Branch  Commits Path  Age  Commit  Message 
main  ./test-repo 10 months ago 1310bfb9 Short message
-feature-a ↓1 ./feature-a 10 months ago f078644e This is a very long commit message that should test how the message column handles...
+feature-a ↓1 ./feature-a 10 months ago f078644e This is a very long commit message that should test how the message column handles...
Showing 2 worktrees, 1 behind
diff --git a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
index fb975f2b0..b40df4ad0 100644
--- a/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
+++ b/tests/snapshots/integration__integration_tests__list__unicode_commit_message.snap
@@ -15,14 +15,14 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmp9GXdoj/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpYmyRj4/test-config.toml
---
success: true
exit_code: 0
----- stdout -----
Branch  Commits Path  Age  Commit  Message 
main  ./test-repo  10 months ago e4614cb7 Fix bug with café ☕ handling
-feature-test ↓1 ./feature-test 10 months ago 0c53695b Add support for 日本語 and émoji 🎉
+feature-test ↓1 ./feature-test 10 months ago 0c53695b Add support for 日本語 and émoji 🎉
Showing 2 worktrees, 1 behind