1 Commits
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
2 changed files with 27 additions and 37 deletions

No files matched your search

+21 -25
View File
@@ -19,45 +19,41 @@ die() {
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"
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
+6 -12
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,8 +41,8 @@ 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
@@ -53,8 +50,6 @@ new_repo() {
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"
[ "$(git show --name-only --format= HEAD | sort)" = \
@@ -62,8 +57,7 @@ script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
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"