#!/usr/bin/env bash
# Exercise 15.1: put the book's folder under Git and make the first commit. Run: bash first-commit.sh
# It works in a temporary copy, with a few files standing in for chapters 1 to 14.
set -e
export GIT_AUTHOR_NAME="Sara Khan" GIT_AUTHOR_EMAIL="sara@example.com"
export GIT_COMMITTER_NAME="$GIT_AUTHOR_NAME" GIT_COMMITTER_EMAIL="$GIT_AUTHOR_EMAIL"
export GIT_CONFIG_GLOBAL=/dev/null  # ignore your own Git settings while the script runs
run() { local s="\$"; for a in "$@"; do if [[ $a == *" "* ]]; then s+=" \"$a\""; else s+=" $a"; fi; done; echo "$s"; "$@"; }
cd "$(mktemp -d)"
mkdir -p code-from-zero/chapter-01 code-from-zero/chapter-05
echo 'console.log("Hello, world!");' > code-from-zero/chapter-01/hello.js
echo '<h1>Sara</h1>' > code-from-zero/chapter-05/profile.html
cd code-from-zero

run git init -q -b main
run git status --short
run git add .
run git commit -q -m "Add everything from chapters 1 to 14"
run git log --oneline --stat
