diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 00000000..79a83443 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Runs the same content consistency checks CI runs, so drift between slides, +# exercises and diagrams is caught locally before it ever reaches a push. +# +# Not wired in by default: git only looks in .git/hooks, which isn't tracked. +# Enable it once per clone with: +# git config core.hooksPath .githooks + +set -euo pipefail + +repo_root=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd) +cd "$repo_root" + +# Keep the per-check "n. ... / ok: ..." rundown quiet on a passing commit; show +# it only when something actually failed, so it's there to diagnose but doesn't +# scroll past on every commit. +if output=$(bash advanced/tests/check_consistency.sh 2>&1); then + status=0 +else + status=$? +fi + +if [ "$status" -ne 0 ]; then + echo "$output" + echo "" + echo "Content consistency checks failed, commit aborted." + echo "Fix the issues above, or bypass this hook with 'git commit --no-verify'." + exit 1 +fi + +echo "$output" | tail -n 1 diff --git a/.github/workflows/build_advanced_slides.yml b/.github/workflows/build_advanced_slides.yml index 8c7cfc17..b79b3096 100644 --- a/.github/workflows/build_advanced_slides.yml +++ b/.github/workflows/build_advanced_slides.yml @@ -13,6 +13,10 @@ on: permissions: contents: write +concurrency: + group: build-advanced-slides-${{ github.ref }} + cancel-in-progress: true + jobs: build-pdf: runs-on: ubuntu-latest @@ -28,23 +32,31 @@ jobs: with: node-version: 22 - - name: Build PDF - run: | - npx @marp-team/marp-cli@latest advanced/slides/slides.md \ - --theme-set slides_theme/c2sm-light.css slides_theme/c2sm-dark.css \ - --pdf \ - --allow-local-files \ - -o advanced/slides/slides_advanced.pdf + - name: Build diagrams and PDF + # Same script authors run locally, so the committed PDF cannot drift. + run: ./advanced/slides/build.sh - - name: Commit updated PDF to PR branch + - name: Commit updated diagrams and PDF to PR branch run: | git config user.name "GitHub Action" git config user.email "action@github.com" - git add advanced/slides/slides_advanced.pdf + git add advanced/slides/images advanced/slides/slides_advanced.pdf if git diff --cached --quiet; then - echo "PDF is already up to date." + echo "Diagrams and PDF are already up to date." else - git commit -m "Update advanced slides PDF" - git push origin HEAD:${{ github.head_ref }} - fi \ No newline at end of file + # [skip ci] stops GitHub from queuing new workflow runs for this commit, + # so fork PRs don't need a fresh manual approval after every auto-push. + git commit -m "Update advanced slides diagrams and PDF [skip ci]" + + # The sibling beginner-slides workflow can push to this same branch at + # the same time (both trigger on shared slides_theme/** changes), so + # retry with a rebase if another push landed first. + for attempt in 1 2 3 4 5; do + git push origin HEAD:${{ github.head_ref }} && break + [[ $attempt -eq 5 ]] && { echo "::error::Push failed after $attempt attempts"; exit 1; } + echo "Push rejected, rebasing onto latest and retrying..." + git fetch origin ${{ github.head_ref }} + git rebase FETCH_HEAD + done + fi diff --git a/.github/workflows/build_beginner_slides.yml b/.github/workflows/build_beginner_slides.yml index a8cc6cee..108449ce 100644 --- a/.github/workflows/build_beginner_slides.yml +++ b/.github/workflows/build_beginner_slides.yml @@ -13,6 +13,10 @@ on: permissions: contents: write +concurrency: + group: build-beginner-slides-${{ github.ref }} + cancel-in-progress: true + jobs: build-pdf: runs-on: ubuntu-latest @@ -29,12 +33,8 @@ jobs: node-version: 22 - name: Build PDF - run: | - npx @marp-team/marp-cli@latest beginner/slides/slides.md \ - --theme-set slides_theme/c2sm-light.css slides_theme/c2sm-dark.css \ - --pdf \ - --allow-local-files \ - -o beginner/slides/slides_beginner.pdf + # Same script authors run locally, so the committed PDF cannot drift. + run: ./beginner/slides/build.sh - name: Commit updated PDF to PR branch run: | @@ -45,6 +45,18 @@ jobs: if git diff --cached --quiet; then echo "PDF is already up to date." else - git commit -m "Update beginner slides PDF" - git push origin HEAD:${{ github.head_ref }} + # [skip ci] stops GitHub from queuing new workflow runs for this commit, + # so fork PRs don't need a fresh manual approval after every auto-push. + git commit -m "Update beginner slides PDF [skip ci]" + + # The sibling advanced-slides workflow can push to this same branch at + # the same time (both trigger on shared slides_theme/** changes), so + # retry with a rebase if another push landed first. + for attempt in 1 2 3 4 5; do + git push origin HEAD:${{ github.head_ref }} && break + [[ $attempt -eq 5 ]] && { echo "::error::Push failed after $attempt attempts"; exit 1; } + echo "Push rejected, rebasing onto latest and retrying..." + git fetch origin ${{ github.head_ref }} + git rebase FETCH_HEAD + done fi \ No newline at end of file diff --git a/.github/workflows/content_consistency.yml b/.github/workflows/content_consistency.yml new file mode 100644 index 00000000..620d3418 --- /dev/null +++ b/.github/workflows/content_consistency.yml @@ -0,0 +1,23 @@ +name: Content consistency + +# Catches exactly the kind of drift that made the 2026 content update necessary in the +# first place: slides referencing an exercise that no longer exists, an exercise the +# slides never mention, or a diagram that got renamed on one side but not the other. + +on: + pull_request: + paths: + - "advanced/**" + - "beginner/**" + - ".github/workflows/content_consistency.yml" + + workflow_dispatch: + +jobs: + consistency: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Check that slides, exercises and diagrams agree + run: bash advanced/tests/check_consistency.sh diff --git a/.github/workflows/publish_pages.yml b/.github/workflows/publish_pages.yml new file mode 100644 index 00000000..353f120d --- /dev/null +++ b/.github/workflows/publish_pages.yml @@ -0,0 +1,84 @@ +name: Publish Slides to GitHub Pages + +on: + push: + branches: + - main + paths: + - "advanced/slides/**" + - "beginner/slides/**" + - "slides_theme/**" + - "pages/**" + - ".github/workflows/publish_pages.yml" + + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +# Never cancel a deployment half-way: let a running one finish before the next starts. +concurrency: + group: pages + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Check out repository + uses: actions/checkout@v5 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Build both decks + # Same scripts authors run locally, so the published site cannot drift. + run: | + ./beginner/slides/build.sh + ./advanced/slides/build.sh + + - name: Assemble site + # The theme stylesheets reference the C2SM logo and the title background as + # ../../slides_theme/images/..., relative to the deck. That only resolves if + # the site mirrors the repository layout, so keep the /slides/ depth + # and ship slides_theme/images alongside. + run: | + mkdir -p _site/slides_theme _site/advanced _site/beginner + + cp pages/index.html _site/index.html + cp -r slides_theme/images _site/slides_theme/ + + cp -r advanced/slides _site/advanced/ + cp -r beginner/slides _site/beginner/ + + # Serve each deck at /slides/ instead of a long file name. + mv _site/advanced/slides/slides_advanced.html _site/advanced/slides/index.html + mv _site/beginner/slides/slides_beginner.html _site/beginner/slides/index.html + + # Sources and build inputs have no business on the published site. + rm -rf _site/*/slides/diagrams + rm -f _site/*/slides/slides.md _site/*/slides/build.sh + rm -f _site/*/slides/images/.diagram-hashes + + - name: Upload Pages artifact + uses: actions/upload-pages-artifact@v3 + with: + path: _site + + deploy: + needs: build + runs-on: ubuntu-latest + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/shellcheck.yml b/.github/workflows/shellcheck.yml new file mode 100644 index 00000000..a61db364 --- /dev/null +++ b/.github/workflows/shellcheck.yml @@ -0,0 +1,30 @@ +name: Shellcheck + +# The exercises lean on several shell scripts to bootstrap sandboxes and self-test. +# A bug in one of them breaks the course for everyone following it, so lint them like +# the code they are. + +on: + pull_request: + paths: + - "**.sh" + - ".github/workflows/shellcheck.yml" + + workflow_dispatch: + +jobs: + shellcheck: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@master + with: + severity: warning + # beginner/helpers.sh predates this workflow and is not part of this task's + # scope; it has its own pre-existing style warnings (unquoted variables, + # unchecked cd) that are a separate cleanup, not a regression to gate on here. + # A trailing single file cannot be excluded by name alone: the action's find + # walks from scandir "." and only matches "./beginner/helpers.sh" verbatim. + ignore_paths: ./beginner/helpers.sh diff --git a/.github/workflows/test_helpers.yml b/.github/workflows/test_helpers.yml new file mode 100644 index 00000000..1bfb2ca7 --- /dev/null +++ b/.github/workflows/test_helpers.yml @@ -0,0 +1,56 @@ +name: Test helper functions + +# The helper scripts bootstrap every exercise, so they have to work on every platform +# the course is taught on: Linux, macOS and Git Bash for Windows. windows-latest ships +# Git for Windows, and a step with `shell: bash` runs under its Git Bash - so this +# actually exercises the platform that issue #147 was raised about, not a stand-in for it. + +on: + pull_request: + paths: + - "advanced/helpers.sh" + - "advanced/examples/**" + - "advanced/tests/**" + - "beginner/helpers.sh" + - "beginner/examples/**" + - "beginner/tests/**" + - ".github/workflows/test_helpers.yml" + + workflow_dispatch: + +jobs: + test: + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + + runs-on: ${{ matrix.os }} + + defaults: + run: + # windows-latest defaults to PowerShell; this makes every step below use the + # Git Bash that ships with Git for Windows instead, on all three platforms. + shell: bash + + steps: + - name: Check out the course + uses: actions/checkout@v5 + with: + path: git-course + + - name: Report the Git version under test + run: git --version + + - name: Set a Git identity + # Runners have no identity configured, and the helpers create commits. + run: | + git config --global user.name "GitHub Action" + git config --global user.email "action@github.com" + git config --global init.defaultBranch main + + - name: Test the advanced helpers + run: bash git-course/advanced/tests/test_helpers.sh + + - name: Test the beginner helpers + run: bash git-course/beginner/tests/test_helpers.sh diff --git a/.gitignore b/.gitignore index 1a1c0065..74df64c6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,9 @@ .DS_Store git-course_env/ .vscode/*.log +check_requirements.log + +# HTML decks are built on demand by build.sh and published from CI, not committed. +advanced/slides/slides_advanced.html +beginner/slides/slides_beginner.html +_site/ diff --git a/.vscode/settings.json b/.vscode/settings.json index 8f861f2d..dcffc9f0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,5 @@ { "markdown.marp.themes": [ - "./slides_theme/c2sm.css", "./slides_theme/c2sm-light.css", "./slides_theme/c2sm-dark.css" ] diff --git a/Expert_Topics.md b/Expert_Topics.md new file mode 100644 index 00000000..79b2bb9f --- /dev/null +++ b/Expert_Topics.md @@ -0,0 +1,133 @@ +# Expert Git topics + +A collecting place for Git topics the C2SM courses do **not** cover, and a rough syllabus for a +possible third course. + +Each entry says why it matters and names the commands to look up. This is a reading list, not a +tutorial - none of it is needed for the two existing courses. + +**What is already covered:** + +- **[Git: The Basics](beginner)** - `init`, `add`, `commit`, `status`, `log`, branches, + `switch`, `restore`, merging and merge conflicts, `.gitignore`, remotes, `push`, `pull`, + `fetch`, and a first pull request. +- **[Git: Beyond the Basics](advanced)** - `log`/`blame`/`diff`/`show` in depth, submodules, + `.gitignore` in depth, `cherry-pick`, `rebase`, `stash`, `worktree`, hooks, `git lfs`, and the + issue → fork → pull request → review workflow. + +--- + +## Git internals + +Understanding what Git actually stores turns most of its odd behavior into common sense. + +- The object database: **blobs**, **trees**, **commits**, **tags** - four object types, all + content-addressed by hash. + `git hash-object`, `git cat-file -t`, `git cat-file -p`, `git ls-tree` +- Why identical content is stored once, no matter how many commits or branches contain it. +- The **index** (staging area) is a real file, `.git/index`, not an abstract idea. + `git ls-files --stage` +- **References** are files containing a hash: `.git/refs/heads/main`, `.git/HEAD`, `packed-refs`. + `git symbolic-ref`, `git update-ref`, `git rev-parse` +- **Packfiles** and delta compression, and why a fresh clone is smaller than your working copy. + `git gc`, `git count-objects -vH`, `git verify-pack` +- The ongoing **SHA-1 to SHA-256** transition. + +## Rewriting history + +- **Interactive rebase** - the workhorse for tidying a branch before review. + `git rebase -i`, with `pick`, `reword`, `edit`, `squash`, `fixup`, `drop`, `exec` +- Preparing fixes that squash themselves into the right commit. + `git commit --fixup `, then `git rebase -i --autosquash` +- **Removing a file from all of history** - the only real answer when a password or a huge binary + was committed. Note that the credential must still be rotated: it has been public. + [`git filter-repo`](https://github.com/newren/git-filter-repo) (the modern replacement for + `filter-branch`) +- Comparing two versions of a rewritten branch, which ordinary `diff` cannot do. + `git range-diff` +- `git replace` for grafting history without rewriting it. + +## Recovery: undoing almost anything + +- **`git reflog`** - the local record of everywhere `HEAD` has been. Almost nothing is truly lost + for 90 days, including commits dropped by a bad rebase or reset. +- `git reset --soft` / `--mixed` / `--hard`, and precisely what each one moves. +- `git restore` vs `git checkout` vs `git revert` - which change history and which do not. +- `git fsck --lost-found` for objects no reference points at any more. + +## Debugging with history + +- **`git bisect`** - binary search through history to find the commit that broke something. + Manual (`git bisect start` / `good` / `bad`) and automated (`git bisect run