Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/git/repository/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
44 changes: 44 additions & 0 deletions tests/integration_tests/bare_repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading