Skip to content

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

fix(config): pass `--end-of-options` when reading project config at a ref (#2711)

Maximilian Rooseed203c3490d
diff --git a/src/git/repository/config.rs b/src/git/repository/config.rs
index 37a75ba8a..12d5fed3b 100644
--- a/src/git/repository/config.rs
+++ b/src/git/repository/config.rs
@@ -636,8 +636,14 @@ impl Repository {
if std::env::var_os("WORKTRUNK_PROJECT_CONFIG_PATH").is_some() {
return self.load_project_config().ok().flatten();
}
+ // `--end-of-options` keeps a ref like `-foo` from being parsed as a
+ // flag (git's option parser would otherwise reject `-foo:.config/wt.toml`).
let content = self
- .run_command(&["show", &format!("{gitref}:.config/wt.toml")])
+ .run_command(&[
+ "show",
+ "--end-of-options",
+ &format!("{gitref}:.config/wt.toml"),
+ ])
.ok()?;
let migrated = crate::config::migrate_content(&content);
toml::from_str::<ProjectConfig>(&migrated).ok()
@@ -674,6 +680,31 @@ mod tests {
assert!(repo.project_config_at_ref("HEAD").is_none());
}
+ /// A ref literally named `-foo` must round-trip through
+ /// [`project_config_at_ref`] without git's option parser eating the
+ /// leading `-`. Without `--end-of-options`, `git show` would reject
+ /// `-foo:.config/wt.toml` as a flag and the helper would silently
+ /// return `None` even though the file exists on the ref.
+ #[test]
+ fn project_config_at_ref_handles_hyphen_prefixed_ref() {
+ let test = TestRepo::with_initial_commit();
+ let repo = Repository::at(test.root_path()).unwrap();
+
+ test.write_project_config(r#"post-start = "echo hi""#);
+ test.run_git(&["add", ".config/wt.toml"]);
+ test.run_git(&["commit", "-m", "Add config"]);
+
+ // `git branch -- -foo` is rejected by recent git, but `update-ref`
+ // happily writes the ref — which is the worst case we want to be
+ // robust against.
+ test.run_git(&["update-ref", "refs/heads/-foo", "HEAD"]);
+
+ let cfg = repo
+ .project_config_at_ref("-foo")
+ .expect("config readable at hyphen-prefixed ref");
+ assert!(cfg.hooks.post_start.is_some());
+ }
+
#[test]
fn test_get_config_regexp_no_match_returns_empty() {
// Exit 1 from git config --get-regexp means "no keys matched" — must