aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmkhint73
-rwxr-xr-xtests/mkhint_test.sh63
2 files changed, 130 insertions, 6 deletions
diff --git a/mkhint b/mkhint
index 89bcdb3..f3395e7 100755
--- a/mkhint
+++ b/mkhint
@@ -33,6 +33,8 @@ HINT_FILE=""
NEW_HINT_FILE=""
DELETE_HINT_FILES=()
MATCHED_PKGS=()
+SHOW_LIST=""
+RUN_REVIEW=""
COMMAND=""
NO_DL=0
@@ -48,6 +50,7 @@ Usage:
./mkhint --hintfile FILE Update hint, suggest latest version via nvchecker
./mkhint --check [FILE...] Check all (or named) hints for upstream updates
./mkhint --list List hint files
+ ./mkhint --review Review hints matching SBo version, keep/delete each
./mkhint --clean Remove .bak files from HINT_DIR
./mkhint --no-dl --hintfile FILE Update hint, skip downloads, add NODOWNLOAD=yes
./mkhint --no-dl --new FILE Create hint with NODOWNLOAD=yes
@@ -58,6 +61,7 @@ Options:
--hintfile, -f FILE Path to existing hint file (required with --version)
--new, -n FILE Create new hint file (required with --version or standalone)
--list, -l List all hint files in the default directory
+ --review, -R Review hints whose version matches the SBo .info; diff + keep/delete
--clean, -c Remove all .bak files from HINT_DIR
--check, -C [FILE...] Check hints for upstream updates via nvchecker, update interactively
--delete, -d FILE Delete a hint file (and .bak if present)
@@ -141,6 +145,52 @@ list_hint_files() {
fi
}
+# Show each matched hint side-by-side with its .info, prompt Keep/Delete/Skip.
+# Relies on MATCHED_PKGS populated by list_hint_files.
+review_hint_files() {
+ if [[ ${#MATCHED_PKGS[@]} -eq 0 ]]; then
+ echo "No hints match their SBo version; nothing to review."
+ return 0
+ fi
+
+ local deleted=0 kept=0
+ local pkg
+ for pkg in "${MATCHED_PKGS[@]}"; do
+ local hint="${HINT_DIR}/${pkg}.hint"
+ local info
+ info=$(find "$REPO_DIR" -mindepth 2 -name "${pkg}.info" 2>/dev/null | head -1)
+ [[ -f "$hint" ]] || continue
+
+ echo ""
+ echo "=== $pkg ==="
+ if command -v git &>/dev/null; then
+ git diff --no-index --color=auto "$hint" "$info" || true
+ else
+ diff -y --width="${COLUMNS:-160}" "$hint" "$info" || true
+ fi
+
+ local ans
+ read -r -p "Review $pkg: [K]eep / [D]elete / [S]kip (default Keep): " ans
+ case "$ans" in
+ [Dd])
+ _remove_hint "$hint"
+ deleted=$((deleted + 1))
+ ;;
+ [Ss]|[Kk]|"")
+ echo "Kept: $pkg"
+ kept=$((kept + 1))
+ ;;
+ *)
+ echo "Unrecognised answer; keeping $pkg"
+ kept=$((kept + 1))
+ ;;
+ esac
+ done
+
+ echo ""
+ echo "Reviewed ${#MATCHED_PKGS[@]} hint(s): deleted $deleted, kept $kept."
+}
+
# Validate wget availability
check_wget() {
if ! command -v wget &> /dev/null; then
@@ -781,8 +831,8 @@ check_updates() {
# Main function
main() {
local parsed
- parsed=$(getopt -o v:f:n:lcCdNh \
- --long version:,hintfile:,new:,list,clean,check,delete,no-dl,help \
+ parsed=$(getopt -o v:f:n:lcCdNhR \
+ --long version:,hintfile:,new:,list,clean,check,delete,no-dl,help,review \
-n 'mkhint' -- "$@") || { show_help; exit 1; }
eval set -- "$parsed"
@@ -801,7 +851,11 @@ main() {
shift 2
;;
--list|-l)
- COMMAND="list"
+ SHOW_LIST=1
+ shift
+ ;;
+ --review|-R)
+ RUN_REVIEW=1
shift
;;
--clean|-c)
@@ -863,13 +917,20 @@ main() {
exit 1
fi
+ if [[ -n "$SHOW_LIST" || -n "$RUN_REVIEW" ]]; then
+ [[ -n "$SHOW_LIST" ]] && list_hint_files
+ if [[ -n "$RUN_REVIEW" ]]; then
+ # ensure MATCHED_PKGS is populated even when -l was not given
+ [[ -z "$SHOW_LIST" ]] && list_hint_files >/dev/null
+ review_hint_files
+ fi
+ exit $?
+ fi
+
case "$COMMAND" in
help)
show_help
;;
- list)
- list_hint_files
- ;;
clean)
clean_bak_files
;;
diff --git a/tests/mkhint_test.sh b/tests/mkhint_test.sh
index e435eff..e95b529 100755
--- a/tests/mkhint_test.sh
+++ b/tests/mkhint_test.sh
@@ -775,6 +775,69 @@ echo "$out" | grep "clion.hint" | grep -q $'\033\[33m' \
&& { echo " FAIL: clion wrongly highlighted"; (( FAIL++ )); ERRORS+=("T36 false hl"); } \
|| { echo " PASS: clion row plain"; (( PASS++ )); }
+# ── T37: -R delete a matched hint ─────────────────────────────────────────────
+echo ""
+echo "T37: -R answer D → matched hint and .bak removed"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.5.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+touch "$MOCK_HINT/curl.hint.bak"
+out=$(run_mkhint -R < <(printf 'D\n') 2>&1)
+assert_file_not_exists "curl hint deleted" "$MOCK_HINT/curl.hint"
+assert_file_not_exists "curl bak deleted" "$MOCK_HINT/curl.hint.bak"
+echo "$out" | grep -q "deleted 1" \
+ && { echo " PASS: summary reports deleted 1"; (( PASS++ )); } \
+ || { echo " FAIL: summary wrong"; echo "$out" | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T37 summary"); }
+
+# ── T38: -R keep a matched hint ───────────────────────────────────────────────
+echo ""
+echo "T38: -R answer K → matched hint unchanged"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+cat > "$MOCK_HINT/curl.hint" << 'EOF'
+VERSION="8.5.0"
+ARCH="x86_64"
+DOWNLOAD="https://curl.se/download/curl-8.5.0.tar.gz"
+MD5SUM="abc123def456abc123def456abc123de"
+EOF
+run_mkhint -R < <(printf 'K\n') >/dev/null 2>&1
+assert_file_exists "curl hint kept" "$MOCK_HINT/curl.hint"
+
+# ── T39: -R empty answer = keep ───────────────────────────────────────────────
+echo ""
+echo "T39: -R empty answer → kept (default)"
+run_mkhint -R < <(printf '\n') >/dev/null 2>&1
+assert_file_exists "curl hint kept on empty" "$MOCK_HINT/curl.hint"
+
+# ── T40: -R skip a matched hint ───────────────────────────────────────────────
+echo ""
+echo "T40: -R answer S → matched hint unchanged"
+run_mkhint -R < <(printf 'S\n') >/dev/null 2>&1
+assert_file_exists "curl hint kept on skip" "$MOCK_HINT/curl.hint"
+
+# ── T41: -R with no matches → nothing to review, exit 0 ───────────────────────
+echo ""
+echo "T41: -R no matched rows → nothing to review"
+rm -f "$MOCK_HINT"/*.hint "$MOCK_HINT"/*.bak 2>/dev/null
+# clion hint version differs from its .info → no match
+cat > "$MOCK_HINT/clion.hint" << 'EOF'
+VERSION="9.9.9"
+ARCH="x86_64"
+DOWNLOAD="UNSUPPORTED"
+MD5SUM=""
+EOF
+set +e
+out=$(run_mkhint -R < <(printf '\n') 2>&1)
+code=$?
+set -e
+assert_exit_code "no-match review exits 0" 0 "$code"
+echo "$out" | grep -q "nothing to review" \
+ && { echo " PASS: nothing-to-review message"; (( PASS++ )); } \
+ || { echo " FAIL: message missing"; echo "$out" | sed 's/^/ /'; (( FAIL++ )); ERRORS+=("T41 msg"); }
+
# ─── SUMMARY ──────────────────────────────────────────────────────────────────
teardown