Skip to content

fix: resolve {{ repo }} to project name instead of .git in bare repos - #1545

Closed
worktrunk-bot wants to merge 2 commits into
mainfrom
fix/issue-1543
Closed

worktrunk-bot wants to merge 2 commits into
mainfrom
fix/issue-1543

Conversation

@worktrunk-bot

Copy link
Copy Markdown
Collaborator

Problem

In the nested bare repository layout (project/.git as bare repo), the {{ repo }} template variable resolved to .git instead of the project name. This made features like subdomain routing with Caddy unusable since all repos shared the same name.

This is a regression/re-report of #1279, whose fix branch was never merged.

Solution

Add Repository::repo_name() that derives a human-readable name from repo_path():

  • project/.git → "project" (parent directory name)
  • project/.bare → "project" (parent directory name)
  • project.git → "project" (strip .git suffix)
  • project → "project" (normal repos unchanged)

Updated build_hook_context() and compute_worktree_path() to use the new method.

Testing

Added test_nested_bare_repo_template_var_repo_name integration test that creates a project/.git bare repo layout, configures a hook using {{ repo }}, and verifies it resolves to "project".


Closes #1543 — automated triage

In the nested bare repository layout (project/.git as bare repo), the
{{ repo }} template variable resolved to ".git" instead of "project".
Add Repository::repo_name() that handles .git/.bare directory names
by using the parent directory, and strips .git suffixes from bare repo
names like project.git.

Closes #1543

Co-authored-by: Claude <[email protected]>

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same file_name().unwrap_or(...) pattern exists in two more places that will also resolve to .git in bare repos:

  • src/llm.rs:551 — render_commit_template()
  • src/commands/step_commands.rs:300 and :385 — run_squash_step() and inspect_squash_prompt()

These use wt.root() but feed the result into the same repo template variable. Should be migrated to repo.repo_name() for consistency.

Happy to push a fix commit.

Same bare-repo bug existed in llm.rs and step_commands.rs where
{{ repo }} would resolve to ".git" instead of the project name.

Co-Authored-By: Claude <[email protected]>
worktrunk-bot added a commit that referenced this pull request Mar 16, 2026
Previously, claude-mention triggered on `issues: [opened, edited]` while
claude-issue-triage skipped issues mentioning @worktrunk-bot. This caused
races when a user both commented on an existing issue and filed a new one
— two workflows independently created fix PRs for the same bug (#1544/#1545).

Now triage handles all new issues (including @worktrunk-bot mentions),
and mention only triggers on issue edits. This eliminates the race for
new issues while preserving the ability to summon the bot by editing an
existing issue.

Ref: #1548 (comment)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner

using #1281

@max-sixty max-sixty closed this Mar 16, 2026
max-sixty pushed a commit that referenced this pull request Mar 21, 2026
…ixes (#1548)

## Problem

When a user both comments on an existing issue AND files a new issue
within seconds (as happened with #1279/#1543), two independent workflows
(`claude-mention` and `claude-issue-triage`) race to create fix PRs.
This produced duplicate PRs #1544 and #1545, which modify the exact same
6 files with nearly identical changes.

The review bot then reviewed both PRs independently and even posted
misleading feedback on #1545 — flagging "missing" call site migrations
in `src/llm.rs` and `src/commands/step_commands.rs` that PR #1544
already handles.

**Evidence:** Run 23121388888 (review of #1545) posted a COMMENT
suggesting files that the sibling PR #1544 already covers. Run
23121179226 (review of #1544) found no issues but didn't detect the
duplication either.

This is a variant of #1428 but affects user-triggered events (not
bot-authored), so the existing bot-author filter from #1429 doesn't
help.

## Fix

Add a new **Step 2: Check for overlapping PRs** to the review-pr skill.
Before reading the diff, the reviewer checks whether other open
bot-authored PRs touch the same files. If overlap is found, it's flagged
in the review so one can be closed as a duplicate.

Also renumbers subsequent steps (3→4, 4→5, etc.) and updates internal
cross-references.

## Why this approach

- **Catches duplicates at review time** — the cheapest point to detect,
since both PRs exist by then
- **Doesn't require workflow coordination** — no locking or
inter-workflow communication needed
- **Low false-positive risk** — overlapping files on bot PRs with
similar fixes is a strong signal

The underlying race between triage and mention workflows remains (fixing
that would require cross-workflow locking), but this ensures the
reviewer surfaces the duplication for human action.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: worktrunk-bot <[email protected]>
Co-authored-by: Claude <[email protected]>
@max-sixty
max-sixty deleted the fix/issue-1543 branch June 18, 2026 06:00
max-sixty pushed a commit that referenced this pull request Nov 28, 2026
…#4908)

`{{ repo }}` in commit and squash prompt templates now renders the
repository's name in every worktree. Before, it rendered the current
worktree's folder name, so a custom template run from a linked worktree
at `~/code/myrepo.feature` got `myrepo.feature`. A hook in the same
worktree gets `myrepo`, and [the LLM commits
docs](https://worktrunk.dev/llm-commits/) describe the variable as
"Repository name".

The three prompt sites (`build_commit_prompt`, the squash preview, the
squash run) each derived the name from `wt.root()`. They now share
`llm::prompt_repo_name`, which reads `Repository::repo_path()`, the same
source `build_hook_context` and the worktree-path template use. The
default templates don't reference `{{ repo }}`, so only custom templates
are affected.

One effect to know about: in a nested bare layout (`project/.git` with
worktrees beside it), the prompt's `repo` changes from the worktree's
folder name (e.g. `main`) to `.git`. That's the value hooks already get
there. Naming bare repos better was discussed in #1281, #1544 and #1545,
and this PR doesn't change that.

The new test
`test_prompt_repo_names_the_repository_from_a_linked_worktree` covers
`commit --show-prompt`, `squash --show-prompt`, `squash --dry-run`, and
a real squash, all from a linked worktree. On `main` it fails with
`repo=repo.feature`; with the fix it passes. The `merge::` and
`bare_repository::` integration tests also pass locally, except
`test_merge_no_ff_signs_merge_commit`, which fails the same way on
`main` in this sandbox (ssh refuses the test's signing key because its
file permissions are too open).

Co-authored-by: worktrunk-bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated-fix Automated CI fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In a bare repo layout the template var repo resolves to .git

2 participants