Author SHA1 Message Date
sneak 47b35661a2 Replace script/update-policy with a short wget-and-commit script (closes #165)
check / check (push) Successful in 13s
The script fetches a fixed list of three files from the main branch of
prompts with wget: docs/REPO_POLICIES.md, docs/CODE_STYLEGUIDE.md and
itself. It moves them into place and commits them. It does not push. It
stops before anything is replaced when a fetch fails, when a listed file
has uncommitted changes, and when REPO_POLICIES.md is still at the repo
root. It runs under busybox.

The line-keeping rules, the hash argument and the push are gone. The
policies and checklists say so, and name docs/REPO_POLICIES.md as the
file's place.

Model: opus-5-5
2026-11-18 20:56:57 +00:00
3 changed files with 34 additions and 115 deletions

No files matched your search

+1 -6
View File
@@ -1,6 +1,6 @@
---
title: Repository Policies
last_modified: 2026-11-19
last_modified: 2026-11-18
---
This document covers repository structure, tooling, and workflow standards. Code
@@ -163,11 +163,6 @@ style conventions are in separate documents:
- `docs/REPO_POLICIES.md`
- `docs/CODE_STYLEGUIDE.md`
- `script/update-policy` itself, so the script stays current
- `docs/CODE_STYLEGUIDE_GO.md`, when the repo has a `go.mod`
- `docs/GO_HTTP_SERVER_CONVENTIONS.md`, when its Go code imports `net/http`
- `docs/CODE_STYLEGUIDE_JS.md`, when the repo tracks `.js` or `.ts` files
- `docs/CODE_STYLEGUIDE_PYTHON.md`, when the repo has a `pyproject.toml` or
`setup.py`
# Tests and checks
+24 -49
View File
@@ -1,8 +1,7 @@
#!/bin/sh
# script/update-policy: replace the files below, and the style guides
# for the repo's languages, with their current versions from the main
# branch of the prompts repo, and commit them. It does not push.
# Identical in all repos, and it updates itself.
# script/update-policy: replace the files below with their current
# versions from the main branch of the prompts repo, and commit them. It
# does not push. Identical in all repos, and it updates itself.
set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
@@ -15,70 +14,46 @@ prompts/CODE_STYLEGUIDE.md:docs/CODE_STYLEGUIDE.md
script/update-policy:script/update-policy
"
# The style guide for each language the repo uses, and the HTTP server
# conventions for Go code using net/http. Go and Python are found by
# their file at the root, JavaScript by tracked .js or .ts files: many
# Go repos have a package.json only to pin prettier.
language_files() {
if [ -e go.mod ]; then
echo prompts/CODE_STYLEGUIDE_GO.md:docs/CODE_STYLEGUIDE_GO.md
if git grep -q '"net/http"' -- '*.go'; then
echo prompts/GO_HTTP_SERVER_CONVENTIONS.md:docs/GO_HTTP_SERVER_CONVENTIONS.md
fi
fi
if [ -n "$(git ls-files -- '*.js' '*.ts')" ]; then
echo prompts/CODE_STYLEGUIDE_JS.md:docs/CODE_STYLEGUIDE_JS.md
fi
if [ -e pyproject.toml ] || [ -e setup.py ]; then
echo prompts/CODE_STYLEGUIDE_PYTHON.md:docs/CODE_STYLEGUIDE_PYTHON.md
fi
}
die() {
echo "update-policy: $*" >&2
exit 1
}
main() {
cd "$ROOT"
[ ! -e prompts/REPO_POLICIES.md ] ||
cd "$ROOT"
[ ! -e prompts/REPO_POLICIES.md ] ||
die "this is the prompts repo, where these files come from"
[ ! -e REPO_POLICIES.md ] ||
[ ! -e REPO_POLICIES.md ] ||
die "REPO_POLICIES.md is at the root;" \
"move it into docs/ with git mv and fix the links to it first"
FILES="$FILES $(language_files)"
paths=""
for entry in $FILES; do
paths=""
for entry in $FILES; do
paths="$paths ${entry#*:}"
done
[ -z "$(git status --porcelain -- $paths)" ] ||
done
[ -z "$(git status --porcelain -- $paths)" ] ||
die "commit or discard your changes to these files first:$paths"
# Every file is fetched before any is replaced. The temporary
# directory is inside the repo so that mv renames: the running script
# is replaced by a new file, never rewritten in place.
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
trap 'rm -rf "$tmp"' EXIT
for entry in $FILES; do
# Every file is fetched before any is replaced. The temporary directory
# is inside the repo so that mv renames: the running script is replaced
# by a new file, never rewritten in place.
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
trap 'rm -rf "$tmp"' EXIT
for entry in $FILES; do
mkdir -p "$tmp/$(dirname "${entry#*:}")"
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
die "cannot fetch $RAW_URL/${entry%%:*}"
done
chmod 755 "$tmp/script/update-policy"
done
chmod 755 "$tmp/script/update-policy"
for path in $paths; do
for path in $paths; do
mkdir -p "$(dirname "$path")"
mv "$tmp/$path" "$path"
done
done
git add -- $paths
if git diff --cached --quiet -- $paths; then
git add -- $paths
if git diff --cached --quiet -- $paths; then
echo "update-policy: already current, nothing to commit"
else
else
git commit -q -m "Update policy files from prompts" -- $paths
echo "update-policy: committed; review it, then push"
fi
}
main "$@"
fi
+9 -60
View File
@@ -1,8 +1,7 @@
#!/bin/sh
# test/update-policy.sh: test script/update-policy on throwaway repos. A
# stub wget serves the files from this checkout, or fails for the path
# in WGET_FAIL, so nothing touches the network. Like wget, it writes a
# new file without the execute bit, whatever the source's mode.
# in WGET_FAIL, so nothing touches the network.
set -eu
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
@@ -26,16 +25,14 @@ while [ "\$#" -gt 1 ]; do
done
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
cat "$PROMPTS/\$path" > "\$output"
cp "$PROMPTS/\$path" "\$output"
EOF
chmod +x "$dir/bin/wget"
PATH="$dir/bin:$PATH"
export PATH
# new_repo: a repo with one commit, holding only an older copy of the
# script that is shorter than the new one. A run that rewrote the running
# script in place, instead of replacing it, would then read the new
# file's last lines as commands and fail.
# script, so that a run must replace the script that is running.
new_repo() {
scenario="$1"
rm -rf "$dir/repo"
@@ -44,77 +41,29 @@ new_repo() {
git config user.name test
git config user.email test@example.com
mkdir script
grep -v '^# ' "$PROMPTS/script/update-policy" > script/update-policy
chmod +x script/update-policy
cp "$PROMPTS/script/update-policy" script/
echo "# older copy" >> script/update-policy
echo own > README.md
git add README.md script/update-policy
git commit -q -m initial
}
# committed_files_are: check that the last commit holds the listed files
# and the ones given, and no others.
committed_files_are() {
[ "$(git show --name-only --format= HEAD | sort)" = \
"$(echo "$LISTED $*" | tr ' ' '\n' | grep . | sort)" ] ||
fail "commit holds the wrong files"
}
new_repo "a first run, with no language files, commits exactly the listed files"
new_repo "a first run writes and commits exactly the listed files"
echo stray > stray.txt
echo staged >> README.md
git add README.md
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit"
committed_files_are
[ "$(git show --name-only --format= HEAD | sort)" = \
"$(echo "$LISTED" | tr ' ' '\n' | sort)" ] || fail "commit holds other files"
cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" ||
fail "REPO_POLICIES.md differs"
[ -x script/update-policy ] || fail "script not executable"
[ "$(git status --porcelain)" = "$(printf 'M README.md\n?? stray.txt')" ] ||
fail "changed files outside the list"
[ "$(git status --porcelain)" = "?? stray.txt" ] || fail "tree not clean"
scenario="a second run commits nothing"
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit"
grep -q "nothing to commit" "$dir/output" || fail "did not say so"
new_repo "a Go repo that uses net/http also gets the Go guide and HTTP conventions"
echo "module example.com/app" > go.mod
printf 'package main\n\nimport "net/http"\n' > main.go
git add go.mod main.go
git commit -q -m go
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_GO.md docs/GO_HTTP_SERVER_CONVENTIONS.md
cmp -s docs/CODE_STYLEGUIDE_GO.md "$PROMPTS/prompts/CODE_STYLEGUIDE_GO.md" ||
fail "CODE_STYLEGUIDE_GO.md differs"
new_repo "a Go repo without net/http gets only the Go guide"
echo "module example.com/app" > go.mod
printf 'package main\n\nimport "fmt"\n' > main.go
git add go.mod main.go
git commit -q -m go
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_GO.md
new_repo "a Go repo with a package.json only for prettier gets no JS guide"
echo "module example.com/app" > go.mod
printf 'package main\n\nimport "fmt"\n' > main.go
echo '{"devDependencies": {"prettier": "3.3.3"}}' > package.json
mkdir -p .yarn/releases
echo "// yarn" > .yarn/releases/yarn-4.5.0.cjs
git add go.mod main.go package.json .yarn/releases/yarn-4.5.0.cjs
git commit -q -m go-with-prettier
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_GO.md
new_repo "a repo with .js files and pyproject.toml gets the JS and Python guides"
echo "{}" > package.json
echo "console.log(1);" > index.js
echo "[project]" > pyproject.toml
git add package.json index.js pyproject.toml
git commit -q -m js-and-python
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_JS.md docs/CODE_STYLEGUIDE_PYTHON.md
new_repo "a failed fetch writes nothing"
WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 &&
fail "exited zero"