Split unwanted changes into new child commit with AI description
Split unwanted changes from the current commit into a new child commit based on a pattern (test, docs, config, or custom glob). The original commit keeps wanted changes, while matching files move to a child commit with an AI-generated description.
/plugin marketplace add edmundmiller/dotfiles/plugin install jj@dotfiles-plugins<pattern>claude-haiku-4-5!# Source utility scripts
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" source "$SCRIPT_DIR/../hooks/jj-state.sh" source "$SCRIPT_DIR/../hooks/jj-templates.sh" source "$SCRIPT_DIR/../hooks/jj-diff-context.sh" source "$SCRIPT_DIR/../hooks/pattern-expand.sh"
!# Validate pattern argument
if [ -z "$ARGUMENTS" ]; then echo "❌ Error: Pattern required" echo "" echo "Usage: `/jj:split <pattern>`" echo "" echo "Common patterns:" echo "- `test` - Test and spec files" echo "- `docs` - Documentation (.md, README, CHANGELOG)" echo "- `config` - Config files (.json, .yaml, .toml)" echo "- Custom glob patterns (e.g., `.md`, `src/**/.test.ts`)" echo "" echo "What it does:" echo "1. Keeps wanted changes in current commit (@)" echo "2. Moves unwanted (matching pattern) changes to new child commit" echo "3. Auto-generates description for child commit" echo "" echo "Example: `/jj:split test` - splits test files into new child commit" exit 0 fi
jj statusformat_commit_shortget_diff_summarySplit unwanted changes matching pattern "$ARGUMENTS" from current commit (@) into a new child commit with an AI-generated description.
Pattern Expansion (handled by expand_pattern function):
test → Test files: *test*.{py,js,ts,jsx,tsx,java,go,rs,cpp,c,h}, *spec*, test_*, *_test.*docs → Documentation: *.md, README*, CHANGELOG*, LICENSE*, docs/**/*config → Config files: *.json, *.yaml, *.yml, *.toml, *.ini, *.conf, .*rc, .*ignoreUse: PATTERNS=$(expand_pattern "$ARGUMENTS") to get the appropriate jj move flags.
Workflow:
jj new @ to create empty child where split changes will gojj move --from @- -p 'glob:pattern' to move unwanted files from parent to child~/bin/jj-ai-desc.py @ to analyze split changes and generate commit messageResult structure:
@ (new child): unwanted changes with AI description
@- (original): wanted changes, original description preserved
Important notes:
-p flags for multiple patterns: jj move --from @- -p 'glob:*.md' -p 'glob:README*''glob:pattern'Example execution:
# Get patterns using expand_pattern function
PATTERNS=$(expand_pattern "$ARGUMENTS")
# Split test files
jj new @
eval "jj move --from @- $PATTERNS" # eval needed to expand the pattern flags
~/bin/jj-ai-desc.py @
# Or manually for specific cases:
# Split test files
jj new @
jj move --from @- $(expand_pattern "test")
~/bin/jj-ai-desc.py @
# Split documentation
jj new @
jj move --from @- $(expand_pattern "docs")
~/bin/jj-ai-desc.py @
# Split config files
jj new @
jj move --from @- $(expand_pattern "config")
~/bin/jj-ai-desc.py @
Final verification:
Show the result: !format_commit_list '@|@-'