#!/bin/sh
# Run with: sh worktrees-demo.sh. Requires Git and a POSIX shell.
# All files are created under a new temporary directory; your project is untouched.
set -eu
workshop=$(mktemp -d "${TMPDIR:-/tmp}/codeck-worktrees.XXXXXX")
printf 'Tutorial directory: %s\n' "$workshop"
git --version
git init -q -b main "$workshop/project"
cd "$workshop/project"
git config user.name 'Tutorial Example'
git config user.email 'tutorial@example.invalid'
printf '# Demo\n' > README.md
git add README.md
git commit -qm 'Initial snapshot'
git worktree add -b codex/docs ../docs-task main
git worktree add -b codex/checks ../checks-task main
printf 'Documentation task\n' > ../docs-task/guide.txt
git -C ../docs-task add guide.txt
git -C ../docs-task commit -qm 'Add guide'
printf 'Verification task\n' > ../checks-task/checks.txt
git -C ../checks-task add checks.txt
git -C ../checks-task commit -qm 'Add checks'
git worktree list
git diff --stat main...codex/docs
git diff --stat main...codex/checks
git merge --no-edit codex/docs
git merge --no-edit codex/checks
test -f guide.txt && test -f checks.txt
git worktree remove ../docs-task
git worktree remove ../checks-task
git branch -d codex/docs codex/checks
printf 'PASS: both files integrated; linked worktrees removed\n'
git status --short
printf 'The disposable main repository remains at %s/project\n' "$workshop"
