in root.html). Outputs custom og:image with assets_prefix normalisation and non-Google site verification. --> Building & Testing the Git Init Script: Headless, Interactive, Scaffolding | IT-Journey in _layouts/root.html. What this file adds: - Custom og:image with preview_images.assets_prefix path normalisation for the theme-specific page.preview and page.header.og_image keys. When page.image is set, jekyll-seo-tag handles og:image and this file skips its own og:image output to avoid duplicate tags. - Non-Google site verification tags (Bing, Yandex, Naver, Baidu) Dependencies: - jekyll-seo-tag plugin (loaded in _layouts/root.html via Building & Testing the Git Init Script: Headless, Interactive, Scaffolding | IT-Journey ) - site.preview_images config in _config.yml =================================================================== --> Building & Testing the Git Init Script: Headless, Interactive, Scaffolding | IT-Journey Skip to main content
Settings
Search
Appearance
Theme Mode
About
Jekyll v3.10.0
Environment Production
Last Build
2026-04-11 02:52 UTC
Current Environment Production
Build Time Apr 11, 02:52
Jekyll v3.10.0
Build env (JEKYLL_ENV) production
Quick Links
Page Location
Page Info
Layout default
Collection quests
Path _quests/0001/building-testing-git-init-script.md
URL /quests/level-0001-git-init-testing/
Date 2025-11-13
Theme Skin
SVG Backgrounds
Layer Opacity
0.6
0.04
0.08

Building & Testing the Git Init Script: Headless, Interactive, Scaffolding

By IT-Journey Team

Hands-on quest to build, extend, and test `git_init.sh` — an interactive and headless repo initializer with programmatic scaffolding.

Estimated reading time: 2 minutes

The Challenge: Safe automation without surprises

You have a powerful repository initializer — scripts/git_init.sh — that supports interactive prompts and programmatic --headless invocations. This quest will guide you through validating the script’s behavior, adding tests, and ensuring it behaves well in CI.

Why this matters:

  • Scripts are often used in automation and CI; they must behave predictably and be testable.
  • Headless behavior must be non-destructive and reliable; interactive commands can’t be used in CI loops.
  • Creating files via programmatic scaffolding must be done with a clear contract and test coverage.

Objectives

  • Verify script syntax with bash -n and lint with shellcheck.
  • Add Bats tests to confirm --headless operations do not push.
  • Ensure easy to run --no-push for local tests.
  • Add CI step instructions for running tests.

Tests and Tools

We suggest two layers of tests:

  1. Unit-ish validations using local filesystem checks via bats.
  2. Linting static validation with shellcheck.

Example Bats Test (save in tests/bats/test_headless.bats)

#!/usr/bin/env bats

setup() {
  TMPDIR=$(mktemp -d)
  cd "$TMPDIR"
}

teardown() {
  rm -rf "$TMPDIR"
}

@test "headless mode creates a repo and does not push" {
  run bash /path/to/scripts/git_init.sh --headless -n sample-test --no-push
  [ "$status" -eq 0 ]
  [ -d "$HOME/github/sample-test/.git" ]
}

ShellCheck linting

Install with brew install shellcheck on macOS and run shellcheck scripts/git_init.sh.

Syntax check

Use bash -n scripts/git_init.sh to detect syntax issues early.

Try it locally

  1. Syntax check
bash -n scripts/git_init.sh
  1. Run headless mode locally without pushing
bash scripts/git_init.sh --headless -n test-quest-sample --no-push --gitignore python,macos --scaffold python
  1. Run Bats tests
# install bats-core
brew install bats-core
bats tests/bats
  1. Run ShellCheck
brew install shellcheck
shellcheck scripts/git_init.sh

Acceptance Criteria

  • bash -n returns no error
  • shellcheck returns no major errors
  • bats tests/bats/test_headless.bats returns pass for headless creation
  • --gitignore creates a .gitignore file when requested
  • --scaffold python creates src and tests
  • --dry-run prints operations and does not create files or push

Next Steps (Optional)

  • Try --dry-run to preview changes without applying them.
  • Create a GitHub Actions job that installs bats and shellcheck and runs tests on PRs.

Complete this quest to prove you can safely add features to a script and make it testable in automation.

Good luck! 🛠️