|
| 1 | +# Create Commits Command |
| 2 | + |
| 3 | +This command automates the creation of logical, well-structured commits with intelligent grouping by function and descriptive messages, including code quality validation and proper branch management. |
| 4 | + |
| 5 | +## Command Usage |
| 6 | + |
| 7 | +- `create-commits` - Basic usage with current branch |
| 8 | +- `create-commits --base develop` - Create commits with custom base branch reference |
| 9 | + |
| 10 | +### Flag Details |
| 11 | + |
| 12 | +- `--base <branch-name>` - Specify the base branch for reference (default: main) |
| 13 | + - Useful when working with feature branches or dependent branches |
| 14 | + - Helps determine which changes are new since branching from base |
| 15 | + |
| 16 | +## Workflow |
| 17 | + |
| 18 | +### 1. Branch Management |
| 19 | + |
| 20 | +- Check current branch name using `git branch --show-current` |
| 21 | +- Determine base branch (default: `main`, or value from `--base` flag) |
| 22 | +- Validate base branch exists: `git show-ref --verify refs/heads/<base-branch>` or `git ls-remote --heads origin <base-branch>` |
| 23 | +- If current branch is same as base branch: |
| 24 | + - Analyze staged and unstaged changes to determine scope |
| 25 | + - Create new branch with format: `<scope>/auto-<timestamp>-<short-description>` |
| 26 | + - Example: `feat/auto-20250625-dataset-metadata-updates` |
| 27 | +- If current branch is different from base branch: |
| 28 | + - Use existing branch for commit creation |
| 29 | + - Verify branch is not behind remote base branch: `git merge-base --is-ancestor origin/<base-branch> HEAD` |
| 30 | + |
| 31 | +### 2. Pre-Commit Validation |
| 32 | + |
| 33 | +Execute the following commands in sequence and stop if any fail: |
| 34 | + |
| 35 | +- Run `pnpm lint` to check for linting issues |
| 36 | +- If linting fails, run `pnpm lint:fix` to auto-fix issues |
| 37 | +- Run `pnpm data-portal type-check` to verify TypeScript types |
| 38 | +- If type check fails, report specific errors and require manual fixes before proceeding |
| 39 | + |
| 40 | +### 3. Change Analysis and Commit Splitting |
| 41 | + |
| 42 | +Analyze all staged and unstaged changes to intelligently group them: |
| 43 | + |
| 44 | +#### File Grouping Logic: |
| 45 | + |
| 46 | +- **UI Components**: Group `*.tsx` files in `/components/` together |
| 47 | +- **GraphQL Operations**: Group `*.server.ts` files in `/graphql/` together |
| 48 | +- **Type Definitions**: Group `__generated_v2__/**/*.ts` files together |
| 49 | +- **Translations**: Group `translation.json` changes separately |
| 50 | +- **Configuration**: Group config files (`*.config.*`, `package.json`, etc.) together |
| 51 | +- **Tests**: Group test files (`*.test.*`, `*.spec.*`) together |
| 52 | +- **Documentation**: Group `*.md` files together |
| 53 | + |
| 54 | +#### Commit Creation Strategy: |
| 55 | + |
| 56 | +1. **Single Logical Changes**: Each commit should represent one cohesive change |
| 57 | +2. **Component-Based Grouping**: Changes to a component and its related files go together |
| 58 | +3. **Feature Boundaries**: Don't mix different features in the same commit |
| 59 | +4. **Dependency Order**: Commit dependencies (types, GraphQL) before dependents (components) |
| 60 | + |
| 61 | +### 4. Commit Message Generation |
| 62 | + |
| 63 | +For each commit group, generate messages using this format: `<scope>: <description>` |
| 64 | + |
| 65 | +#### Scope Selection Rules: |
| 66 | + |
| 67 | +- `feat`: New features, components, or major functionality additions |
| 68 | +- `fix`: Bug fixes, error corrections, or issue resolutions |
| 69 | +- `refactor`: Code restructuring without functional changes |
| 70 | +- `style`: CSS, styling, or visual updates |
| 71 | +- `docs`: Documentation updates or README changes |
| 72 | +- `test`: Adding or updating tests |
| 73 | +- `chore`: Maintenance, dependencies, or tooling updates |
| 74 | +- `perf`: Performance improvements |
| 75 | +- `build`: Build system or deployment changes |
| 76 | +- `ci`: Continuous integration configuration |
| 77 | + |
| 78 | +#### Description Guidelines: |
| 79 | + |
| 80 | +- Use present tense ("add" not "added") |
| 81 | +- Keep under 50 characters for the title |
| 82 | +- Be specific about what changed |
| 83 | +- Examples: |
| 84 | + - `feat: add dataset metadata display table` |
| 85 | + - `fix: resolve GraphQL type generation errors` |
| 86 | + - `refactor: extract reusable metadata components` |
| 87 | + |
| 88 | +### 5. Commit Execution |
| 89 | + |
| 90 | +For each commit group: |
| 91 | + |
| 92 | +1. Stage only the files belonging to that group using `git add <files>` |
| 93 | +2. Create commit with generated message |
| 94 | +3. Verify commit was created successfully |
| 95 | +4. Continue to next group |
| 96 | + |
| 97 | +## Error Handling |
| 98 | + |
| 99 | +### Lint Failures: |
| 100 | + |
| 101 | +- Attempt auto-fix with `pnpm lint:fix` |
| 102 | +- If still failing, list specific errors and pause for manual resolution |
| 103 | + |
| 104 | +### Type Check Failures: |
| 105 | + |
| 106 | +- Display TypeScript errors clearly |
| 107 | +- Require manual fixes before proceeding |
| 108 | +- Suggest running `pnpm data-portal build:codegen` if GraphQL types are stale |
| 109 | + |
| 110 | +### Git Conflicts: |
| 111 | + |
| 112 | +- If branch is behind base branch, suggest rebasing first: `git rebase origin/<base-branch>` |
| 113 | +- If conflicts exist, pause and request manual resolution |
| 114 | + |
| 115 | +### Base Branch Validation: |
| 116 | + |
| 117 | +- If specified base branch doesn't exist locally or remotely, list available branches and exit |
| 118 | +- If current branch is the same as base branch, require creation of new branch first |
| 119 | +- If base branch is not accessible, suggest fetching: `git fetch origin <base-branch>` |
| 120 | + |
| 121 | +### Empty Changes: |
| 122 | + |
| 123 | +- If no staged or unstaged changes exist, inform user and exit gracefully |
| 124 | + |
| 125 | +## Success Confirmation |
| 126 | + |
| 127 | +After successful commit creation: |
| 128 | + |
| 129 | +1. Display summary of commits created with messages |
| 130 | +2. Show branch status and commit count |
| 131 | +3. Confirm all validation checks passed |
| 132 | + |
| 133 | +## Advanced Features |
| 134 | + |
| 135 | +### Commit Message Enhancement: |
| 136 | + |
| 137 | +- Analyze file diffs to understand the nature of changes |
| 138 | +- Include relevant component names or feature areas |
| 139 | + |
| 140 | +### Quality Gates: |
| 141 | + |
| 142 | +- Ensure all commits have proper conventional format |
| 143 | +- Verify no sensitive information is being committed |
| 144 | +- Check that commit messages are descriptive and meaningful |
| 145 | + |
| 146 | +### Base Branch Validation Requirements: |
| 147 | + |
| 148 | +1. **Branch Existence Check**: Verify base branch exists using `git show-ref --verify refs/heads/<base-branch>` (local) or `git ls-remote --heads origin <base-branch>` (remote) |
| 149 | +2. **Branch Accessibility**: Ensure base branch is up-to-date with remote: `git fetch origin <base-branch>` |
| 150 | +3. **Self-Reference Prevention**: Prevent creating commits when current branch equals base branch without creating new branch first |
| 151 | +4. **Branch Relationship Validation**: Check if current branch has diverged from base branch using `git merge-base <base-branch> HEAD` |
| 152 | + |
| 153 | +## Workflow Summary |
| 154 | + |
| 155 | +1. **Validate Environment**: Check branch status and base branch |
| 156 | +2. **Quality Validation**: Run linting and type checking |
| 157 | +3. **Analyze Changes**: Group files logically by function and feature |
| 158 | +4. **Generate Messages**: Create descriptive conventional commit messages |
| 159 | +5. **Execute Commits**: Create commits in logical order with proper staging |
| 160 | +6. **Confirm Success**: Validate all commits were created successfully |
0 commit comments