Skip to content

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

feat: Display user-defined status in list output

Maximilian Roos0696cb14761e
diff --git a/src/commands/list/layout.rs b/src/commands/list/layout.rs
index 04936b145..7ae6080c9 100644
--- a/src/commands/list/layout.rs
+++ b/src/commands/list/layout.rs
@@ -398,11 +398,10 @@ pub fn calculate_column_widths(
// Branch name
max_branch = max_branch.max(item.branch_name().width());
- // Status symbols (worktrees only)
- if let Some(info) = worktree_info
- && !info.status_symbols.is_empty()
- {
- max_status = max_status.max(info.status_symbols.width());
+ // Status column: git status symbols + user-defined status (worktrees only)
+ if let Some(info) = worktree_info {
+ let combined_width = info.combined_status().width();
+ max_status = max_status.max(combined_width);
}
// Time
@@ -694,6 +693,7 @@ mod tests {
pr_status: None,
has_conflicts: false,
status_symbols: String::new(),
+ user_status: None,
display: DisplayFields::default(),
working_diff_display: None,
};
@@ -769,6 +769,7 @@ mod tests {
pr_status: None,
has_conflicts: false,
status_symbols: String::new(),
+ user_status: None,
display: DisplayFields::default(),
working_diff_display: None,
};
@@ -843,6 +844,7 @@ mod tests {
pr_status: None,
has_conflicts: false,
status_symbols: String::new(),
+ user_status: None,
display: DisplayFields::default(),
working_diff_display: None,
};
@@ -908,6 +910,7 @@ mod tests {
pr_status: None,
has_conflicts: false,
status_symbols: String::new(),
+ user_status: None,
display: DisplayFields::default(),
working_diff_display: None,
};
diff --git a/src/commands/list/model.rs b/src/commands/list/model.rs
index 81b8135cc..6bd16330b 100644
--- a/src/commands/list/model.rs
+++ b/src/commands/list/model.rs
@@ -43,6 +43,9 @@ pub struct WorktreeInfo {
pub has_conflicts: bool,
/// Git status symbols (=, ↑, ↓, ⇡, ⇣, ?, !, +, », ✘) indicating working tree state
pub status_symbols: String,
+ /// User-defined status from worktrunk.status git config
+ #[serde(skip_serializing_if = "Option::is_none")]
+ pub user_status: Option<String>,
// Display fields for json-pretty format (with ANSI colors)
#[serde(flatten)]
@@ -173,6 +176,7 @@ impl UpstreamStatus {
/// Unified type for displaying worktrees and branches in the same table
#[derive(serde::Serialize)]
#[serde(tag = "type", rename_all = "lowercase")]
+#[allow(clippy::large_enum_variant)]
pub enum ListItem {
Worktree(WorktreeInfo),
Branch(BranchInfo),
@@ -310,6 +314,14 @@ impl BranchInfo {
}
}
+/// Read user-defined status from worktrunk.status git config
+fn read_user_status(repo: &Repository) -> Option<String> {
+ repo.run_command(&["config", "--worktree", "--get", "worktrunk.status"])
+ .ok()
+ .map(|output| output.trim().to_string())
+ .filter(|s| !s.is_empty())
+}
+
/// Git status information parsed from `git status --porcelain`
// TODO: Consider using a struct with bool fields instead of String for symbols
// (has_untracked, has_modified, has_staged, has_renamed, has_deleted, has_conflicts,
@@ -519,6 +531,9 @@ impl WorktreeInfo {
false
};
+ // Read user-defined status from git config
+ let user_status = read_user_status(&wt_repo);
+
Ok(WorktreeInfo {
worktree: wt.clone(),
commit,
@@ -532,10 +547,27 @@ impl WorktreeInfo {
pr_status,
has_conflicts,
status_symbols: status_info.symbols,
+ user_status,
display: DisplayFields::default(),
working_diff_display: None,
})
}
+
+ /// Combine git status symbols and user-defined status
+ /// Returns the combined string with a space separator if both are present
+ pub fn combined_status(&self) -> String {
+ if !self.status_symbols.is_empty() {
+ if let Some(ref user_status) = self.user_status {
+ format!("{} {}", self.status_symbols, user_status)
+ } else {
+ self.status_symbols.clone()
+ }
+ } else if let Some(ref user_status) = self.user_status {
+ user_status.clone()
+ } else {
+ String::new()
+ }
+ }
}
/// Gather list data (worktrees + optional branches).
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 36ebdfbd0..566a85f2e 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -356,9 +356,9 @@ pub fn format_list_item_line(
}
}
(ColumnKind::Status, _) => {
- // Determine status content: actual symbols or middle dot indicator for branch-only entries
+ // Combine git status symbols + user-defined status from worktrunk.status
let status_content = if let Some(info) = worktree_info {
- info.status_symbols.clone()
+ info.combined_status()
} else {
"·".to_string()
};
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index 07a58fe3c..9e96ec0c9 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -612,3 +612,136 @@ fn test_list_primary_on_different_branch() {
snapshot_list("list_primary_on_different_branch", &repo);
}
+
+#[test]
+fn test_list_with_user_status() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Worktree with user status only (no git changes)
+ let clean_wt = repo.add_worktree("clean-with-status", "clean-with-status");
+
+ // Enable worktree config
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "extensions.worktreeConfig", "true"])
+ .current_dir(&clean_wt)
+ .output()
+ .expect("Failed to enable worktree config");
+
+ // Set user status
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "--worktree", "worktrunk.status", "waiting"])
+ .current_dir(&clean_wt)
+ .output()
+ .expect("Failed to set user status");
+
+ // Worktree with both git status and user status
+ let dirty_wt = repo.add_worktree("dirty-with-status", "dirty-with-status");
+
+ // Enable worktree config
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "extensions.worktreeConfig", "true"])
+ .current_dir(&dirty_wt)
+ .output()
+ .expect("Failed to enable worktree config");
+
+ // Set user status
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "--worktree", "worktrunk.status", "*"])
+ .current_dir(&dirty_wt)
+ .output()
+ .expect("Failed to set user status");
+
+ // Add uncommitted changes
+ std::fs::write(dirty_wt.join("new.txt"), "content").expect("Failed to write file");
+
+ // Worktree with git status only (no user status)
+ let dirty_no_status_wt = repo.add_worktree("dirty-no-status", "dirty-no-status");
+ std::fs::write(dirty_no_status_wt.join("file.txt"), "content").expect("Failed to write file");
+
+ // Worktree with neither (control)
+ repo.add_worktree("clean-no-status", "clean-no-status");
+
+ snapshot_list("with_user_status", &repo);
+}
+
+#[test]
+fn test_list_json_with_user_status() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Worktree with user status
+ let with_status_wt = repo.add_worktree("with-status", "with-status");
+
+ // Enable worktree config
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "extensions.worktreeConfig", "true"])
+ .current_dir(&with_status_wt)
+ .output()
+ .expect("Failed to enable worktree config");
+
+ // Set user status
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "--worktree", "worktrunk.status", "processing..."])
+ .current_dir(&with_status_wt)
+ .output()
+ .expect("Failed to set user status");
+
+ // Worktree without user status
+ repo.add_worktree("without-status", "without-status");
+
+ snapshot_list_json("json_with_user_status", &repo);
+}
+
+#[test]
+fn test_list_user_status_with_special_characters() {
+ let mut repo = TestRepo::new();
+ repo.commit("Initial commit");
+
+ // Test with emoji
+ let emoji_wt = repo.add_worktree("emoji", "emoji");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "extensions.worktreeConfig", "true"])
+ .current_dir(&emoji_wt)
+ .output()
+ .expect("Failed to enable worktree config");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "--worktree", "worktrunk.status", "🔄"])
+ .current_dir(&emoji_wt)
+ .output()
+ .expect("Failed to set user status");
+
+ // Test with multiple characters
+ let multi_wt = repo.add_worktree("multi", "multi");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args(["config", "extensions.worktreeConfig", "true"])
+ .current_dir(&multi_wt)
+ .output()
+ .expect("Failed to enable worktree config");
+
+ let mut cmd = Command::new("git");
+ repo.configure_git_cmd(&mut cmd);
+ cmd.args([
+ "config",
+ "--worktree",
+ "worktrunk.status",
+ "blocked: needs review",
+ ])
+ .current_dir(&multi_wt)
+ .output()
+ .expect("Failed to set user status");
+
+ snapshot_list("user_status_special_chars", &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
new file mode 100644
index 000000000..aa5853cb7
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__list__json_with_user_status.snap
@@ -0,0 +1,136 @@
+---
+source: tests/integration_tests/list.rs
+info:
+ program: wt
+ args:
+ - list
+ - "--format=json"
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpRF2nse/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+[
+ {
+ "type": "worktree",
+ "worktree": {
+ "path": "[REPO]",
+ "head": "[SHA]",
+ "branch": "main",
+ "bare": false,
+ "detached": false,
+ "locked": null,
+ "prunable": null
+ },
+ "timestamp": 0,
+ "commit_message": "Initial commit",
+ "ahead": 0,
+ "behind": 0,
+ "working_tree_diff": [
+ 0,
+ 0
+ ],
+ "working_tree_diff_with_main": [
+ 0,
+ 0
+ ],
+ "branch_diff": [
+ 0,
+ 0
+ ],
+ "is_primary": true,
+ "upstream_remote": null,
+ "upstream_ahead": 0,
+ "upstream_behind": 0,
+ "worktree_state": null,
+ "pr_status": null,
+ "has_conflicts": false,
+ "status_symbols": ""
+ },
+ {
+ "type": "worktree",
+ "worktree": {
+ "path": "[WORKTREE_WITH_STATUS]",
+ "head": "[SHA]",
+ "branch": "with-status",
+ "bare": false,
+ "detached": false,
+ "locked": null,
+ "prunable": null
+ },
+ "timestamp": 0,
+ "commit_message": "Initial commit",
+ "ahead": 0,
+ "behind": 0,
+ "working_tree_diff": [
+ 0,
+ 0
+ ],
+ "working_tree_diff_with_main": [
+ 0,
+ 0
+ ],
+ "branch_diff": [
+ 0,
+ 0
+ ],
+ "is_primary": false,
+ "upstream_remote": null,
+ "upstream_ahead": 0,
+ "upstream_behind": 0,
+ "worktree_state": null,
+ "pr_status": null,
+ "has_conflicts": false,
+ "status_symbols": "",
+ "user_status": "processing..."
+ },
+ {
+ "type": "worktree",
+ "worktree": {
+ "path": "[WORKTREE_WITHOUT_STATUS]",
+ "head": "[SHA]",
+ "branch": "without-status",
+ "bare": false,
+ "detached": false,
+ "locked": null,
+ "prunable": null
+ },
+ "timestamp": 0,
+ "commit_message": "Initial commit",
+ "ahead": 0,
+ "behind": 0,
+ "working_tree_diff": [
+ 0,
+ 0
+ ],
+ "working_tree_diff_with_main": [
+ 0,
+ 0
+ ],
+ "branch_diff": [
+ 0,
+ 0
+ ],
+ "is_primary": false,
+ "upstream_remote": null,
+ "upstream_ahead": 0,
+ "upstream_behind": 0,
+ "worktree_state": null,
+ "pr_status": null,
+ "has_conflicts": false,
+ "status_symbols": ""
+ }
+]
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__list__user_status_special_chars.snap b/tests/snapshots/integration__integration_tests__list__user_status_special_chars.snap
new file mode 100644
index 000000000..3a9c2413e
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__list__user_status_special_chars.snap
@@ -0,0 +1,30 @@
+---
+source: tests/integration_tests/list.rs
+info:
+ program: wt
+ args:
+ - list
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpCBPe6p/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+Branch Status  Working ± Main ↕ State  Path  Remote ↕ Commit  Age  Message
+main  ./test-repo b834638e 10 months ago Initial commit
+emoji  🔄 (matches main) ./emoji  b834638e 10 months ago Initial commit
+multi  blocked: needs review (matches main) ./multi  b834638e 10 months ago Initial commit
+
+⚪ Showing 3 worktrees
+
+----- stderr -----
diff --git a/tests/snapshots/integration__integration_tests__list__with_user_status.snap b/tests/snapshots/integration__integration_tests__list__with_user_status.snap
new file mode 100644
index 000000000..44474b16c
--- /dev/null
+++ b/tests/snapshots/integration__integration_tests__list__with_user_status.snap
@@ -0,0 +1,32 @@
+---
+source: tests/integration_tests/list.rs
+info:
+ program: wt
+ args:
+ - list
+ env:
+ CLICOLOR_FORCE: "1"
+ COLUMNS: "150"
+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_CONFIG_GLOBAL: /dev/null
+ GIT_CONFIG_SYSTEM: /dev/null
+ GIT_EDITOR: ""
+ LANG: C
+ LC_ALL: C
+ SOURCE_DATE_EPOCH: "1761609600"
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmppsaSps/test-config.toml
+---
+success: true
+exit_code: 0
+----- stdout -----
+Branch  Status  Working ± Main ↕ State  Path  Remote ↕ Commit  Age  Message
+main  ./test-repo  b834638e 10 months ago Initial commit
+clean-no-status  (matches main) ./clean-no-status  b834638e 10 months ago Initial commit
+clean-with-status waiting (matches main) ./clean-with-status b834638e 10 months ago Initial commit
+dirty-no-status ! +1 -1 ./dirty-no-status b834638e 10 months ago Initial commit
+dirty-with-status ? * (matches main) ./dirty-with-status b834638e 10 months ago Initial commit
+
+⚪ Showing 5 worktrees, 1 with changes
+
+----- stderr -----