#!/usr/bin/env bash set -euo pipefail root_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd) source "$root_dir/scripts/fossil-env.sh" if [[ $# -ne 1 ]]; then printf 'Usage: %s TARGET_DIRECTORY\n' "$0" >&2 exit 2 fi target_dir=$1 mkdir -p "$target_dir/repositories" "$target_dir/checkouts" create_repository() { local slug=$1 local title=$2 local repository="$target_dir/repositories/$slug.fossil" local checkout="$target_dir/checkouts/$slug" local is_new=0 if [[ ! -f "$repository" ]]; then is_new=1 "$FOSSIL" init \ --admin-user copland \ --date-override 2024-01-01T12:00:00Z \ --project-name "$title" \ "$repository" >/dev/null fi "$FOSSIL" user default copland -R "$repository" mkdir -p "$checkout" if [[ ! -f "$checkout/.fslckout" && ! -f "$checkout/_FOSSIL_" ]]; then ( cd /tmp "$FOSSIL" open --nested --workdir "$checkout" "$repository" >/dev/null ) fi ( cd "$checkout" "$FOSSIL" user default copland if [[ "$is_new" -eq 1 ]]; then mkdir -p src printf '#+title: %s\n\nA small repository used to preview the Copland Fossil skin.\n\n* Usage\n\nRun the example from a C compiler.\n' "$title" > README.org printf '#include \n\nint main(void) {\n puts("hello from %s");\n return 0;\n}\n' "$slug" > src/main.c fi if [[ ! -f docs/org-support.org ]]; then mkdir -p docs printf '%s\n' \ '#+title: Native Org preview' \ '#+author: Copland' \ '#+date: 2026-08-21' \ '#+options: toc:2' \ '' \ '* Overview' \ '' \ 'This public fixture demonstrates *bold*, /italic/, _underlined_,' \ '+struck+, ~code~, and =verbatim= text.' \ '' \ '- Rendered by Fossil' \ ' 1. Nested ordered item' \ '- [[file:../README.org][Back to the README]]' \ '' \ '* Data' \ '' \ '| Format | Native |' \ '|--------+--------|' \ '| Org | yes |' \ '' \ '#+begin_src nix' \ '{ pkgs ? import {} }: pkgs.hello' \ '#+end_src' \ '' \ '#+begin_example' \ '' \ '#+end_example' \ '' \ '** Details' \ '' \ 'Jump [[*Overview][back to the overview]].' > docs/org-support.org fi "$FOSSIL" addremove >/dev/null if [[ -n $("$FOSSIL" changes) ]]; then "$FOSSIL" commit --no-warnings \ --date-override 2024-01-03T12:00:00Z \ --user-override copland \ -m "Add Org documentation fixture" fi if [[ "$is_new" -eq 1 ]]; then "$FOSSIL" tag add release-0.1 current fi ) local wiki_fixture="$target_dir/$slug-org-wiki.org" printf '%s\n' \ '#+TITLE: This title is intentionally suppressed' \ '#+AUTHOR: Copland' \ '#+OPTIONS: toc:2' \ '' \ '* Overview' \ '' \ 'Open [[wiki:Deployment Guide][the deployment guide]] or the' \ '[[file:docs/org-support.org][repository documentation]].' \ '' \ '** Details' \ '' \ 'Return [[*Overview][to the overview]].' >"$wiki_fixture" if ! "$FOSSIL" wiki list -R "$repository" | grep -Fxq 'Org Wiki'; then "$FOSSIL" wiki create 'Org Wiki' "$wiki_fixture" -R "$repository" >/dev/null fi } create_repository alpha "Alpha" create_repository beta "Beta"