Compare commits
1
Commits
next
..
47b35661a2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47b35661a2 |
No files matched your search
+21
-25
@@ -19,45 +19,41 @@ die() {
|
|||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
cd "$ROOT"
|
||||||
cd "$ROOT"
|
[ ! -e prompts/REPO_POLICIES.md ] ||
|
||||||
[ ! -e prompts/REPO_POLICIES.md ] ||
|
|
||||||
die "this is the prompts repo, where these files come from"
|
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;" \
|
die "REPO_POLICIES.md is at the root;" \
|
||||||
"move it into docs/ with git mv and fix the links to it first"
|
"move it into docs/ with git mv and fix the links to it first"
|
||||||
|
|
||||||
paths=""
|
paths=""
|
||||||
for entry in $FILES; do
|
for entry in $FILES; do
|
||||||
paths="$paths ${entry#*:}"
|
paths="$paths ${entry#*:}"
|
||||||
done
|
done
|
||||||
[ -z "$(git status --porcelain -- $paths)" ] ||
|
[ -z "$(git status --porcelain -- $paths)" ] ||
|
||||||
die "commit or discard your changes to these files first:$paths"
|
die "commit or discard your changes to these files first:$paths"
|
||||||
|
|
||||||
# Every file is fetched before any is replaced. The temporary
|
# Every file is fetched before any is replaced. The temporary directory
|
||||||
# directory is inside the repo so that mv renames: the running script
|
# is inside the repo so that mv renames: the running script is replaced
|
||||||
# is replaced by a new file, never rewritten in place.
|
# by a new file, never rewritten in place.
|
||||||
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
|
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
|
||||||
trap 'rm -rf "$tmp"' EXIT
|
trap 'rm -rf "$tmp"' EXIT
|
||||||
for entry in $FILES; do
|
for entry in $FILES; do
|
||||||
mkdir -p "$tmp/$(dirname "${entry#*:}")"
|
mkdir -p "$tmp/$(dirname "${entry#*:}")"
|
||||||
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
|
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
|
||||||
die "cannot fetch $RAW_URL/${entry%%:*}"
|
die "cannot fetch $RAW_URL/${entry%%:*}"
|
||||||
done
|
done
|
||||||
chmod 755 "$tmp/script/update-policy"
|
chmod 755 "$tmp/script/update-policy"
|
||||||
|
|
||||||
for path in $paths; do
|
for path in $paths; do
|
||||||
mkdir -p "$(dirname "$path")"
|
mkdir -p "$(dirname "$path")"
|
||||||
mv "$tmp/$path" "$path"
|
mv "$tmp/$path" "$path"
|
||||||
done
|
done
|
||||||
|
|
||||||
git add -- $paths
|
git add -- $paths
|
||||||
if git diff --cached --quiet -- $paths; then
|
if git diff --cached --quiet -- $paths; then
|
||||||
echo "update-policy: already current, nothing to commit"
|
echo "update-policy: already current, nothing to commit"
|
||||||
else
|
else
|
||||||
git commit -q -m "Update policy files from prompts" -- $paths
|
git commit -q -m "Update policy files from prompts" -- $paths
|
||||||
echo "update-policy: committed; review it, then push"
|
echo "update-policy: committed; review it, then push"
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
main "$@"
|
|
||||||
+6
-12
@@ -1,8 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# test/update-policy.sh: test script/update-policy on throwaway repos. A
|
# 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
|
# 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
|
# in WGET_FAIL, so nothing touches the network.
|
||||||
# new file without the execute bit, whatever the source's mode.
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
|
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
|
||||||
@@ -26,16 +25,14 @@ while [ "\$#" -gt 1 ]; do
|
|||||||
done
|
done
|
||||||
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
|
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
|
||||||
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
|
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
|
||||||
cat "$PROMPTS/\$path" > "\$output"
|
cp "$PROMPTS/\$path" "\$output"
|
||||||
EOF
|
EOF
|
||||||
chmod +x "$dir/bin/wget"
|
chmod +x "$dir/bin/wget"
|
||||||
PATH="$dir/bin:$PATH"
|
PATH="$dir/bin:$PATH"
|
||||||
export PATH
|
export PATH
|
||||||
|
|
||||||
# new_repo: a repo with one commit, holding only an older copy of the
|
# 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, so that a run must replace the script that is running.
|
||||||
# script in place, instead of replacing it, would then read the new
|
|
||||||
# file's last lines as commands and fail.
|
|
||||||
new_repo() {
|
new_repo() {
|
||||||
scenario="$1"
|
scenario="$1"
|
||||||
rm -rf "$dir/repo"
|
rm -rf "$dir/repo"
|
||||||
@@ -44,8 +41,8 @@ new_repo() {
|
|||||||
git config user.name test
|
git config user.name test
|
||||||
git config user.email test@example.com
|
git config user.email test@example.com
|
||||||
mkdir script
|
mkdir script
|
||||||
grep -v '^# ' "$PROMPTS/script/update-policy" > script/update-policy
|
cp "$PROMPTS/script/update-policy" script/
|
||||||
chmod +x script/update-policy
|
echo "# older copy" >> script/update-policy
|
||||||
echo own > README.md
|
echo own > README.md
|
||||||
git add README.md script/update-policy
|
git add README.md script/update-policy
|
||||||
git commit -q -m initial
|
git commit -q -m initial
|
||||||
@@ -53,8 +50,6 @@ new_repo() {
|
|||||||
|
|
||||||
new_repo "a first run writes and commits exactly the listed files"
|
new_repo "a first run writes and commits exactly the listed files"
|
||||||
echo stray > stray.txt
|
echo stray > stray.txt
|
||||||
echo staged >> README.md
|
|
||||||
git add README.md
|
|
||||||
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
||||||
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit"
|
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit"
|
||||||
[ "$(git show --name-only --format= HEAD | sort)" = \
|
[ "$(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" ||
|
cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" ||
|
||||||
fail "REPO_POLICIES.md differs"
|
fail "REPO_POLICIES.md differs"
|
||||||
[ -x script/update-policy ] || fail "script not executable"
|
[ -x script/update-policy ] || fail "script not executable"
|
||||||
[ "$(git status --porcelain)" = "$(printf 'M README.md\n?? stray.txt')" ] ||
|
[ "$(git status --porcelain)" = "?? stray.txt" ] || fail "tree not clean"
|
||||||
fail "changed files outside the list"
|
|
||||||
|
|
||||||
scenario="a second run commits nothing"
|
scenario="a second run commits nothing"
|
||||||
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
||||||
|
|||||||
Reference in new issue
Block a user