Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
Standardize enum serialization to kebab-case
Maximilian Roosaf1868aa6a3d
diff --git a/src/cli.rs b/src/cli.rsindex 3ec139217..710ba1d3d 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -724,7 +724,7 @@ wt config state previous-branch set featurepub enum CiStatusAction {/// Get CI status for a branch#[command(- after_long_help = r#"Returns: passed, running, failed, conflicts, noci, or error.+ after_long_help = r#"Returns: passed, running, failed, conflicts, no-ci, or error.## Examplesdiff --git a/src/commands/config.rs b/src/commands/config.rsindex f68a3f95e..3a8c9b93b 100644--- a/src/commands/config.rs+++ b/src/commands/config.rs@@ -657,22 +657,10 @@ pub fn handle_state_get(key: &str, refresh: bool, branch: Option<String>) -> any}let has_upstream = repo.upstream_branch(&branch_name).ok().flatten().is_some();- match PrStatus::detect(&branch_name, &head, &repo_root, has_upstream) {- Some(status) => {- let status_str = match status.ci_status {- super::list::ci_status::CiStatus::Passed => "passed",- super::list::ci_status::CiStatus::Running => "running",- super::list::ci_status::CiStatus::Failed => "failed",- super::list::ci_status::CiStatus::Conflicts => "conflicts",- super::list::ci_status::CiStatus::NoCI => "noci",- super::list::ci_status::CiStatus::Error => "error",- };- crate::output::data(status_str)?;- }- None => {- crate::output::data("noci")?;- }- }+ let ci_status = PrStatus::detect(&branch_name, &head, &repo_root, has_upstream)+ .map_or(super::list::ci_status::CiStatus::NoCI, |s| s.ci_status);+ let status_str: &'static str = ci_status.into();+ crate::output::data(status_str)?;}"logs" => {let git_common_dir = repo.git_common_dir()?;diff --git a/src/commands/hooks.rs b/src/commands/hooks.rsindex 3e0b9245d..8d11f3be9 100644--- a/src/commands/hooks.rs+++ b/src/commands/hooks.rs@@ -36,6 +36,8 @@ pub enum HookFailureStrategy {////// Approval for project hooks is handled at the gate (command entry point),/// not during hook execution.+#[derive(strum::Display)]+#[strum(serialize_all = "kebab-case")]pub enum HookSource {/// User hooks from ~/.config/worktrunk/config.toml (no approval required)User,@@ -44,17 +46,9 @@ pub enum HookSource {}impl HookSource {- /// Returns the label prefix for this source- fn label_prefix(&self) -> &'static str {- match self {- HookSource::User => "user",- HookSource::Project => "project",- }- }-/// Format a label for display: "user pre-merge" or "project pre-merge"fn format_label(&self, hook_type: HookType) -> String {- format!("{} {}", self.label_prefix(), hook_type)+ format!("{} {}", self, hook_type)}}@@ -215,7 +209,7 @@ impl<'a> HookPipeline<'a> {let name = prepared.name.as_deref().unwrap_or("cmd");// Include source in operation name to prevent log file collisions between// user and project hooks with the same name- let operation = format!("{}-{}-{}", source.label_prefix(), operation_prefix, name);+ let operation = format!("{}-{}-{}", source, operation_prefix, name);if let Err(err) = spawn_detached(self.ctx.repo,self.ctx.worktree_path,@@ -341,9 +335,9 @@ mod tests {use super::*;#[test]- fn test_hook_source_label_prefix() {- assert_eq!(HookSource::User.label_prefix(), "user");- assert_eq!(HookSource::Project.label_prefix(), "project");+ fn test_hook_source_display() {+ assert_eq!(HookSource::User.to_string(), "user");+ assert_eq!(HookSource::Project.to_string(), "project");}#[test]diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rsindex ad3b85368..76422b65e 100644--- a/src/commands/list/ci_status.rs+++ b/src/commands/list/ci_status.rs@@ -936,8 +936,9 @@ fn is_retriable_error(stderr: &str) -> bool {/// - Conflicts: Yellow (merge conflicts)/// - NoCI: Gray (no PR/checks)/// - Error: Yellow (CI fetch failed, e.g., rate limit)-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]-#[serde(rename_all = "lowercase")]+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, strum::IntoStaticStr)]+#[serde(rename_all = "kebab-case")]+#[strum(serialize_all = "kebab-case")]pub enum CiStatus {Passed,Running,@@ -954,8 +955,9 @@ pub enum CiStatus {/// The internal distinction (CiSource::PullRequest vs CiSource::Branch) is preserved/// for potential future visual differentiation. We tried ◒ (half circle) for branch CI/// but it renders narrower than ● in many terminal fonts, causing misalignment.-#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]-#[serde(rename_all = "lowercase")]+#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, strum::IntoStaticStr)]+#[serde(rename_all = "kebab-case")]+#[strum(serialize_all = "kebab-case")]pub enum CiSource {/// Pull request or merge requestPullRequest,diff --git a/src/commands/list/collect.rs b/src/commands/list/collect.rsindex 93c65dba4..055f64f21 100644--- a/src/commands/list/collect.rs+++ b/src/commands/list/collect.rs@@ -58,7 +58,7 @@ struct StatusContext {name(TaskKind),vis(pub),derive(Hash, strum::IntoStaticStr),- strum(serialize_all = "snake_case")+ strum(serialize_all = "kebab-case"))]pub(super) enum TaskResult {/// Commit timestamp and messagediff --git a/src/commands/list/json_output.rs b/src/commands/list/json_output.rsindex abddd2d2d..ac8cf816e 100644--- a/src/commands/list/json_output.rs+++ b/src/commands/list/json_output.rs@@ -400,25 +400,9 @@ fn worktree_state_to_json(/// Convert PrStatus to JsonPrfn pr_status_to_json(pr: &PrStatus) -> JsonPr {- use super::ci_status::{CiSource, CiStatus};-- let ci = match pr.ci_status {- CiStatus::Passed => "passed",- CiStatus::Running => "running",- CiStatus::Failed => "failed",- CiStatus::Conflicts => "conflicts",- CiStatus::NoCI => "no_ci",- CiStatus::Error => "error",- };-- let source = match pr.source {- CiSource::PullRequest => "pull_request",- CiSource::Branch => "branch",- };-JsonPr {- ci,- source,+ ci: pr.ci_status.into(),+ source: pr.source.into(),stale: pr.is_stale,url: pr.url.clone(),}@@ -522,7 +506,7 @@ mod tests {};let json = pr_status_to_json(&pr);assert_eq!(json.ci, "passed");- assert_eq!(json.source, "pull_request");+ assert_eq!(json.source, "pull-request");assert!(!json.stale);assert_eq!(json.url,@@ -578,7 +562,7 @@ mod tests {url: None,};let json = pr_status_to_json(&pr);- assert_eq!(json.ci, "no_ci");+ assert_eq!(json.ci, "no-ci");}#[test]diff --git a/src/commands/list/model.rs b/src/commands/list/model.rsindex 1f9b17477..b10b3b9c4 100644--- a/src/commands/list/model.rs+++ b/src/commands/list/model.rs@@ -940,8 +940,8 @@ impl serde::Serialize for OperationState {////// Represents whether a worktree is in the middle of a git operation.#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, serde::Serialize, strum::IntoStaticStr)]-#[serde(rename_all = "lowercase")]-#[strum(serialize_all = "lowercase")]+#[serde(rename_all = "kebab-case")]+#[strum(serialize_all = "kebab-case")]pub enum GitOperationState {#[strum(serialize = "")]#[serde(rename = "")]@@ -1352,15 +1352,15 @@ mod tests {#[test]fn test_integration_reason_into_static_str() {let s: &'static str = IntegrationReason::SameCommit.into();- assert_eq!(s, "same_commit");+ assert_eq!(s, "same-commit");let s: &'static str = IntegrationReason::Ancestor.into();assert_eq!(s, "ancestor");let s: &'static str = IntegrationReason::TreesMatch.into();- assert_eq!(s, "trees_match");+ assert_eq!(s, "trees-match");let s: &'static str = IntegrationReason::NoAddedChanges.into();- assert_eq!(s, "no_added_changes");+ assert_eq!(s, "no-added-changes");let s: &'static str = IntegrationReason::MergeAddsNothing.into();- assert_eq!(s, "merge_adds_nothing");+ assert_eq!(s, "merge-adds-nothing");}#[test]diff --git a/src/commands/list/timing.rs b/src/commands/list/timing.rsindex a72f6474b..bedbaddc0 100644--- a/src/commands/list/timing.rs+++ b/src/commands/list/timing.rs@@ -8,7 +8,7 @@ const DEBUG_ENV_VALUE: &str = "1";/// Operation names for tracking timing#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq, strum::AsRefStr)]-#[strum(serialize_all = "snake_case")]+#[strum(serialize_all = "kebab-case")]pub enum OpName {CommitDetails,AheadBehind,diff --git a/src/config/user.rs b/src/config/user.rsindex 8f668b12e..3425c8ea2 100644--- a/src/config/user.rs+++ b/src/config/user.rs@@ -73,7 +73,7 @@ use super::expansion::{expand_template, sanitize_branch_name};serde::Serialize,serde::Deserialize,)]-#[serde(rename_all = "lowercase")]+#[serde(rename_all = "kebab-case")]pub enum StageMode {/// Stage everything: untracked files + unstaged tracked changes#[default]diff --git a/src/git/mod.rs b/src/git/mod.rsindex 322986dc4..502c8d8e9 100644--- a/src/git/mod.rs+++ b/src/git/mod.rs@@ -110,8 +110,8 @@ pub fn unescape_branch_from_config(escaped: &str) -> String {/// 4. [`TreesMatch`](Self::TreesMatch) - tree SHA comparison (~100-300ms)/// 5. [`MergeAddsNothing`](Self::MergeAddsNothing) - merge simulation (~500ms-2s)#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, strum::IntoStaticStr)]-#[serde(rename_all = "snake_case")]-#[strum(serialize_all = "snake_case")]+#[serde(rename_all = "kebab-case")]+#[strum(serialize_all = "kebab-case")]pub enum IntegrationReason {/// Branch HEAD is literally the same commit as target.///diff --git a/src/shell.rs b/src/shell.rsindex f738c2f54..c098f874b 100644--- a/src/shell.rs+++ b/src/shell.rs@@ -48,7 +48,7 @@ fn home_dir_required() -> Result<PathBuf, std::io::Error> {/// On Windows, Git Bash users should use `bash` for shell integration./// PowerShell integration is available for native Windows users without Git Bash.#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum, strum::Display, strum::EnumString)]-#[strum(serialize_all = "lowercase", ascii_case_insensitive)]+#[strum(serialize_all = "kebab-case", ascii_case_insensitive)]pub enum Shell {Bash,Fish,diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rsindex 85bff1598..af8aeac2f 100644--- a/tests/integration_tests/config_state.rs+++ b/tests/integration_tests/config_state.rs@@ -185,24 +185,24 @@ fn test_state_clear_previous_branch_empty(repo: TestRepo) {#[rstest]fn test_state_get_ci_status(repo: TestRepo) {- // Without any CI configured, should return "noci"+ // Without any CI configured, should return "no-ci"let output = wt_state_cmd(&repo, "ci-status", "get", &[]).output().unwrap();assert!(output.status.success());- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "no-ci");}#[rstest]fn test_state_get_ci_status_specific_branch(repo: TestRepo) {repo.git_command(&["branch", "feature"]).status().unwrap();- // Without any CI configured, should return "noci"+ // Without any CI configured, should return "no-ci"let output = wt_state_cmd(&repo, "ci-status", "get", &["--branch", "feature"]).output().unwrap();assert!(output.status.success());- assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "noci");+ assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "no-ci");}#[rstest]@@ -231,7 +231,7 @@ fn test_state_clear_ci_status_branch(repo: TestRepo) {repo.git_command(&["config","worktrunk.ci.main",- &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),]).status().unwrap();@@ -573,7 +573,7 @@ fn test_state_get_with_ci_entries(repo: TestRepo) {repo.git_command(&["config","worktrunk.ci.feature",- &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),]).status().unwrap();@@ -626,7 +626,7 @@ fn test_state_get_comprehensive(repo: TestRepo) {repo.git_command(&["config","worktrunk.ci.feature",- &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),]).status().unwrap();@@ -678,7 +678,7 @@ fn test_state_get_json_comprehensive(repo: TestRepo) {repo.git_command(&["config","worktrunk.ci.feature",- &format!(r#"{{"status":{{"ci_status":"passed","source":"pullrequest","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),+ &format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),]).status().unwrap();diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rsindex 6586a56db..c90e5d2b3 100644--- a/tests/integration_tests/list.rs+++ b/tests/integration_tests/list.rs@@ -1638,10 +1638,10 @@ TODO: Add request/response examples for each endpoint// === Mock CI status ===// CI requires --full flag, but we mock it so examples show realistic output// Note: main's CI is mocked AFTER the merge commit so the hash matches- mock_ci_status(repo, "main", "passed", "pullrequest", false);- mock_ci_status(repo, "fix-auth", "passed", "pullrequest", false);+ mock_ci_status(repo, "main", "passed", "pull-request", false);+ mock_ci_status(repo, "fix-auth", "passed", "pull-request", false);// feature-api has unpushed commits, so CI is stale (shows dimmed)- mock_ci_status(repo, "feature-api", "running", "pullrequest", true);+ mock_ci_status(repo, "feature-api", "running", "pull-request", true);feature_api}diff --git a/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap b/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snapindex 06eceb4ca..86cb122c6 100644--- a/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap+++ b/tests/snapshots/integration__integration_tests__list__json_tree_matches_main_after_merge.snap@@ -88,7 +88,7 @@ exit_code: 0}},"main_state": "integrated",- "integration_reason": "no_added_changes",+ "integration_reason": "no-added-changes","main": {"ahead": 2,"behind": 0