Skip to content

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

fix: reject underscore in vars keys (invalid git config variable name) (#2285)

Martin Zisermanc70e77bf2d37
diff --git a/docs/content/config.md b/docs/content/config.md
index e734acea7..29ec4289d 100644
--- a/docs/content/config.md
+++ b/docs/content/config.md
@@ -1001,7 +1001,7 @@ dev = "npm start -- --port {{ vars.config.port }}"
### Storage format
-Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits, hyphens, and underscores — dots conflict with git config's section separator.
+Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits and hyphens — dots conflict with git config's section separator, underscores with its variable name format.
### Command reference
diff --git a/skills/worktrunk/reference/config.md b/skills/worktrunk/reference/config.md
index 9573ae4e7..8cd38eda6 100644
--- a/skills/worktrunk/reference/config.md
+++ b/skills/worktrunk/reference/config.md
@@ -1048,7 +1048,7 @@ dev = "npm start -- --port {{ vars.config.port }}"
### Storage format
-Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits, hyphens, and underscores — dots conflict with git config's section separator.
+Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits and hyphens — dots conflict with git config's section separator, underscores with its variable name format.
### Command reference
diff --git a/src/cli/config.rs b/src/cli/config.rs
index 4c8bc7738..60133047a 100644
--- a/src/cli/config.rs
+++ b/src/cli/config.rs
@@ -900,7 +900,7 @@ dev = "npm start -- --port {{ vars.config.port }}"
## Storage format
-Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits, hyphens, and underscores — dots conflict with git config's section separator."#
+Stored in git config as `worktrunk.state.<branch>.vars.<key>`. Keys must contain only letters, digits and hyphens — dots conflict with git config's section separator, underscores with its variable name format."#
)]
Vars {
#[command(subcommand)]
diff --git a/src/commands/config/state.rs b/src/commands/config/state.rs
index cfdb65ac6..ce26b1d00 100644
--- a/src/commands/config/state.rs
+++ b/src/commands/config/state.rs
@@ -1174,18 +1174,13 @@ fn handle_state_show_table(repo: &Repository) -> anyhow::Result<()> {
// ==================== Vars Operations ====================
-/// Validate a vars key name: letters, digits, hyphens, underscores only.
+/// Validate a vars key name: letters, digits, and hyphens only.
fn validate_vars_key(key: &str) -> anyhow::Result<()> {
if key.is_empty() {
anyhow::bail!("Key cannot be empty");
}
- if !key
- .chars()
- .all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_')
- {
- anyhow::bail!(
- "Invalid key {key:?}: keys must contain only letters, digits, hyphens, and underscores"
- );
+ if !key.chars().all(|c| c.is_ascii_alphanumeric() || c == '-') {
+ anyhow::bail!("Invalid key {key:?}: keys must contain only letters, digits, and hyphens");
}
Ok(())
}
diff --git a/tests/integration_tests/config_state.rs b/tests/integration_tests/config_state.rs
index 672c8e13b..91a4bd7bc 100644
--- a/tests/integration_tests/config_state.rs
+++ b/tests/integration_tests/config_state.rs
@@ -1573,7 +1573,7 @@ fn test_vars_invalid_key(repo: TestRepo) {
.output()
.unwrap();
assert!(!output.status.success());
- assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r#"✗ Invalid key "foo.bar": keys must contain only letters, digits, hyphens, and underscores"#);
+ assert_snapshot!(String::from_utf8_lossy(&output.stderr), @r#"✗ Invalid key "foo.bar": keys must contain only letters, digits, and hyphens"#);
}
#[rstest]