# Directory Structure Creation

## Path Normalization for WSL

```bash
# If on WSL, translate Windows paths to /mnt/ format
# normalize_path_for_platform() from _shared.md handles this
# Example: D:/projects/MyApp → /mnt/d/projects/MyApp
PROJECT_BASE="{ROOT_FOLDER}"  # Must be already normalized for current platform
```

## Create Complete Structure

**⛔ CRITICAL: Use ABSOLUTE PATHS for ALL operations. NEVER use `cd` (it does not persist between Bash calls).**
**⛔ Use `git -C <path>` or `GIT_DIR=<path>` instead of `cd` + `git`.**

```bash
PROJECT_BASE="{ROOT_FOLDER}"

# Create subdirectories (absolute paths)
mkdir -p "$PROJECT_BASE/features" "$PROJECT_BASE/releases" "$PROJECT_BASE/hotfixes"

# Create bare repository if not exists (absolute path, no cd)
if [ ! -d "$PROJECT_BASE/.bare" ]; then
  git clone --bare "{REPO_URL}" "$PROJECT_BASE/.bare"

  # Configure bare repo for worktrees (using git -C, no cd)
  git -C "$PROJECT_BASE/.bare" config core.bare false
  git -C "$PROJECT_BASE/.bare" config core.worktree ..
fi

# Create .git pseudo-file pointing to .bare
echo "gitdir: ./.bare" > "$PROJECT_BASE/.git"

# Organized mode: numbered main folders (absolute paths, GIT_DIR instead of cd)
if [ "$WORKTREE_MODE" = "organized" ]; then
  [ ! -d "$PROJECT_BASE/01-Main" ] && \
    GIT_DIR="$PROJECT_BASE/.bare" git worktree add "$PROJECT_BASE/01-Main" main

  [ ! -d "$PROJECT_BASE/02-Develop" ] && \
    GIT_DIR="$PROJECT_BASE/.bare" git worktree add "$PROJECT_BASE/02-Develop" develop
fi

# Simple mode: named folders (absolute paths)
if [ "$WORKTREE_MODE" = "simple" ]; then
  [ ! -d "$PROJECT_BASE/main" ] && \
    GIT_DIR="$PROJECT_BASE/.bare" git worktree add "$PROJECT_BASE/main" main

  [ ! -d "$PROJECT_BASE/develop" ] && \
    GIT_DIR="$PROJECT_BASE/.bare" git worktree add "$PROJECT_BASE/develop" develop
fi

# Convert worktree paths to relative format (cross-platform: Windows + WSL)
detect_platform
repair_worktree_paths "$PROJECT_BASE/.bare"

# Create gitflow config directory (absolute paths)
DEVELOP_DIR=$([ "$WORKTREE_MODE" = "organized" ] && echo "02-Develop" || echo "develop")
mkdir -p "$PROJECT_BASE/$DEVELOP_DIR/.claude/gitflow/plans"
mkdir -p "$PROJECT_BASE/$DEVELOP_DIR/.claude/gitflow/logs"
mkdir -p "$PROJECT_BASE/$DEVELOP_DIR/.claude/gitflow/cache"
mkdir -p "$PROJECT_BASE/$DEVELOP_DIR/.claude/gitflow/backup"
```

## Folder Structure to Create

```
{ROOT_FOLDER}/
├── .bare/                 # Git bare repository (this repo only)
├── 01-Main/               # Worktree: main branch
├── 02-Develop/            # Worktree: develop branch
├── features/              # Feature branch worktrees
├── releases/              # Release branch worktrees
└── hotfixes/              # Hotfix branch worktrees
```
