--- name: submodule description: Add git submodules with proper registration, verification, and optional commit --- # Git Submodule Workflow Add git submodules correctly with full verification to prevent registration issues. ## Usage - `/submodule ` - Add submodule with specified URL and path - `/submodule` - Interactive mode, will prompt for URL and path ## Workflow ### Step 1: Gather Information If not provided, ask the user for: - **Repository URL** (required) - The git repository to add as submodule - **Target path** (required) - Where to place the submodule (relative to project root) ### Step 2: Pre-flight Checks Before adding, verify: ```bash # Check if path already exists ls -la 2>/dev/null && echo "WARNING: Path exists" # Check if already in .gitmodules grep -q "" .gitmodules 2>/dev/null && echo "WARNING: Already in .gitmodules" # Check current submodule status git submodule status ``` If path exists but isn't a proper submodule, it may need cleanup first. ### Step 3: Add Submodule ```bash git submodule add ``` ### Step 4: Verify Registration (4-Point Check) All four checks must pass: ```bash # 1. Check .gitmodules has entry grep -A2 "" .gitmodules # 2. Check git submodule status shows it git submodule status | grep "" # 3. Check .git/modules// exists ls .git/modules// # 4. Check submodule has proper .git file cat /.git # Should show: gitdir: ../../.git/modules/ ``` ### Step 5: Recovery (If Verification Fails) If the submodule exists but isn't registered: ```bash # Remove from index without deleting files git rm --cached # Re-add properly git submodule add ``` If .gitmodules entry exists but submodule isn't in index: ```bash # Re-register existing directory git submodule add ``` ### Step 6: Stage and Review ```bash # Check what's staged git status # Should show: # new file: .gitmodules (if first submodule or modified) # new file: ``` ### Step 7: Commit (Optional) If user wants to commit: ```bash git commit -m "chore: add git submodule at " ``` ## Common Issues | Issue | Cause | Fix | |-------|-------|-----| | "already exists in index" | Path was added but not as submodule | `git rm --cached ` then re-add | | Shows as untracked directory | Submodule not in git index | Run `git submodule add` on existing dir | | Warning about embedded repo | Directory has .git but not registered | Use `git submodule add` not `git clone` |