A listed file the repo lacks is now written whole, with no keep rule. A prompts/NAME.md goes to docs/NAME.md unless the repo keeps it at NAME.md, and any other file goes to its own path. A language's files are skipped when git tracks no source file of that language. A listed path git ignores now stops the script before it writes. README bullets split into short sentences, and a false sentence about template repos deleted. Model: opus-5-5
This commit is contained in:
1 parent
f4275b9ac0
commit
76b75fa79f
4 files changed
+166
-45
No files matched your search
+42
-20
@@ -24,8 +24,9 @@ PROMPTS_URL="https://git.eeqj.de/sneak/prompts"
|
||||
PROMPTS_API_URL="https://git.eeqj.de/api/v1/repos/sneak/prompts"
|
||||
PROMPTS_FIRST_COMMIT="af257bef63f162a681bddc80d9b941c47a44b748"
|
||||
|
||||
# Paths in the prompts repo. A file the target repo does not carry is
|
||||
# skipped, except the two scripts, which every repo gets.
|
||||
# Paths in the prompts repo. Every repo gets each file, written whole if
|
||||
# the repo lacks it. A language's files are skipped when git tracks no
|
||||
# source file of that language.
|
||||
VENDORED_FILES="
|
||||
.dockerignore
|
||||
.editorconfig
|
||||
@@ -58,15 +59,36 @@ fetch() {
|
||||
die "cannot fetch $1"
|
||||
}
|
||||
|
||||
# local_path <path in prompts>: print where the target repo keeps the
|
||||
# file, or nothing if git does not track it there. A prompts/NAME.md
|
||||
# lands at docs/NAME.md or NAME.md.
|
||||
# file_applies <path in prompts>: fail if the file is for a language of
|
||||
# which git tracks no source file in the target repo.
|
||||
file_applies() {
|
||||
case "$1" in
|
||||
.golangci.yml | prompts/CODE_STYLEGUIDE_GO.md | \
|
||||
prompts/GO_HTTP_SERVER_CONVENTIONS.md)
|
||||
[ -n "$(git ls-files -- '*.go')" ]
|
||||
;;
|
||||
prompts/CODE_STYLEGUIDE_JS.md)
|
||||
[ -n "$(git ls-files -- '*.js' '*.mjs' '*.ts')" ]
|
||||
;;
|
||||
prompts/CODE_STYLEGUIDE_PYTHON.md)
|
||||
[ -n "$(git ls-files -- '*.py')" ]
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# local_path <path in prompts>: print where the file goes in the target
|
||||
# repo. A prompts/NAME.md stays at NAME.md if git tracks it there and not
|
||||
# at docs/NAME.md; otherwise it goes to docs/NAME.md. Any other file goes
|
||||
# to its own path.
|
||||
local_path() {
|
||||
name="${1#prompts/}"
|
||||
if [ "$name" != "$1" ] && [ -n "$(git ls-files -- "docs/$name")" ]; then
|
||||
echo "docs/$name"
|
||||
elif [ -n "$(git ls-files -- "$name")" ]; then
|
||||
if [ "$name" = "$1" ]; then
|
||||
echo "$1"
|
||||
elif [ -z "$(git ls-files -- "docs/$name")" ] &&
|
||||
[ -n "$(git ls-files -- "$name")" ]; then
|
||||
echo "$name"
|
||||
else
|
||||
echo "docs/$name"
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -177,9 +199,8 @@ $own"
|
||||
# stop_on_own_script <fetched> <local>: stop if the local script has a
|
||||
# line the canonical file has never held, unless it is blank or a
|
||||
# comment: the repo wrote that script itself, and replacing it would
|
||||
# delete it. A repo without the script is fine.
|
||||
# delete it.
|
||||
stop_on_own_script() {
|
||||
[ -e "$2" ] || return 0
|
||||
own="$(local_only_lines "$1" "$2")"
|
||||
if [ -n "$own" ]; then
|
||||
die "$2 has lines the canonical file has never held; rename the repo's own script to keep it:
|
||||
@@ -210,23 +231,24 @@ main() {
|
||||
fetch "$PROMPTS_URL/compare/$PROMPTS_FIRST_COMMIT...$commit.patch" \
|
||||
"$tmp/history.patch"
|
||||
|
||||
carried=""
|
||||
to_write=""
|
||||
for file in $VENDORED_FILES; do
|
||||
case "$file" in
|
||||
script/*) path="$file" ;;
|
||||
*) path="$(local_path "$file")" ;;
|
||||
esac
|
||||
[ -n "$path" ] || continue
|
||||
file_applies "$file" || continue
|
||||
path="$(local_path "$file")"
|
||||
if git check-ignore -q -- "$path"; then
|
||||
die "$path is ignored by git; stop ignoring it"
|
||||
fi
|
||||
if [ -n "$(git status --porcelain -- "$path")" ]; then
|
||||
die "$path has uncommitted changes"
|
||||
fi
|
||||
mkdir -p "$tmp/$(dirname "$path")"
|
||||
fetch "$PROMPTS_URL/raw/commit/$commit/$file" "$tmp/$path"
|
||||
former_lines "$tmp/history.patch" "$file" > "$tmp/$path.former"
|
||||
carried="$carried $path"
|
||||
to_write="$to_write $path"
|
||||
done
|
||||
|
||||
for path in $carried; do
|
||||
for path in $to_write; do
|
||||
[ -e "$path" ] || continue
|
||||
case "$path" in
|
||||
.gitignore | .editorconfig | .dockerignore)
|
||||
keep_lines_below_last "$tmp/$path" "$path"
|
||||
@@ -241,12 +263,12 @@ main() {
|
||||
done
|
||||
|
||||
echo "$commit"
|
||||
for path in $carried; do
|
||||
for path in $to_write; do
|
||||
mkdir -p "$(dirname "$path")"
|
||||
case "$path" in
|
||||
script/*)
|
||||
# A new name and mv, because script/update-policy may
|
||||
# be the script running.
|
||||
mkdir -p script
|
||||
cp "$tmp/$path" "$path.new"
|
||||
chmod 755 "$path.new"
|
||||
mv "$path.new" "$path"
|
||||
|
||||
Reference in new issue
Block a user