Skip to content

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

Refactor: Improve README age display examples

Maximilian Roos3f1011eac121
diff --git a/README.md b/README.md
index 08bf6d479..e38ab3175 100644
--- a/README.md
+++ b/README.md
@@ -64,9 +64,9 @@ merge, cleanup.
```console
$ wt list
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-@ main ^ ./repo ⇡0 ⇣0 b834638e 10mo Initial commit
-+ bugfix-y ↑ ↑1 ./repo.bugfix-y 412a27c8 10mo Fix bug
-+ feature-x + ↑ +5 ↑3 ./repo.feature-x 7fd821aa 10mo Add file 3
+@ main ^ ./repo ⇡0 ⇣0 f0879504 1d Initial commit
++ feature-x + ↑ +5 ↑3 ./repo.feature-x bf0292c8 1h Add file 3
++ bugfix-y ↑ ↑1 ./repo.bugfix-y 1c6de543 2h Fix bug
⚪ Showing 3 worktrees, 1 with changes, 2 ahead
```
@@ -932,11 +932,11 @@ git config worktrunk.status.feature-x "💬"
```console
$ wt list
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-@ main ^ ./repo b834638e 10mo Initial commit
-+ clean-no-status ∅ ./repo.clean-no-status b834638e 10mo Initial commit
-+ clean-with-status ∅ 💬 ./repo.clean-with-status b834638e 10mo Initial commit
-+ dirty-no-status ! +1 -1 ./repo.dirty-no-status b834638e 10mo Initial commit
-+ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status b834638e 10mo Initial commit
+@ main ^ ./repo f0879504 1d Initial commit
++ clean-no-status ∅ ./repo.clean-no-status f0879504 1d Initial commit
++ clean-with-status ∅ 💬 ./repo.clean-with-status f0879504 1d Initial commit
++ dirty-no-status ! +1 -1 ./repo.dirty-no-status f0879504 1d Initial commit
++ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status f0879504 1d Initial commit
⚪ Showing 5 worktrees, 1 with changes
```
@@ -961,11 +961,11 @@ When using Claude:
```console
$ wt list
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-@ main ^ ./repo b834638e 10mo Initial commit
-+ clean-no-status ∅ ./repo.clean-no-status b834638e 10mo Initial commit
-+ clean-with-status ∅ 💬 ./repo.clean-with-status b834638e 10mo Initial commit
-+ dirty-no-status ! +1 -1 ./repo.dirty-no-status b834638e 10mo Initial commit
-+ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status b834638e 10mo Initial commit
+@ main ^ ./repo f0879504 1d Initial commit
++ clean-no-status ∅ ./repo.clean-no-status f0879504 1d Initial commit
++ clean-with-status ∅ 💬 ./repo.clean-with-status f0879504 1d Initial commit
++ dirty-no-status ! +1 -1 ./repo.dirty-no-status f0879504 1d Initial commit
++ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status f0879504 1d Initial commit
⚪ Showing 5 worktrees, 1 with changes
```
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index ac6ac0d81..1326408c2 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -36,6 +36,12 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use tempfile::TempDir;
+/// Time constants for `commit_with_age()` - use as `5 * MINUTE`, `2 * HOUR`, etc.
+pub const MINUTE: i64 = 60;
+pub const HOUR: i64 = 60 * MINUTE;
+pub const DAY: i64 = 24 * HOUR;
+pub const WEEK: i64 = 7 * DAY;
+
/// Create a `wt` CLI command with standardized test environment settings.
///
/// The command has the following guarantees:
@@ -331,6 +337,87 @@ impl TestRepo {
.unwrap();
}
+ /// Create a commit with a specific age relative to SOURCE_DATE_EPOCH
+ ///
+ /// This allows creating commits that display specific relative ages
+ /// in the Age column (e.g., "10m", "1h", "1d").
+ ///
+ /// # Arguments
+ /// * `message` - The commit message
+ /// * `age_seconds` - How many seconds ago the commit should appear
+ ///
+ /// # Example
+ /// ```ignore
+ /// repo.commit_with_age("Initial commit", 86400); // Shows "1d"
+ /// repo.commit_with_age("Fix bug", 3600); // Shows "1h"
+ /// repo.commit_with_age("Add feature", 600); // Shows "10m"
+ /// ```
+ pub fn commit_with_age(&self, message: &str, age_seconds: i64) {
+ // SOURCE_DATE_EPOCH used in tests - must match configure_git_cmd/test_env_vars
+ const SOURCE_DATE_EPOCH: i64 = 1761609600;
+ let commit_time = SOURCE_DATE_EPOCH - age_seconds;
+ let timestamp = format!("@{}", commit_time);
+
+ // Use file.txt like commit() does - allows multiple commits to the same file
+ let file_path = self.root.join("file.txt");
+ std::fs::write(&file_path, message).unwrap();
+
+ self.git_command(&["add", "."]).output().unwrap();
+
+ // Create commit with custom timestamp
+ let mut cmd = Command::new("git");
+ cmd.env("GIT_CONFIG_GLOBAL", &self.git_config_path);
+ cmd.env("GIT_CONFIG_SYSTEM", "/dev/null");
+ cmd.env("GIT_AUTHOR_DATE", &timestamp);
+ cmd.env("GIT_COMMITTER_DATE", &timestamp);
+ cmd.env("LC_ALL", "C");
+ cmd.env("LANG", "C");
+ cmd.args(["commit", "-m", message])
+ .current_dir(&self.root)
+ .output()
+ .unwrap();
+ }
+
+ /// Create a commit with a specific age in a given directory (e.g., a worktree)
+ ///
+ /// Like `commit_with_age()` but for any git working directory.
+ /// Uses `file.txt` with the message as content for deterministic commits.
+ ///
+ /// # Example
+ /// ```ignore
+ /// let feature_wt = repo.add_worktree("feature", "feature");
+ /// repo.commit_with_age_in("Feature work", 2 * HOUR, &feature_wt);
+ /// ```
+ pub fn commit_with_age_in(&self, message: &str, age_seconds: i64, dir: &Path) {
+ // SOURCE_DATE_EPOCH used in tests - must match configure_git_cmd/test_env_vars
+ const SOURCE_DATE_EPOCH: i64 = 1761609600;
+ let commit_time = SOURCE_DATE_EPOCH - age_seconds;
+ let timestamp = format!("@{}", commit_time);
+
+ // Use file.txt with message as content - deterministic for same message
+ let file_path = dir.join("file.txt");
+ std::fs::write(&file_path, message).unwrap();
+
+ // Stage the file
+ let mut cmd = Command::new("git");
+ cmd.env("GIT_CONFIG_GLOBAL", &self.git_config_path);
+ cmd.env("GIT_CONFIG_SYSTEM", "/dev/null");
+ cmd.args(["add", "."]).current_dir(dir).output().unwrap();
+
+ // Create commit with custom timestamp
+ let mut cmd = Command::new("git");
+ cmd.env("GIT_CONFIG_GLOBAL", &self.git_config_path);
+ cmd.env("GIT_CONFIG_SYSTEM", "/dev/null");
+ cmd.env("GIT_AUTHOR_DATE", &timestamp);
+ cmd.env("GIT_COMMITTER_DATE", &timestamp);
+ cmd.env("LC_ALL", "C");
+ cmd.env("LANG", "C");
+ cmd.args(["commit", "-m", message])
+ .current_dir(dir)
+ .output()
+ .unwrap();
+ }
+
/// Add a worktree with the given name and branch
///
/// The worktree path follows the default template format: `repo.{branch}`
@@ -974,6 +1061,23 @@ pub fn wait_for_file_lines(path: &Path, expected_lines: usize, timeout: std::tim
mod tests {
use super::*;
+ #[test]
+ fn test_commit_with_age() {
+ let repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Create commits with specific ages
+ repo.commit_with_age("One hour ago", HOUR);
+ repo.commit_with_age("One day ago", DAY);
+ repo.commit_with_age("One week ago", WEEK);
+ repo.commit_with_age("Ten minutes ago", 10 * MINUTE);
+
+ // Verify commits were created (git log shows 5 commits)
+ let output = repo.git_command(&["log", "--oneline"]).output().unwrap();
+ let log = String::from_utf8_lossy(&output.stdout);
+ assert_eq!(log.lines().count(), 5);
+ }
+
#[test]
fn test_validate_ansi_codes_no_leak() {
// Good - no nesting
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 4f946dee0..a678a5751 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -1,4 +1,4 @@
-use crate::common::{TestRepo, list_snapshots, setup_snapshot_settings, wt_command};
+use crate::common::{DAY, HOUR, TestRepo, list_snapshots, setup_snapshot_settings, wt_command};
use insta::Settings;
use insta_cmd::assert_cmd_snapshot;
use std::path::Path;
@@ -709,7 +709,7 @@ fn test_list_primary_on_different_branch() {
#[test]
fn test_list_with_user_status() {
let mut repo = TestRepo::new();
- repo.commit("Initial commit");
+ repo.commit_with_age("Initial commit", DAY);
// Worktree with user status only (no git changes)
repo.add_worktree("clean-with-status");
@@ -749,7 +749,7 @@ fn test_list_with_user_status() {
#[test]
fn test_list_json_with_user_status() {
let mut repo = TestRepo::new();
- repo.commit("Initial commit");
+ repo.commit_with_age("Initial commit", DAY);
// Worktree with user status (emoji only)
repo.add_worktree("with-status");
@@ -828,35 +828,20 @@ fn test_list_user_status_with_special_characters() {
#[test]
fn test_readme_example_simple_list() {
let mut repo = TestRepo::new();
- repo.commit("Initial commit");
+ // Initial commit on main - oldest (1 day ago)
+ repo.commit_with_age("Initial commit", DAY);
repo.setup_remote("main");
// Create worktrees with various states
let feature_x = repo.add_worktree("feature-x");
let bugfix_y = repo.add_worktree("bugfix-y");
- // feature-x: ahead with uncommitted changes
- // Make 3 commits
- for i in 1..=3 {
- std::fs::write(
- feature_x.join(format!("file{}.txt", i)),
- format!("content {}", i),
- )
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", &format!("file{}.txt", i)])
- .current_dir(&feature_x)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", &format!("Add file {}", i)])
- .current_dir(&feature_x)
- .output()
- .unwrap();
- }
- // Add unstaged changes (+5 -2 lines)
+ // feature-x: ahead with uncommitted changes (3 commits, most recent 10min ago)
+ repo.commit_with_age_in("Add file 1", 3 * HOUR, &feature_x);
+ repo.commit_with_age_in("Add file 2", 2 * HOUR, &feature_x);
+ repo.commit_with_age_in("Add file 3", HOUR, &feature_x);
+
+ // Add staged changes (+5 lines)
std::fs::write(
feature_x.join("modified.txt"),
"line1\nline2\nline3\nline4\nline5\n",
@@ -869,20 +854,8 @@ fn test_readme_example_simple_list() {
.output()
.unwrap();
- // bugfix-y: 1 commit ahead, clean tree
- std::fs::write(bugfix_y.join("bugfix.txt"), "fix content").unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["add", "bugfix.txt"])
- .current_dir(&bugfix_y)
- .output()
- .unwrap();
- let mut cmd = Command::new("git");
- repo.configure_git_cmd(&mut cmd);
- cmd.args(["commit", "-m", "Fix bug"])
- .current_dir(&bugfix_y)
- .output()
- .unwrap();
+ // bugfix-y: 1 commit ahead (2 hours ago), clean tree
+ repo.commit_with_age_in("Fix bug", 2 * HOUR, &bugfix_y);
snapshot_list("readme_example_simple_list", &repo);
}
diff --git a/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap b/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
index 7c5220e28..4ef4901dd 100644
--- a/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
+++ b/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
@@ -24,7 +24,7 @@ exit_code: 0
----- stdout -----
[
{
- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",
+ "head_sha": "f0879504ee3d7dc97723a75c22712f27b604be74",
"branch": "main",
"timestamp": 0,
"commit_message": "Initial commit",
@@ -76,7 +76,7 @@ exit_code: 0
"is_current": true
},
{
- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",
+ "head_sha": "f0879504ee3d7dc97723a75c22712f27b604be74",
"branch": "with-status",
"timestamp": 0,
"commit_message": "Initial commit",
@@ -129,7 +129,7 @@ exit_code: 0
"is_main": false
},
{
- "head_sha": "b834638e33dbc6b37002685ee0777f4b8f1af904",
+ "head_sha": "f0879504ee3d7dc97723a75c22712f27b604be74",
"branch": "without-status",
"timestamp": 0,
"commit_message": "Initial commit",
diff --git a/tests/snapshots/integration__integration_tests__list__readme_example_simple_list.snap b/tests/snapshots/integration__integration_tests__list__readme_example_simple_list.snap
index afab99e29..fade4466a 100644
--- a/tests/snapshots/integration__integration_tests__list__readme_example_simple_list.snap
+++ b/tests/snapshots/integration__integration_tests__list__readme_example_simple_list.snap
@@ -24,8 +24,8 @@ exit_code: 0
----- stderr -----
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-@ main ^ ./repo ⇡0 ⇣0 b834638e 10mo Initial commit
-+ bugfix-y ↑ ↑1 ./repo.bugfix-y 412a27c8 10mo Fix bug
-+ feature-x + ↑ +5 ↑3 ./repo.feature-x 7fd821aa 10mo Add file 3
+@ main ^ ./repo ⇡0 ⇣0 f0879504 1d Initial commit
++ feature-x + ↑ +5 ↑3 ./repo.feature-x bf0292c8 1h Add file 3
++ bugfix-y ↑ ↑1 ./repo.bugfix-y 1c6de543 2h Fix bug
⚪ Showing 3 worktrees, 1 with changes, 2 ahead
diff --git a/tests/snapshots/integration__integration_tests__list__with_user_status.snap b/tests/snapshots/integration__integration_tests__list__with_user_status.snap
index f67723ed2..6ed98d6ef 100644
--- a/tests/snapshots/integration__integration_tests__list__with_user_status.snap
+++ b/tests/snapshots/integration__integration_tests__list__with_user_status.snap
@@ -24,10 +24,10 @@ exit_code: 0
----- stderr -----
Branch Status HEAD± main↕ Path Remote⇅ Commit Age Message
-@ main ^ ./repo b834638e 10mo Initial commit
-+ clean-no-status ∅ ./repo.clean-no-status b834638e 10mo Initial commit
-+ clean-with-status ∅ 💬 ./repo.clean-with-status b834638e 10mo Initial commit
-+ dirty-no-status ! +1 -1 ./repo.dirty-no-status b834638e 10mo Initial commit
-+ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status b834638e 10mo Initial commit
+@ main ^ ./repo f0879504 1d Initial commit
++ clean-no-status ∅ ./repo.clean-no-status f0879504 1d Initial commit
++ clean-with-status ∅ 💬 ./repo.clean-with-status f0879504 1d Initial commit
++ dirty-no-status ! +1 -1 ./repo.dirty-no-status f0879504 1d Initial commit
++ dirty-with-status ?∅ 🤖 ./repo.dirty-with-status f0879504 1d Initial commit
⚪ Showing 5 worktrees, 1 with changes