fix: add default-branch guard to commit skills (#386)

This commit is contained in:
Trevin Chow
2026-03-25 21:41:17 -07:00
committed by GitHub
parent f819e435a5
commit 31f07c0047
2 changed files with 21 additions and 1 deletions

View File

@@ -18,10 +18,21 @@ command git status
command git diff HEAD
command git branch --show-current
command git log --oneline -10
command git rev-parse --abbrev-ref origin/HEAD
```
The last command returns the remote default branch (e.g., `origin/main`). Strip the `origin/` prefix to get the branch name. If the command fails or returns a bare `HEAD`, try:
```bash
command gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'
```
If both fail, fall back to `main`.
If there are no changes (nothing staged, nothing modified), report that and stop.
If the current branch matches `main`, `master`, or the resolved default branch name, warn the user and ask whether to continue committing here or create a feature branch first. Use the platform's blocking question tool (`AskUserQuestion` in Claude Code, `request_user_input` in Codex, `ask_user` in Gemini). If no question tool is available, present the options and wait for the user's reply before proceeding. If the user chooses to create a branch, derive the name from the change content and switch to it before continuing.
### Step 2: Determine commit message convention
Follow this priority order: