Skip to content

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

Read config from dash-prefixed default branches (#4277)

DDL51f9a7cb16f9
diff --git a/src/git/repository/config.rs b/src/git/repository/config.rs
index 0aac2b242..f1ed39e3a 100644
--- a/src/git/repository/config.rs
+++ b/src/git/repository/config.rs
@@ -955,7 +955,7 @@ impl Repository {
}
let spec = format!("{}:.config/wt.toml", self.default_branch()?);
- match self.run_command_output(&["show", &spec]) {
+ match self.run_command_output(&["show", "--end-of-options", &spec]) {
Ok(output) if output.status.success() => Some((
String::from_utf8_lossy(&output.stdout).into_owned(),
PathBuf::from(&spec),
diff --git a/tests/integration_tests/bare_repository.rs b/tests/integration_tests/bare_repository.rs
index 1a866997b..8106aeb4f 100644
--- a/tests/integration_tests/bare_repository.rs
+++ b/tests/integration_tests/bare_repository.rs
@@ -1310,6 +1310,50 @@ fn test_bare_repo_config_show_reflects_object_store_fallback() {
);
}
+#[test]
+fn test_bare_repo_config_show_reads_dash_prefixed_default_branch() {
+ let test = BareRepoTest::new();
+
+ let main_worktree = test.create_worktree("main", "main");
+ test.commit_in(&main_worktree, "Initial commit");
+
+ let config_dir = main_worktree.join(".config");
+ fs::create_dir_all(&config_dir).unwrap();
+ fs::write(
+ config_dir.join("wt.toml"),
+ "[list]\nurl = \"http://localhost:3000\"\n",
+ )
+ .unwrap();
+ test.run_git_in(&main_worktree, &["add", ".config/wt.toml"]);
+ test.run_git_in(&main_worktree, &["commit", "-m", "Add project config"]);
+
+ test.run_git_in(
+ test.bare_repo_path(),
+ &["update-ref", "refs/heads/-x", "refs/heads/main"],
+ );
+ test.run_git_in(
+ test.bare_repo_path(),
+ &["config", "worktrunk.default-branch", "-x"],
+ );
+
+ let mut cmd = test.wt_command();
+ cmd.args(["config", "show", "--format=json"])
+ .current_dir(test.bare_repo_path());
+ let output = cmd.output().unwrap();
+ assert!(
+ output.status.success(),
+ "stderr: {}",
+ String::from_utf8_lossy(&output.stderr)
+ );
+ let json: serde_json::Value =
+ serde_json::from_str(&String::from_utf8_lossy(&output.stdout)).unwrap();
+ assert_eq!(
+ json["project"]["config"]["list"]["url"], "http://localhost:3000",
+ "config show must read the committed config when the default branch starts with a dash, got: {}",
+ json["project"]
+ );
+}
+
#[test]
fn test_bare_repo_project_config_found_with_dash_c_flag() {
// Regression test for #1691 (comment): project config in the primary worktree