-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify.sh
More file actions
executable file
·83 lines (73 loc) · 2.65 KB
/
Copy pathverify.sh
File metadata and controls
executable file
·83 lines (73 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/env bash
# SPDX-License-Identifier: MPL-2.0
# SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell <j.d.a.jewell@open.ac.uk>
#
# verify.sh — local-vs-origin sync-status verifier.
#
# Walks the configured REPOS list (or every git repo under $GS_REPOS_DIR
# with --all) and prints a Markdown table of each one's local HEAD vs
# origin/<branch>.
#
# Read-only — never fetches, never writes. Pair with `update_repos.sh` if
# you need to sync first.
set -uo pipefail
SCRIPT_DIR="$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)"
. "${SCRIPT_DIR}/lib/common.sh"
GS_SCRIPT_NAME="verify"
GS_HELP_TEXT="Usage: verify.sh [--all] [--help]
Print a sync-status table for the configured (or every) repo. Read-only.
"
gs::strict
gs::install_trap
gs::install_trap_summary
CONFIG_FILE="${SCRIPT_DIR}/../config/repos.config"
[[ -f "${CONFIG_FILE}" ]] && source "${CONFIG_FILE}"
: "${REPOS:=}"
: "${BASE_DIR:=${GS_REPOS_DIR}}"
OPT_ALL=0
while (( $# > 0 )); do
case "$1" in
--all) OPT_ALL=1 ;;
-v|--verbose) GS_LOG_LEVEL=debug ;;
-q|--quiet) GS_LOG_LEVEL=warn ;;
-h|--help) printf '%s\n' "${GS_HELP_TEXT}"; exit 0 ;;
*) gs::die "unknown flag: $1" ;;
esac
shift
done
declare -a TARGETS=()
if (( OPT_ALL )); then
while IFS= read -r r; do TARGETS+=("${r}"); done < <(gs::repos)
else
if [[ ${#REPOS[@]:-0} -eq 0 ]]; then
gs::die "no REPOS configured (use --all)"
fi
for r in "${REPOS[@]}"; do TARGETS+=("${BASE_DIR}/${r}"); done
fi
printf '| Repository | Branch | Local HEAD | Origin HEAD | In sync? |\n'
printf '| --- | --- | --- | --- | --- |\n'
declare -i N=0 OK=0 DRIFT=0 SKIP=0
for repo in "${TARGETS[@]}"; do
name="$(basename -- "${repo}")"
if [[ ! -d "${repo}/.git" ]]; then
printf '| %s | _missing_ | - | - | skip |\n' "${name}"
(( SKIP++ )) || true
continue
fi
cd "${repo}" || { (( SKIP++ )) || true; continue; }
branch="$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "?")"
local_msg="$(git log -1 --pretty=format:'%s' 2>/dev/null || echo "")"
if git rev-parse --verify "origin/${branch}" >/dev/null 2>&1; then
remote_msg="$(git log -1 --pretty=format:'%s' "origin/${branch}" 2>/dev/null || echo "")"
else
remote_msg="(no upstream)"
fi
sync="No"
[[ "${local_msg}" == "${remote_msg}" ]] && sync="Yes"
[[ "${sync}" = "Yes" ]] && (( OK++ )) || (( DRIFT++ )) || true
(( N++ )) || true
printf '| %s | %s | %.60s | %.60s | %s |\n' \
"${name}" "${branch}" "${local_msg}" "${remote_msg}" "${sync}"
done
gs::info "scanned=${N} in-sync=${OK} drift=${DRIFT} skipped=${SKIP}"
exit 0