Skip to content

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

Unify git config state storage under worktrunk.state.<branch>.* (#234)

Maximilian Roos7f0c92724082
diff --git a/docs/content/claude-code.md b/docs/content/claude-code.md
index 3be77ac20..2c9c720b5 100644
--- a/docs/content/claude-code.md
+++ b/docs/content/claude-code.md
@@ -44,7 +44,7 @@ Set status markers manually for any workflow:
```bash
$ wt config var set marker "🚧" # Current branch
$ wt config var set marker "βœ…" --branch feature # Specific branch
-$ git config worktrunk.marker.feature "πŸ’¬" # Direct git config
+$ git config worktrunk.state.feature.marker '{"marker":"πŸ’¬","set_at":0}' # Direct
```
## Statusline
diff --git a/docs/content/config.md b/docs/content/config.md
index a90f59517..a5fcb4314 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -817,10 +817,10 @@ bugfix πŸ€–!↑⇑ ~/code/myproject.bugfix
### Storage
-Stored in git config as `worktrunk.marker.<branch>`. Set directly with:
+Stored in git config as `worktrunk.state.<branch>.marker`. Set directly with:
```bash
-git config worktrunk.marker.feature "🚧"
+git config worktrunk.state.feature.marker '{"marker":"🚧","set_at":0}'
```
Without a subcommand, runs `get` for the current branch. For `--branch`, use `get --branch=NAME`.
diff --git a/docs/content/tips-patterns.md b/docs/content/tips-patterns.md
index cb5a76328..522751dab 100644
--- a/docs/content/tips-patterns.md
+++ b/docs/content/tips-patterns.md
@@ -58,7 +58,7 @@ Set status manually for any workflow:
```bash
wt config var set marker "🚧" # Current branch
wt config var set marker "βœ…" --branch feature # Specific branch
-git config worktrunk.marker.feature "πŸ’¬" # Direct git config
+git config worktrunk.state.feature.marker '{"marker":"πŸ’¬","set_at":0}' # Direct
```
See [Claude Code Integration](@/claude-code.md#installation) for plugin installation.
diff --git a/docs/demos/wt-select/build b/docs/demos/wt-select/build
index aa4ef8e0a..d220c0e51 100755
--- a/docs/demos/wt-select/build
+++ b/docs/demos/wt-select/build
@@ -39,7 +39,7 @@ The setup process:
CI CACHE TRICK
==============
-The CI status is cached in git config (`worktrunk.ci.{branch}`). To show CI
+The CI status is cached in git config (`worktrunk.state.{branch}.ci-status`). To show CI
status without actual GitHub/GitLab access, we:
1. Write fake CI cache entries directly to git config
2. Use a future timestamp (1 hour ahead) so the cache never expires during recording
@@ -347,7 +347,7 @@ fn validate_template(template: &str) -> Result<(), String> {
def add_ci_status(env: DemoEnv):
"""Add fake CI status to git config for demo.
- CI status is cached in git config as worktrunk.ci.{branch} with JSON value.
+ CI status is cached in git config as worktrunk.state.{branch}.ci-status with JSON value.
The cache uses a future timestamp to prevent expiration during VHS recording.
"""
import json
@@ -404,7 +404,7 @@ def add_ci_status(env: DemoEnv):
print("Adding CI status cache...")
for branch, config in ci_configs.items():
- config_key = f"worktrunk.ci.{branch}"
+ config_key = f"worktrunk.state.{branch}.ci-status"
config_json = json.dumps(config)
git(["-C", str(env.repo), "config", config_key, config_json])
diff --git a/src/cli.rs b/src/cli.rs
index 72de6bfab..47948211a 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -569,10 +569,10 @@ bugfix πŸ€–!↑⇑ ~/code/myproject.bugfix
## Storage
-Stored in git config as `worktrunk.marker.<branch>`. Set directly with:
+Stored in git config as `worktrunk.state.<branch>.marker`. Set directly with:
```console
-git config worktrunk.marker.feature "🚧"
+git config worktrunk.state.feature.marker '{"marker":"🚧","set_at":0}'
```
Without a subcommand, runs `get` for the current branch. For `--branch`, use `get --branch=NAME`."#
diff --git a/src/commands/config.rs b/src/commands/config.rs
index c172c4f69..95131e63a 100644
--- a/src/commands/config.rs
+++ b/src/commands/config.rs
@@ -649,10 +649,7 @@ pub fn handle_state_get(key: &str, refresh: bool, branch: Option<String>) -> any
if refresh {
crate::output::print(progress_message("Fetching CI status..."))?;
// Clear cache to force refresh
- let config_key = format!(
- "worktrunk.ci.{}",
- worktrunk::git::escape_branch_for_config(&branch_name)
- );
+ let config_key = format!("worktrunk.state.{branch_name}.ci-status");
let _ = repo.run_command(&["config", "--unset", &config_key]);
}
@@ -763,8 +760,7 @@ pub fn handle_state_set(key: &str, value: String, branch: Option<String>) -> any
"set_at": now
});
- let escaped = worktrunk::git::escape_branch_for_config(&branch_name);
- let config_key = format!("worktrunk.marker.{}", escaped);
+ let config_key = format!("worktrunk.state.{branch_name}.marker");
repo.run_command(&["config", &config_key, &json.to_string()])?;
crate::output::print(success_message(cformat!(
@@ -818,10 +814,7 @@ pub fn handle_state_clear(key: &str, branch: Option<String>, all: bool) -> anyho
Some(b) => b,
None => repo.require_current_branch("clear ci-status for current branch")?,
};
- let config_key = format!(
- "worktrunk.ci.{}",
- worktrunk::git::escape_branch_for_config(&branch_name)
- );
+ let config_key = format!("worktrunk.state.{branch_name}.ci-status");
if repo
.run_command(&["config", "--unset", &config_key])
.is_ok()
@@ -839,7 +832,7 @@ pub fn handle_state_clear(key: &str, branch: Option<String>, all: bool) -> anyho
"marker" => {
if all {
let output = repo
- .run_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
+ .run_command(&["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
.unwrap_or_default();
let mut cleared_count = 0;
@@ -864,8 +857,7 @@ pub fn handle_state_clear(key: &str, branch: Option<String>, all: bool) -> anyho
None => repo.require_current_branch("clear marker for current branch")?,
};
- let escaped = worktrunk::git::escape_branch_for_config(&branch_name);
- let config_key = format!("worktrunk.marker.{}", escaped);
+ let config_key = format!("worktrunk.state.{branch_name}.marker");
if repo
.run_command(&["config", "--unset", &config_key])
.is_ok()
@@ -921,7 +913,7 @@ pub fn handle_state_clear_all() -> anyhow::Result<()> {
// Clear all markers
let markers_output = repo
- .run_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
+ .run_command(&["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
.unwrap_or_default();
for line in markers_output.lines() {
if let Some(config_key) = line.split_whitespace().next() {
@@ -1214,16 +1206,19 @@ struct MarkerEntry {
/// Get all branch markers from git config with timestamps
fn get_all_markers(repo: &Repository) -> Vec<MarkerEntry> {
let output = repo
- .run_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
+ .run_command(&["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
.unwrap_or_default();
let mut markers = Vec::new();
for line in output.lines() {
- // Format: "worktrunk.marker.escaped_branch json_value"
+ // Format: "worktrunk.state.<branch>.marker json_value"
let Some((key, value)) = line.split_once(' ') else {
continue;
};
- let Some(escaped_branch) = key.strip_prefix("worktrunk.marker.") else {
+ let Some(branch) = key
+ .strip_prefix("worktrunk.state.")
+ .and_then(|s| s.strip_suffix(".marker"))
+ else {
continue;
};
let Ok(parsed) = serde_json::from_str::<serde_json::Value>(value) else {
@@ -1233,9 +1228,8 @@ fn get_all_markers(repo: &Repository) -> Vec<MarkerEntry> {
continue; // Skip if "marker" field is missing
};
let set_at = parsed.get("set_at").and_then(|v| v.as_u64()).unwrap_or(0);
- let branch = worktrunk::git::unescape_branch_from_config(escaped_branch);
markers.push(MarkerEntry {
- branch,
+ branch: branch.to_string(),
marker: marker.to_string(),
set_at,
});
diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rs
index 4f0a082f3..06b9c8aae 100644
--- a/src/commands/list/ci_status.rs
+++ b/src/commands/list/ci_status.rs
@@ -367,67 +367,6 @@ mod tests {
);
}
- #[test]
- fn test_escape_branch_round_trip() {
- use worktrunk::git::{escape_branch_for_config, unescape_branch_from_config};
-
- let cases = [
- "main",
- "feature/test",
- "feature.test",
- "feature-test",
- "feature_test",
- "a.b.c",
- "a/b/c",
- "feature-2Dtest", // Literal -2D in branch name
- "-",
- "--",
- "feat/fix-bug",
- // UTF-8 multi-byte sequences
- "cafΓ©", // 2-byte UTF-8 (Γ© = 0xC3 0xA9)
- "ζ—₯本θͺž", // 3-byte UTF-8 (CJK)
- "emoji-πŸŽ‰", // 4-byte UTF-8 (emoji)
- ];
-
- for branch in cases {
- let escaped = escape_branch_for_config(branch);
- let unescaped = unescape_branch_from_config(&escaped);
- assert_eq!(
- unescaped, branch,
- "Round-trip failed for '{}': escaped='{}', unescaped='{}'",
- branch, escaped, unescaped
- );
- }
- }
-
- #[test]
- fn test_escape_branch_git_config_compatible() {
- use worktrunk::git::escape_branch_for_config;
-
- // Git config keys only allow alphanumeric, `-`, and `.`
- let is_valid_config_char = |c: char| c.is_ascii_alphanumeric() || c == '-' || c == '.';
-
- let cases = [
- "main",
- "feature/test",
- "feature_test",
- "feature-test",
- "a/b/c",
- "user@host",
- "100%",
- ];
-
- for branch in cases {
- let escaped = escape_branch_for_config(branch);
- assert!(
- escaped.chars().all(is_valid_config_char),
- "Escaped '{}' contains invalid git config chars: '{}'",
- branch,
- escaped
- );
- }
- }
-
#[test]
fn test_is_retriable_error() {
// Rate limit errors
@@ -1031,12 +970,11 @@ impl CachedCiStatus {
self.head == current_head && now_secs.saturating_sub(self.checked_at) < ttl
}
- /// Read cached CI status from git config
+ /// Read cached CI status from git config.
+ ///
+ /// Key format: `worktrunk.state.<branch>.ci-status`
fn read(branch: &str, repo_root: &str) -> Option<Self> {
- let config_key = format!(
- "worktrunk.ci.{}",
- worktrunk::git::escape_branch_for_config(branch)
- );
+ let config_key = format!("worktrunk.state.{branch}.ci-status");
let mut cmd = Command::new("git");
cmd.args(["config", "--get", &config_key])
.current_dir(repo_root);
@@ -1050,12 +988,11 @@ impl CachedCiStatus {
serde_json::from_str(json.trim()).ok()
}
- /// Write CI status to git config cache
+ /// Write CI status to git config cache.
+ ///
+ /// Key format: `worktrunk.state.<branch>.ci-status`
fn write(&self, branch: &str, repo_root: &str) {
- let config_key = format!(
- "worktrunk.ci.{}",
- worktrunk::git::escape_branch_for_config(branch)
- );
+ let config_key = format!("worktrunk.state.{branch}.ci-status");
let Ok(json) = serde_json::to_string(self) else {
log::debug!("Failed to serialize CI cache for {}", branch);
return;
@@ -1068,28 +1005,41 @@ impl CachedCiStatus {
}
}
- /// List all cached CI statuses as (branch_name, cached_status) pairs
+ /// List all cached CI statuses as (branch_name, cached_status) pairs.
+ ///
+ /// Key format: `worktrunk.state.<branch>.ci-status`
pub(crate) fn list_all(repo: &Repository) -> Vec<(String, Self)> {
let output = repo
- .run_command(&["config", "--get-regexp", r"^worktrunk\.ci\."])
+ .run_command(&[
+ "config",
+ "--get-regexp",
+ r"^worktrunk\.state\..+\.ci-status$",
+ ])
.unwrap_or_default();
output
.lines()
.filter_map(|line| {
let (key, json) = line.split_once(' ')?;
- let escaped = key.strip_prefix("worktrunk.ci.")?;
- let branch = worktrunk::git::unescape_branch_from_config(escaped);
+ let branch = key
+ .strip_prefix("worktrunk.state.")?
+ .strip_suffix(".ci-status")?;
let cached: Self = serde_json::from_str(json).ok()?;
- Some((branch, cached))
+ Some((branch.to_string(), cached))
})
.collect()
}
- /// Clear all cached CI statuses, returns count cleared
+ /// Clear all cached CI statuses, returns count cleared.
+ ///
+ /// Key format: `worktrunk.state.<branch>.ci-status`
pub(crate) fn clear_all(repo: &Repository) -> usize {
let output = repo
- .run_command(&["config", "--get-regexp", r"^worktrunk\.ci\."])
+ .run_command(&[
+ "config",
+ "--get-regexp",
+ r"^worktrunk\.state\..+\.ci-status$",
+ ])
.unwrap_or_default();
let mut cleared = 0;
@@ -1174,10 +1124,10 @@ impl PrStatus {
/// Returns None if no CI found or CLI tools unavailable
///
/// # Caching
- /// Results (including None) are cached in git config (`worktrunk.ci.{branch}`) for 30-60
- /// seconds to avoid hitting GitHub API rate limits. TTL uses deterministic jitter based on
- /// repo path to spread cache expirations across concurrent statuslines. Invalidated when
- /// HEAD changes.
+ /// Results (including None) are cached in git config (`worktrunk.state.<branch>.ci-status`)
+ /// for 30-60 seconds to avoid hitting GitHub API rate limits. TTL uses deterministic jitter
+ /// based on repo path to spread cache expirations across concurrent statuslines. Invalidated
+ /// when HEAD changes.
///
/// # Fork Support
/// Runs gh commands from the repository directory to enable auto-detection of
diff --git a/src/git/mod.rs b/src/git/mod.rs
index 502c8d8e9..3724d89a3 100644
--- a/src/git/mod.rs
+++ b/src/git/mod.rs
@@ -42,58 +42,6 @@ pub use error::{
is_command_not_approved,
};
pub use repository::{Repository, ResolvedWorktree, set_base_path};
-
-/// Escape branch name for use in git config key.
-///
-/// Git config keys only allow alphanumeric, `-`, and `.` characters.
-/// Branch names commonly contain `/` and `_`, so we encode them as `-XX`
-/// where XX is the uppercase hex value. We also encode `-` itself to
-/// ensure round-trip safety.
-pub fn escape_branch_for_config(branch: &str) -> String {
- let mut escaped = String::with_capacity(branch.len());
- for ch in branch.chars() {
- match ch {
- 'a'..='z' | 'A'..='Z' | '0'..='9' | '.' => escaped.push(ch),
- '-' => escaped.push_str("-2D"),
- _ => {
- // Encode as -XX where XX is uppercase hex
- for byte in ch.to_string().bytes() {
- escaped.push_str(&format!("-{byte:02X}"));
- }
- }
- }
- }
- escaped
-}
-
-/// Unescape branch name from git config key.
-pub fn unescape_branch_from_config(escaped: &str) -> String {
- let mut bytes = Vec::with_capacity(escaped.len());
- let mut chars = escaped.chars().peekable();
-
- while let Some(ch) = chars.next() {
- if ch == '-' {
- // Try to read two hex digits
- let hex: String = chars.by_ref().take(2).collect();
- if hex.len() == 2
- && let Ok(byte) = u8::from_str_radix(&hex, 16)
- {
- bytes.push(byte);
- continue;
- }
- // Invalid escape sequence, keep as-is
- bytes.push(b'-');
- bytes.extend(hex.bytes());
- } else {
- // Unescaped char - encode as UTF-8 bytes
- bytes.extend(ch.to_string().bytes());
- }
- }
-
- // Decode collected bytes as UTF-8
- String::from_utf8(bytes).unwrap_or_else(|e| String::from_utf8_lossy(e.as_bytes()).into_owned())
-}
-
/// Why branch content is considered integrated into the target branch.
///
/// Used by both `wt list` (for status symbols) and `wt remove` (for messages).
@@ -597,34 +545,6 @@ mod tests {
);
}
- #[test]
- fn test_escape_unescape_roundtrip() {
- // Test escape
- let cases = [
- ("main", "main"),
- ("feature/foo", "feature-2Ffoo"),
- ("feature_foo", "feature-5Ffoo"),
- ("feature-foo", "feature-2Dfoo"),
- ("v1.0.0", "v1.0.0"), // Dots allowed
- ("user/feature_name-v2", "user-2Ffeature-5Fname-2Dv2"),
- ];
- for (input, expected_escaped) in cases {
- assert_eq!(
- escape_branch_for_config(input),
- expected_escaped,
- "escape {input}"
- );
- assert_eq!(
- unescape_branch_from_config(expected_escaped),
- input,
- "unescape {expected_escaped}"
- );
- }
- // Invalid/truncated escape sequences kept as-is
- assert_eq!(unescape_branch_from_config("foo-GGbar"), "foo-GGbar");
- assert_eq!(unescape_branch_from_config("foo-2"), "foo-2");
- }
-
#[test]
fn test_check_integration() {
// Each integration reason + not integrated
diff --git a/src/git/repository/mod.rs b/src/git/repository/mod.rs
index cc27e3b38..621423af5 100644
--- a/src/git/repository/mod.rs
+++ b/src/git/repository/mod.rs
@@ -272,12 +272,11 @@ impl Repository {
})
}
- /// Read a user-defined marker from `worktrunk.marker.<branch>` in git config.
+ /// Read a user-defined marker from `worktrunk.state.<branch>.marker` in git config.
///
/// Markers are stored as JSON: `{"marker": "text", "set_at": unix_timestamp}`.
pub fn branch_keyed_marker(&self, branch: &str) -> Option<String> {
- let escaped = super::escape_branch_for_config(branch);
- let config_key = format!("worktrunk.marker.{}", escaped);
+ let config_key = format!("worktrunk.state.{branch}.marker");
let raw = self
.run_command(&["config", "--get", &config_key])
.ok()
diff --git a/src/git/test.rs b/src/git/test.rs
index de73fc83d..2dc14a444 100644
--- a/src/git/test.rs
+++ b/src/git/test.rs
@@ -394,120 +394,3 @@ fn snapshot_parse_worktree_list_unknown_attributes() {
}
"#);
}
-
-// Tests for escape_branch_for_config and unescape_branch_from_config
-
-use super::{escape_branch_for_config, unescape_branch_from_config};
-
-#[test]
-fn test_escape_branch_simple() {
- // Alphanumeric and dots should pass through unchanged
- assert_eq!(escape_branch_for_config("main"), "main");
- assert_eq!(escape_branch_for_config("feature.123"), "feature.123");
- assert_eq!(escape_branch_for_config("AaBbZz0189"), "AaBbZz0189");
-}
-
-#[test]
-fn test_escape_branch_with_slash() {
- // Slashes should be encoded as -2F
- assert_eq!(
- escape_branch_for_config("feature/branch"),
- "feature-2Fbranch"
- );
- assert_eq!(escape_branch_for_config("a/b/c"), "a-2Fb-2Fc");
-}
-
-#[test]
-fn test_escape_branch_with_underscore() {
- // Underscores should be encoded as -5F
- assert_eq!(escape_branch_for_config("my_branch"), "my-5Fbranch");
- assert_eq!(escape_branch_for_config("a_b_c"), "a-5Fb-5Fc");
-}
-
-#[test]
-fn test_escape_branch_with_hyphen() {
- // Hyphens should be encoded as -2D
- assert_eq!(escape_branch_for_config("my-branch"), "my-2Dbranch");
- assert_eq!(escape_branch_for_config("a-b-c"), "a-2Db-2Dc");
-}
-
-#[test]
-fn test_escape_branch_mixed_special_chars() {
- // Mix of special characters
- assert_eq!(
- escape_branch_for_config("feature/my-branch_test"),
- "feature-2Fmy-2Dbranch-5Ftest"
- );
-}
-
-#[test]
-fn test_unescape_branch_simple() {
- // Simple strings should pass through unchanged
- assert_eq!(unescape_branch_from_config("main"), "main");
- assert_eq!(unescape_branch_from_config("feature.123"), "feature.123");
-}
-
-#[test]
-fn test_unescape_branch_with_encoded_slash() {
- // -2F should become /
- assert_eq!(
- unescape_branch_from_config("feature-2Fbranch"),
- "feature/branch"
- );
-}
-
-#[test]
-fn test_unescape_branch_with_encoded_underscore() {
- // -5F should become _
- assert_eq!(unescape_branch_from_config("my-5Fbranch"), "my_branch");
-}
-
-#[test]
-fn test_unescape_branch_with_encoded_hyphen() {
- // -2D should become -
- assert_eq!(unescape_branch_from_config("my-2Dbranch"), "my-branch");
-}
-
-#[test]
-fn test_escape_unescape_roundtrip() {
- // Test that escape followed by unescape returns original
- let test_cases = vec![
- "main",
- "feature/branch",
- "my-branch",
- "my_branch",
- "feature/my-branch_test",
- "a/b/c-d_e.f",
- "",
- ];
- for branch in test_cases {
- let escaped = escape_branch_for_config(branch);
- let unescaped = unescape_branch_from_config(&escaped);
- assert_eq!(
- unescaped, branch,
- "Roundtrip failed for '{branch}': escaped='{}', unescaped='{}'",
- escaped, unescaped
- );
- }
-}
-
-#[test]
-fn test_unescape_branch_invalid_escape() {
- // Invalid escape sequences should be kept as-is
- // -XX where XX is not valid hex
- assert_eq!(unescape_branch_from_config("test-ZZ"), "test-ZZ");
- // - at end without following chars
- assert_eq!(unescape_branch_from_config("test-"), "test-");
- // - followed by only one char
- assert_eq!(unescape_branch_from_config("test-A"), "test-A");
-}
-
-#[test]
-fn test_escape_branch_empty() {
- assert_eq!(escape_branch_for_config(""), "");
-}
-
-#[test]
-fn test_unescape_branch_empty() {
- assert_eq!(unescape_branch_from_config(""), "");
-}
diff --git a/tests/CLAUDE.md b/tests/CLAUDE.md
index f96318878..effbfb3a8 100644
--- a/tests/CLAUDE.md
+++ b/tests/CLAUDE.md
@@ -184,7 +184,7 @@ Tests use `TEST_EPOCH` (2025-01-01) for reproducible timestamps. The constant is
use crate::common::TEST_EPOCH;
repo.git_command(&[
- "config", "worktrunk.ci.feature",
+ "config", "worktrunk.state.feature.ci-status",
&format!(r#"{{"checked_at":{TEST_EPOCH},"head":"abc123"}}"#),
]);
```
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 4c01b9b6e..5a6648c18 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1722,14 +1722,11 @@ exit 1
}
}
- /// Set a marker for a branch with proper escaping for git config keys.
+ /// Set a marker for a branch.
///
- /// This handles the branch name escaping required for git config keys,
- /// which only allow alphanumeric, `-`, and `.` characters.
- /// Markers are stored as JSON with a timestamp.
+ /// Markers are stored as JSON with a timestamp in `worktrunk.state.<branch>.marker`.
pub fn set_marker(&self, branch: &str, marker: &str) {
- let escaped = worktrunk::git::escape_branch_for_config(branch);
- let config_key = format!("worktrunk.marker.{}", escaped);
+ let config_key = format!("worktrunk.state.{branch}.marker");
let json_value = format!(r#"{{"marker":"{}","set_at":{}}}"#, marker, TEST_EPOCH);
self.git_command(&["config", &config_key, &json_value])
.output()
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index de519be48..ee9e3893c 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -230,7 +230,7 @@ fn test_state_clear_ci_status_branch(repo: TestRepo) {
// Add CI cache entry
repo.git_command(&[
"config",
- "worktrunk.ci.main",
+ "worktrunk.state.main.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345"}}"#),
])
.status()
@@ -333,7 +333,7 @@ fn test_state_clear_marker_branch_default(repo: TestRepo) {
// Verify it was unset
let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.main"])
+ .git_command(&["config", "--get", "worktrunk.state.main.marker"])
.output()
.unwrap();
assert!(!output.status.success());
@@ -352,7 +352,7 @@ fn test_state_clear_marker_branch_specific(repo: TestRepo) {
// Verify it was unset
let output = repo
- .git_command(&["config", "--get", "worktrunk.marker.feature"])
+ .git_command(&["config", "--get", "worktrunk.state.feature.marker"])
.output()
.unwrap();
assert!(!output.status.success());
@@ -373,7 +373,7 @@ fn test_state_clear_marker_all(repo: TestRepo) {
// Verify all were unset
let output = repo
- .git_command(&["config", "--get-regexp", "^worktrunk\\.marker\\."])
+ .git_command(&["config", "--get-regexp", r"^worktrunk\.state\..+\.marker$"])
.output()
.unwrap();
assert_eq!(String::from_utf8_lossy(&output.stdout).trim(), "");
@@ -494,7 +494,7 @@ fn test_state_clear_all_comprehensive(repo: TestRepo) {
// CI cache
repo.git_command(&[
"config",
- "worktrunk.ci.feature",
+ "worktrunk.state.feature.ci-status",
r#"{"checked_at":1704067200,"head":"abc123"}"#,
])
.status()
@@ -520,7 +520,7 @@ fn test_state_clear_all_comprehensive(repo: TestRepo) {
== Some(1)
); // Not found
assert!(
- repo.git_command(&["config", "--get", "worktrunk.marker.main"])
+ repo.git_command(&["config", "--get", "worktrunk.state.main.marker"])
.output()
.unwrap()
.status
@@ -528,7 +528,7 @@ fn test_state_clear_all_comprehensive(repo: TestRepo) {
== Some(1)
);
assert!(
- repo.git_command(&["config", "--get", "worktrunk.ci.feature"])
+ repo.git_command(&["config", "--get", "worktrunk.state.feature.ci-status"])
.output()
.unwrap()
.status
@@ -580,7 +580,7 @@ fn test_state_get_with_ci_entries(repo: TestRepo) {
// Add CI cache entries - use TEST_EPOCH for deterministic age=0s in snapshots
repo.git_command(&[
"config",
- "worktrunk.ci.feature",
+ "worktrunk.state.feature.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),
])
.status()
@@ -588,7 +588,7 @@ fn test_state_get_with_ci_entries(repo: TestRepo) {
repo.git_command(&[
"config",
- "worktrunk.ci.bugfix",
+ "worktrunk.state.bugfix.ci-status",
&format!(r#"{{"status":{{"ci_status":"failed","source":"branch","is_stale":true}},"checked_at":{TEST_EPOCH},"head":"111222333444555"}}"#),
])
.status()
@@ -596,7 +596,7 @@ fn test_state_get_with_ci_entries(repo: TestRepo) {
repo.git_command(&[
"config",
- "worktrunk.ci.main",
+ "worktrunk.state.main.ci-status",
&format!(r#"{{"status":null,"checked_at":{TEST_EPOCH},"head":"deadbeef12345678"}}"#),
])
.status()
@@ -617,14 +617,14 @@ fn test_state_get_comprehensive(repo: TestRepo) {
// Set up branch markers (JSON format with timestamps for deterministic age)
repo.git_command(&[
"config",
- "worktrunk.marker.feature",
+ "worktrunk.state.feature.marker",
&format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
])
.status()
.unwrap();
repo.git_command(&[
"config",
- "worktrunk.marker.bugfix",
+ "worktrunk.state.bugfix.marker",
&format!(r#"{{"marker":"πŸ› debugging","set_at":{TEST_EPOCH}}}"#),
])
.status()
@@ -633,7 +633,7 @@ fn test_state_get_comprehensive(repo: TestRepo) {
// Set up CI cache
repo.git_command(&[
"config",
- "worktrunk.ci.feature",
+ "worktrunk.state.feature.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),
])
.status()
@@ -676,7 +676,7 @@ fn test_state_get_json_comprehensive(repo: TestRepo) {
// Set up branch markers (JSON format with timestamps)
repo.git_command(&[
"config",
- "worktrunk.marker.feature",
+ "worktrunk.state.feature.marker",
&format!(r#"{{"marker":"🚧 WIP","set_at":{TEST_EPOCH}}}"#),
])
.status()
@@ -685,7 +685,7 @@ fn test_state_get_json_comprehensive(repo: TestRepo) {
// Set up CI cache
repo.git_command(&[
"config",
- "worktrunk.ci.feature",
+ "worktrunk.state.feature.ci-status",
&format!(r#"{{"status":{{"ci_status":"passed","source":"pull-request","is_stale":false}},"checked_at":{TEST_EPOCH},"head":"abc12345def67890"}}"#),
])
.status()
diff --git a/tests/integration_tests/list.rs b/tests/integration_tests/list.rs
index c90e5d2b3..75911aa22 100644
--- a/tests/integration_tests/list.rs
+++ b/tests/integration_tests/list.rs
@@ -1678,11 +1678,8 @@ fn mock_ci_status(repo: &TestRepo, branch: &str, status: &str, source: &str, is_
head
);
- // Write to git config (using escaped branch name)
- let config_key = format!(
- "worktrunk.ci.{}",
- worktrunk::git::escape_branch_for_config(branch)
- );
+ // Write to git config using subsection format (branch name is subsection, no escaping needed)
+ let config_key = format!("worktrunk.state.{branch}.ci-status");
let mut cmd = Command::new("git");
repo.configure_git_cmd(&mut cmd);
cmd.args(["config", &config_key, &cache_json])
diff --git a/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
index 8f5647e04..771f7df3c 100644
--- a/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
+++ b/tests/snapshots/integration__integration_tests__help__help_config_state_marker.snap
@@ -61,8 +61,8 @@ Markers appear at the start of the Status column:
Storage
-Stored in git config as worktrunk.marker.<branch>. Set directly with:
+Stored in git config as worktrunk.state.<branch>.marker. Set directly with:
- git config worktrunk.marker.feature "🚧"
+ git config worktrunk.state.feature.marker '{"marker":"🚧","set_at":0}'
Without a subcommand, runs get for the current branch. For --branch, use get --branch=NAME.