Skip to content

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

feat: add URL to statusline output (#414)

Maximilian Roos9c1b00b2c987
diff --git a/src/commands/list/model.rs b/src/commands/list/model.rs
index 0c27a98d0..830c665bb 100644
--- a/src/commands/list/model.rs
+++ b/src/commands/list/model.rs
@@ -436,6 +436,11 @@ impl ListItem {
parts.push(pr_status.format_indicator_with_options(include_links));
}
+ // 8. URL (from project config template)
+ if let Some(ref url) = self.url {
+ parts.push(url.clone());
+ }
+
parts.join(" ")
}
diff --git a/src/commands/statusline.rs b/src/commands/statusline.rs
index de9fa6bb5..db101aee0 100644
--- a/src/commands/statusline.rs
+++ b/src/commands/statusline.rs
@@ -11,6 +11,7 @@ use anyhow::{Context, Result};
use std::env;
use std::io::{self, Read};
use std::path::Path;
+use worktrunk::config::ProjectConfig;
use worktrunk::git::{Repository, Worktree};
use super::list::{self, CollectOptions};
@@ -243,16 +244,25 @@ fn get_git_status(repo: &Repository, cwd: &Path, include_links: bool) -> Result<
// Build item with identity fields
let mut item = list::build_worktree_item(wt, is_home, true, false);
+ // Load URL template from project config (if configured)
+ let url_template = repo
+ .worktree_root()
+ .ok()
+ .and_then(|root| ProjectConfig::load(root).ok().flatten())
+ .and_then(|config| config.list)
+ .and_then(|list| list.url);
+
+ // Build collect options with URL template
+ let options = CollectOptions {
+ url_template,
+ ..Default::default()
+ };
+
// Populate computed fields (parallel git operations) and format status_line
// Compute everything (same as --full) for complete status symbols
// Pass default_branch for stable informational stats,
// and integration_target for integration status checks.
- list::populate_item(
- &mut item,
- &default_branch,
- &integration_target,
- CollectOptions::default(),
- )?;
+ list::populate_item(&mut item, &default_branch, &integration_target, options)?;
// Format statusline with link control
let statusline = item.format_statusline_with_options(include_links);
diff --git a/tests/integration_tests/statusline.rs b/tests/integration_tests/statusline.rs
index f4507e11c..e40b6fa3c 100644
--- a/tests/integration_tests/statusline.rs
+++ b/tests/integration_tests/statusline.rs
@@ -276,3 +276,42 @@ fn test_statusline_detached_head(mut repo: TestRepo) {
"statusline should not show 'feature' in detached HEAD, got: {output}"
);
}
+
+// --- URL Display Tests ---
+
+/// Test that statusline shows URL when project config has URL template.
+#[rstest]
+fn test_statusline_with_url(repo: TestRepo) {
+ // Configure URL template with simple branch variable (no hash_port for deterministic output)
+ repo.write_project_config(
+ r#"[list]
+url = "http://{{ branch }}.localhost:3000"
+"#,
+ );
+
+ let output = run_statusline(&repo, &[], None);
+ // Shows `?` because writing project config creates uncommitted file
+ assert_snapshot!(output, @" main ?^ http://main.localhost:3000");
+}
+
+/// Test that statusline URL uses branch name in feature worktree.
+#[rstest]
+fn test_statusline_url_in_feature_worktree(mut repo: TestRepo) {
+ // Configure URL template with simple branch variable
+ repo.write_project_config(
+ r#"[list]
+url = "http://{{ branch }}.localhost:3000"
+"#,
+ );
+
+ // Commit the project config so it's visible in worktrees
+ repo.run_git(&["add", ".config/wt.toml"]);
+ repo.run_git(&["commit", "-m", "Add project config"]);
+
+ // Create feature worktree
+ let feature_path = repo.add_worktree("feature");
+
+ // Run statusline from feature worktree
+ let output = run_statusline_from_dir(&repo, &[], None, &feature_path);
+ assert_snapshot!(output, @" feature _ http://feature.localhost:3000");
+}