77 lines
3.2 KiB
Bash
77 lines
3.2 KiB
Bash
#!/usr/bin/env bash
|
|||
|
|
# Is there, in the crate's jj working copy (current directory), a change that justifies a
|
||
|
|
# commit, that is, something other than what the kit itself produces or modifies? Read-only.
|
||
|
|
#
|
||
|
|
# Do not count:
|
||
|
|
# - .crate-kit/ (kit copy) and .cargo/ (generated local configuration);
|
||
|
|
# - a template file (.gitea/workflows/release.yaml, LICENSE, .gitignore, Makefile…) identical to
|
||
|
|
# that of the kind's template (<extension>/templates/<kind>, otherwise crate-kit/template): adopt.sh laid it down as is;
|
||
|
|
# - Cargo.lock when only the `version` line of the crate itself changed (version bump);
|
||
|
|
# - the Makefile when only its kit bootstrap lines changed (KIT_SRC, copy or sync of
|
||
|
|
# .crate-kit/, comments that talk about the kit): the rest (description, PLUGIN_ID…) belongs to the crate.
|
||
|
|
# Without a crate-kit repository alongside ($KIT_SRC), the second filter cannot apply: these files
|
||
|
|
# then count as changes.
|
||
|
|
#
|
||
|
|
# Output: one file per line on standard output. Code 0 if there are any, 1 otherwise (nothing to commit).
|
||
|
|
set -euo pipefail
|
||
|
|
. "$(dirname "$0")/common.sh"
|
||
|
|
|
||
|
|
kit_src="${KIT_SRC:-../crate-kit}"
|
||
|
|
kind="${CRATE_KIND:-}"
|
||
|
|
if [ -z "$kind" ] && [ -f Makefile ]; then
|
||
|
|
kind=$(sed -n 's/^CRATE_KIND *[:?]*= *\([a-z]*\).*/\1/p' Makefile | head -n 1)
|
||
|
|
fi
|
||
|
|
template="$("$kit_src/tools/kit-assemble.sh" --root)/template"
|
||
|
|
overlay=$("$kit_src/tools/kit-assemble.sh" --overlay 2>/dev/null || true)
|
||
|
|
[ -n "$kind" ] && [ -n "$overlay" ] && [ -d "$overlay/templates/$kind" ] && template="$overlay/templates/$kind"
|
||
|
|
|
||
|
|
# Cargo.lock: did only the `version` line of the crate's package change?
|
||
|
|
lock_is_version_bump() {
|
||
|
|
local name
|
||
|
|
name=$(crate_name)
|
||
|
|
jj diff --git --context 1 Cargo.lock 2>/dev/null | awk -v name="$name" '
|
||
|
|
/^(\+\+\+|---)/ { next }
|
||
|
|
/^@@/ { prev = ""; next }
|
||
|
|
/^[-+]/ {
|
||
|
|
changed++
|
||
|
|
if ($0 !~ /^[-+]version = / || prev != " name = \"" name "\"") bad = 1
|
||
|
|
next
|
||
|
|
}
|
||
|
|
/^ / { prev = $0 }
|
||
|
|
END { exit (changed > 0 && !bad) ? 0 : 1 }'
|
||
|
|
}
|
||
|
|
|
||
|
|
# Makefile: did only the kit bootstrap lines change? Those that name KIT_SRC or
|
||
|
|
# `crate-kit` (variable, sync, copy of .crate-kit/) and the comments that talk about the kit; a
|
||
|
|
# modification of any other line (description, PLUGIN_ID, targets) is a real change of the crate.
|
||
|
|
makefile_is_kit_bootstrap() {
|
||
|
|
jj diff --git --context 1 Makefile 2>/dev/null | awk '
|
||
|
|
/^(\+\+\+|---)/ { next }
|
||
|
|
/^[-+]/ {
|
||
|
|
changed++
|
||
|
|
if ($0 !~ /KIT_SRC|crate-kit|kit-copy|^[-+]# .*[Kk]it/) bad = 1
|
||
|
|
}
|
||
|
|
END { exit (changed > 0 && !bad) ? 0 : 1 }'
|
||
|
|
}
|
||
|
|
|
||
|
|
found=0
|
||
|
|
while IFS= read -r line; do
|
||
|
|
# Format of `jj diff --summary`: "M path"; a rename "R {a => b}" remains a change.
|
||
|
|
path="${line#? }"
|
||
|
|
case "$path" in
|
||
|
|
.crate-kit/* | .cargo/*) continue ;;
|
||
|
|
Cargo.lock)
|
||
|
|
if lock_is_version_bump; then continue; fi
|
||
|
|
;;
|
||
|
|
Makefile)
|
||
|
|
if makefile_is_kit_bootstrap; then continue; fi
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
if [ "${line%% *}" = M ] && [ -f "$template/$path" ] && cmp -s "$template/$path" "$path"; then
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
echo "$path"
|
||
|
|
found=1
|
||
|
|
done < <(jj diff --summary)
|
||
|
|
|
||
|
|
[ "$found" -eq 1 ] || { info " nothing to commit outside the kit" ; exit 1; }
|