Project config `.config/wt.toml` in bare repository is ignored
with a bare layout:
myproject/
├── .git/ # bare repository
├── main/ # default branch
├── feature/ # feature branch
└── bugfix/ # bugfix branch
when creating a new worktree with wt switch --create new-feature the .config/toml is only found in the current directory.
If I am in myproject and call the create given the config is in myproject/main/.config/wt.toml then the hooks are not executed.
If I am in myproject/main and call the create given the config is in myproject/main/.config/wt.toml then the hooks are executed.
Fun fact: If I create a myproject/.config/wt.toml it is picked up when calling the create in the project root.
I was expecting that in the bare-repo the .config/wt.toml is being picked up from the default branch.
I am not entirely sure what the "correct" behaviour is. Maybe this is a non-issue.
Thanks for reporting this! I was able to reproduce the issue and identified the root cause: ProjectConfig::load() resolves the config path via current_worktree().root(), which for bare repos at the root directory falls back to the bare directory itself (since git rev-parse --show-toplevel fails for bare repos), so it never finds .config/wt.toml in the primary worktree.
I've opened #1692 with a fix that falls back to checking the primary worktree (default branch worktree) when no config is found at the current location in bare repos. A maintainer will review it shortly.
Another issue is that when wt switch --create --no-cd new-feature --base main -C <repo> is called in any directory other than "repo" the .config/wt.toml in the base worktree main is ignored.
I would expect the hooks from the main/.config/wt.toml being picked up.
Good catch on the -C flag scenario — that should be covered by the fix in #1692 as well, since -C <repo> sets the working directory to the bare repo root before config resolution runs. It hits the same code path: current location has no .config/wt.toml → bare repo → fall back to primary worktree's config.
I'll add a test case for the -C variant to make sure it's explicitly covered.
thanks @seakayone !
Fun fact: If I create a myproject/.config/wt.toml it is picked up when calling the create in the project root.
@worktrunk-bot what code path does this hit? not bad per se, but it worries me a bit that we have a bunch of fallbacks, given that this is not a place the file should be...
The code path is in ProjectConfig::load():
current_worktree()returns aWorkingTreeatbase_path()(the cwd —myproject/)root()runsgit rev-parse --show-toplevel, which fails for bare repos- The fallback in
root()is.unwrap_or_else(|| self.path.clone())— so it returns the bare repo directory itself (myproject/) - That makes
config_path = myproject/.config/wt.toml, which exists and gets loaded
So it's not a deliberate fallback — it's --show-toplevel failing silently and root() falling back to the raw path. The #1692 fix doesn't change this: the config_path.exists() check on line 147 still catches myproject/.config/wt.toml before the bare-repo fallback runs.
Whether this is worth worrying about: it's arguably reasonable behavior — if someone puts a config file in the bare repo root, they probably want it used. But it is an accidental side effect rather than an intentional feature. We could tighten it by skipping the config_path.exists() check when root() fell back (i.e., when --show-toplevel failed), and going straight to the primary worktree lookup. Happy to make that change if you'd prefer it locked down.
We could tighten it by skipping the
config_path.exists()check whenroot()fell back (i.e., when--show-toplevelfailed), and going straight to the primary worktree lookup. Happy to make that change if you'd prefer it locked down.
yes, let's do this and see if we lose anything that we want
Done — #1697 skips the current-location config check for bare repos entirely and goes straight to the primary worktree. A .config/wt.toml in the bare repo root will no longer be picked up.