Compare commits
1
Commits
47b35661a2
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d004fd272c |
No files matched your search
+38
-34
@@ -19,41 +19,45 @@ die() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
cd "$ROOT"
|
||||
[ ! -e prompts/REPO_POLICIES.md ] ||
|
||||
die "this is the prompts repo, where these files come from"
|
||||
[ ! -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"
|
||||
main() {
|
||||
cd "$ROOT"
|
||||
[ ! -e prompts/REPO_POLICIES.md ] ||
|
||||
die "this is the prompts repo, where these files come from"
|
||||
[ ! -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="$paths ${entry#*:}"
|
||||
done
|
||||
[ -z "$(git status --porcelain -- $paths)" ] ||
|
||||
die "commit or discard your changes to these files first:$paths"
|
||||
paths=""
|
||||
for entry in $FILES; do
|
||||
paths="$paths ${entry#*:}"
|
||||
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
|
||||
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"
|
||||
# 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"
|
||||
|
||||
for path in $paths; do
|
||||
mkdir -p "$(dirname "$path")"
|
||||
mv "$tmp/$path" "$path"
|
||||
done
|
||||
for path in $paths; do
|
||||
mkdir -p "$(dirname "$path")"
|
||||
mv "$tmp/$path" "$path"
|
||||
done
|
||||
|
||||
git add -- $paths
|
||||
if git diff --cached --quiet -- $paths; then
|
||||
echo "update-policy: already current, nothing to commit"
|
||||
else
|
||||
git commit -q -m "Update policy files from prompts" -- $paths
|
||||
echo "update-policy: committed; review it, then push"
|
||||
fi
|
||||
git add -- $paths
|
||||
if git diff --cached --quiet -- $paths; then
|
||||
echo "update-policy: already current, nothing to commit"
|
||||
else
|
||||
git commit -q -m "Update policy files from prompts" -- $paths
|
||||
echo "update-policy: committed; review it, then push"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
+12
-6
@@ -1,7 +1,8 @@
|
||||
#!/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.
|
||||
# in WGET_FAIL, so nothing touches the network. Like wget, it writes a
|
||||
# new file without the execute bit, whatever the source's mode.
|
||||
set -eu
|
||||
|
||||
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||
@@ -25,14 +26,16 @@ while [ "\$#" -gt 1 ]; do
|
||||
done
|
||||
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
|
||||
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
|
||||
cp "$PROMPTS/\$path" "\$output"
|
||||
cat "$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, so that a run must replace the script that is running.
|
||||
# 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.
|
||||
new_repo() {
|
||||
scenario="$1"
|
||||
rm -rf "$dir/repo"
|
||||
@@ -41,8 +44,8 @@ new_repo() {
|
||||
git config user.name test
|
||||
git config user.email test@example.com
|
||||
mkdir script
|
||||
cp "$PROMPTS/script/update-policy" script/
|
||||
echo "# older copy" >> script/update-policy
|
||||
grep -v '^# ' "$PROMPTS/script/update-policy" > script/update-policy
|
||||
chmod +x script/update-policy
|
||||
echo own > README.md
|
||||
git add README.md script/update-policy
|
||||
git commit -q -m initial
|
||||
@@ -50,6 +53,8 @@ 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)" = \
|
||||
@@ -57,7 +62,8 @@ 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)" = "?? stray.txt" ] || fail "tree not clean"
|
||||
[ "$(git status --porcelain)" = "$(printf 'M README.md\n?? stray.txt')" ] ||
|
||||
fail "changed files outside the list"
|
||||
|
||||
scenario="a second run commits nothing"
|
||||
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
||||
|
||||
Reference in new issue
Block a user