Skip to content

fix(git-guards): replace 'branch' with 'worktree' in error messages#191

Merged
JacobPEvans merged 3 commits intomainfrom
fix/worktree-error-message
Mar 29, 2026
Merged

fix(git-guards): replace 'branch' with 'worktree' in error messages#191
JacobPEvans merged 3 commits intomainfrom
fix/worktree-error-message

Conversation

@JacobPEvans
Copy link
Copy Markdown
Owner

@JacobPEvans JacobPEvans commented Mar 29, 2026

Summary

Replace "main branch" with "main worktree" in error messages to clarify terminology and prevent Claude from misinterpreting the guard's intent. Users were creating git branches instead of worktrees when blocked by the guard, indicating confusion about whether "main branch" meant the branch name or the literal main worktree directory.

Changes

  • main-branch-guard.sh: Updated error message from "Editing files on the main branch is not allowed" to "Editing files in the main worktree is not allowed"
  • main-branch-guard.sh: Changed second message from "Current branch is 'main'" to "You are in the main worktree" (more accurate and clearer)
  • main-branch-guard.py: Applied same messaging updates to Python implementation for consistency

All changes are user-facing error messages only — no logic changes.

Test Plan

  • Trigger main-branch-guard by attempting to edit a file in the main/ worktree
  • Verify error message says "main worktree" instead of "main branch"
  • Verify Claude responds by creating a worktree (not a git branch) when blocked
  • Confirm both shell and Python guards have consistent messaging

Claude interprets 'main branch' literally and creates a git branch
instead of a worktree. Use 'main worktree' consistently in all
user-facing error messages.

(claude)
Copilot AI review requested due to automatic review settings March 29, 2026 17:20
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the user-facing deny reasons emitted by the main-branch-guard hooks to prefer “main worktree” terminology, aiming to steer users/Claude toward creating Git worktrees instead of creating branches when edits are blocked.

Changes:

  • Updated deny message when the file is detected under a main/ worktree directory to say “main worktree”.
  • Updated deny message for the fallback “on main” detection path to also say “main worktree” (in both shell and Python implementations).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
git-guards/scripts/main-branch-guard.sh Adjusts permissionDecisionReason strings to say “main worktree”
git-guards/scripts/main-branch-guard.py Adjusts permissionDecisionReason strings to say “main worktree”

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the error messages in both the Python and Shell versions of the main branch guard script to use 'main worktree' terminology instead of 'main branch'. The review feedback suggests including the specific file path in all error messages for better context and consistency across the scripts. Additionally, it was noted that these hooks should exit with code 0 when returning a JSON payload, even for 'deny' decisions.

Add file path to the branch-name fallback check for consistency with the
worktree directory check. Both error messages now show the blocked file.

(claude)
@JacobPEvans JacobPEvans enabled auto-merge (squash) March 29, 2026 17:33
@JacobPEvans JacobPEvans merged commit d4bbc9f into main Mar 29, 2026
5 checks passed
@JacobPEvans JacobPEvans deleted the fix/worktree-error-message branch March 29, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants