Instruction file imported from squirrelogic/cursor-rules (
.cursor/rules/git-commit-workflow.mdc). Copyright stays with the author.
Git Commit Workflow Rule
Description
This rule defines the complete workflow for validating changes, running tests, and creating commits. It ensures that all changes are properly tested and validated before being committed using the conventional commits format.
Rule Type
workflow
Rule Format
{
"type": "workflow",
"name": "git_commit_workflow",
"description": "Validates changes and creates conventional commits",
"filters": [
{
"type": "event",
"pattern": "pre_commit"
}
],
"steps": [
{
"action": "validate",
"description": "Run tests and type checks",
"requirements": [
"All tests MUST pass",
"TypeScript compilation MUST succeed",
"Build process MUST complete successfully"
]
},
{
"action": "execute",
"description": "Validate and commit changes",
"script": {
"steps": [
{
"name": "run_tests",
"command": "npm test",
"on_failure": "abort"
},
{
"name": "type_check",
"command": "npm run type-check",
"on_failure": "abort"
},
{
"name": "build",
"command": "npm run build",
"on_failure": "abort"
},
{
"name": "check_changes",
"command": "git status --porcelain",
"store_output": "CHANGED_FILES"
},
{
"name": "stage_changes",
"command": "git add ."
},
{
"name": "create_commit",
"use_rule": "conventional-commits"
}
]
}
}
]
}
Workflow Steps
-
Run Tests
- Execute the test suite using
npm test - Abort if any tests fail
- Ensure all new features have corresponding tests
- Execute the test suite using
-
Type Checking
- Run TypeScript type checking
- Verify no type errors exist
- Abort if type checking fails
-
Build Process
- Run the build process
- Ensure the project builds successfully
- Abort if build fails
-
Check Changes
- Use
git statusto identify modified files - Review changes before staging
- Ensure no unintended files are included
- Use
-
Stage Changes
- Stage all relevant files using
git add - Review staged changes if needed
- Stage all relevant files using
-
Create Commit
- Use conventional-commits rule to format commit message
- Follow proper commit message structure
- Include appropriate type, scope, and description
Integration with Conventional Commits
This workflow automatically integrates with the conventional-commits rule to ensure proper commit message formatting. The workflow will:
- Detect the appropriate commit type based on changes
- Generate a properly formatted commit message
- Include relevant scope based on changed files
- Add detailed body explaining changes
- Include footer with issue references if applicable
Examples
Feature Development
# 1. Run tests
npm test
# 2. Type check
npm run type-check
# 3. Build
npm run build
# 4. Check changes
git status
# 5. Stage changes
git add .
# 6. Create commit (using conventional-commits rule)
printf "feat(auth): implement OAuth2 support\n\nAdd Google and GitHub provider integration\nImplement token refresh handling\n\nCloses #123" | git commit -F -
Bug Fix
# Follow the same workflow
npm test && npm run type-check && npm run build
git status
git add .
printf "fix(api): resolve user data serialization issue\n\nFix incorrect handling of nested user properties\n\nCloses #456" | git commit -F -
Error Handling
- If any validation step fails, the workflow will abort
- Test failures must be resolved before proceeding
- Type errors must be fixed before commit
- Build errors must be addressed
- Proper error messages will be displayed for each failure
Notes
- Always run this workflow before creating commits
- Ensure all tests are up to date
- Keep commits focused and atomic
- Follow the conventional commits format
- Use meaningful commit messages