Files
auto-build/plugin/scripts/worktree-create.sh
Marius Mutu 940c6a9f58 feat: Move specs and memory to git for multi-developer collaboration (v1.0.6)
BREAKING CHANGE: Specs, plans, and memory moved from .auto-build-data/ (gitignored)
to .auto-build/ (git-tracked) to enable team collaboration.

Changes:
- Specs/plans now in .auto-build/specs/ (shared with team)
- Memory (patterns, gotchas) now in .auto-build/memory/ (shared with team)
- .auto-build-data/ now only contains local data (worktrees, cache)
- Added /ab:migrate command for existing projects
- Removed symlinks from worktree-create.sh (no longer needed)

Benefits:
- Any developer can continue a plan started by another
- Patterns and gotchas shared across team
- Works on Windows/Linux/Mac without symlinks
- Full version history in git

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-22 17:44:52 +02:00

115 lines
3.3 KiB
Bash

#!/bin/bash
# Create a git worktree for feature isolation
# Usage: worktree-create.sh <feature-name>
set -e
FEATURE_NAME="$1"
if [ -z "$FEATURE_NAME" ]; then
echo "Error: Feature name required"
echo "Usage: worktree-create.sh <feature-name>"
exit 1
fi
# Get project root from current working directory (where Claude Code is running)
# Note: This script is called from ${CLAUDE_PLUGIN_ROOT}/scripts/ but operates on the project
PROJECT_ROOT="$(pwd)"
PROJECT_NAME=$(basename "$PROJECT_ROOT")
# Define paths
BRANCH_NAME="feature/ab-${FEATURE_NAME}"
WORKTREES_DIR="$(dirname "$PROJECT_ROOT")/ab-worktrees"
WORKTREE_PATH="${WORKTREES_DIR}/${PROJECT_NAME}-${FEATURE_NAME}"
echo "========================================"
echo " Creating Git Worktree"
echo "========================================"
echo ""
echo "Feature: $FEATURE_NAME"
echo "Branch: $BRANCH_NAME"
echo "Path: $WORKTREE_PATH"
echo ""
# Check if we're in a git repository
if ! git -C "$PROJECT_ROOT" rev-parse --git-dir > /dev/null 2>&1; then
echo "Error: Not a git repository"
exit 1
fi
# Check for uncommitted changes
if ! git -C "$PROJECT_ROOT" diff-index --quiet HEAD -- 2>/dev/null; then
echo "Warning: You have uncommitted changes in the main repository"
echo ""
fi
# Create worktrees directory if needed
mkdir -p "$WORKTREES_DIR"
# Create branch if it doesn't exist
cd "$PROJECT_ROOT"
if git show-ref --verify --quiet "refs/heads/${BRANCH_NAME}"; then
echo "Branch already exists: ${BRANCH_NAME}"
else
echo "Creating branch: ${BRANCH_NAME}"
git branch "${BRANCH_NAME}"
fi
# Check if worktree already exists
if [ -d "$WORKTREE_PATH" ]; then
echo "Error: Worktree directory already exists: $WORKTREE_PATH"
echo "Use 'git worktree remove' to clean up first, or choose a different name"
exit 1
fi
# Create worktree
echo "Creating worktree..."
git worktree add "$WORKTREE_PATH" "$BRANCH_NAME"
# Note: No symlinks needed - specs and memory are in .auto-build/ (git-tracked)
# The worktree automatically has access to all shared data
# Update registry
REGISTRY_FILE="$PROJECT_ROOT/.auto-build-data/worktrees/worktree-registry.json"
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
if [ -f "$REGISTRY_FILE" ]; then
# Add to existing registry using jq if available, otherwise use simple append
if command -v jq &> /dev/null; then
TEMP_FILE=$(mktemp)
jq --arg name "$FEATURE_NAME" \
--arg branch "$BRANCH_NAME" \
--arg path "$WORKTREE_PATH" \
--arg created "$TIMESTAMP" \
'.worktrees += [{
"name": $name,
"branch": $branch,
"path": $path,
"created": $created,
"status": "active"
}]' "$REGISTRY_FILE" > "$TEMP_FILE" && mv "$TEMP_FILE" "$REGISTRY_FILE"
else
# Fallback: Just note the worktree was created
echo "Note: Install jq for automatic registry updates"
fi
fi
echo ""
echo "========================================"
echo " Worktree Created Successfully"
echo "========================================"
echo ""
echo "To work in this worktree:"
echo " cd $WORKTREE_PATH"
echo ""
echo "To return to main project:"
echo " cd $PROJECT_ROOT"
echo ""
echo "When done with the feature:"
echo " /ab:worktree cleanup $FEATURE_NAME"
echo ""
# Output for script parsing
echo "WORKTREE_CREATED=$WORKTREE_PATH"
echo "BRANCH=$BRANCH_NAME"