Compare commits
1
Commits
next
..
47b35661a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47b35661a2 |
No files matched your search
@@ -19,7 +19,6 @@ die() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
main() {
|
||||
cd "$ROOT"
|
||||
[ ! -e prompts/REPO_POLICIES.md ] ||
|
||||
die "this is the prompts repo, where these files come from"
|
||||
@@ -34,9 +33,9 @@ main() {
|
||||
[ -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.
|
||||
# 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
|
||||
@@ -58,6 +57,3 @@ main() {
|
||||
git commit -q -m "Update policy files from prompts" -- $paths
|
||||
echo "update-policy: committed; review it, then push"
|
||||
fi
|
||||
}
|
||||
|
||||
main "$@"
|
||||
+6
-12
@@ -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"
|
||||
|
||||
Reference in new issue
Block a user