Skip to content

fix(commit-commands): handle initial commit when no commits exist yet#33234

Open
sakumoto-shota wants to merge 1 commit intoanthropics:mainfrom
sakumoto-shota:fix/commit-commands-initial-commit
Open

fix(commit-commands): handle initial commit when no commits exist yet#33234
sakumoto-shota wants to merge 1 commit intoanthropics:mainfrom
sakumoto-shota:fix/commit-commands-initial-commit

Conversation

@sakumoto-shota
Copy link
Copy Markdown

Summary

  • Fix /commit-commands:commit failing with fatal: your current branch does not have any commits yet

Changes

  • plugins/commit-commands/commands/commit.md: Add error handling for repos with no commits
    • git diff HEAD falls back to git diff --cached (shows staged changes without HEAD)
    • git log --oneline -10 falls back to "No commits yet (initial commit)"

Testing

Tested in a fresh git init repo with no commits:

  • git diff HEAD 2>/dev/null || git diff --cached — shows staged diff correctly
  • git log --oneline -10 2>/dev/null || echo "No commits yet (initial commit)" — shows fallback message
  • Both commands still work normally in repos with existing commits

Fixes #24881

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.

[BUG] /commit-commands:commit doesn't work when there are no commits yet

1 participant