Repository navigation
Expand file tree
/
Copy pathupdate-scribe.sh
More file actions
executable file
·82 lines (70 loc) · 3.19 KB
/
Copy pathupdate-scribe.sh
File metadata and controls
executable file
·82 lines (70 loc) · 3.19 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
#!/usr/bin/env bash
# Pull the newest Scribe into Scriptorium.
#
# Scribe lives at lib/scribe as a git submodule. A submodule records one exact
# commit, so cloning Scriptorium always gets a Scribe that is known to work with
# it — but it also means Scribe moving forward does NOT move Scriptorium. This
# script is what moves the pin: it fetches Scribe's tracking branch (`main`, as
# recorded in .gitmodules), checks out its tip, and stages the new pin.
#
# Usage:
# scripts/update-scribe.sh # bump to the latest Scribe, stage it
# scripts/update-scribe.sh --check # report whether a newer Scribe exists,
# # change nothing (exit 1 if behind)
#
# After a bump, run the tests before committing:
# wfl --test TestPrograms/util.test.wfl (and the rest — see README)
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$root"
check_only=no
if [ "${1:-}" = "--check" ]; then
check_only=yes
elif [ "$#" -gt 0 ]; then
echo "usage: scripts/update-scribe.sh [--check]" >&2
exit 2
fi
if [ ! -e lib/scribe/src/scribe.wfl ]; then
echo "lib/scribe is not checked out. Run:" >&2
echo " git submodule update --init --recursive" >&2
exit 1
fi
before="$(git -C lib/scribe rev-parse HEAD)"
branch="$(git config -f .gitmodules submodule.lib/scribe.branch || echo main)"
git -C lib/scribe fetch --quiet origin "$branch"
after="$(git -C lib/scribe rev-parse FETCH_HEAD)"
if [ "$before" = "$after" ]; then
echo "Scribe is already at the tip of $branch ($(git -C lib/scribe log -1 --format=%h))."
exit 0
fi
# The pin can legitimately sit *ahead* of the tracking branch — e.g. it points at
# a Scribe branch whose PR has not merged yet. Bumping would be a downgrade, so
# say so and leave it alone.
if git -C lib/scribe merge-base --is-ancestor "$after" "$before"; then
echo "The pinned Scribe is ahead of $branch — nothing to bump."
echo "Pinned commits not yet on $branch:"
git -C lib/scribe log --oneline --no-decorate "$after..$before" | sed 's/^/ /'
exit 0
fi
# Neither is an ancestor of the other: the histories have diverged, so moving to
# `after` would silently drop the commits unique to the pinned revision. That is
# a maintainer decision, not something a bump script should make.
if ! git -C lib/scribe merge-base --is-ancestor "$before" "$after"; then
echo "Scribe $branch has diverged from the pinned revision — refusing to bump." >&2
echo " pinned only: $(git -C lib/scribe rev-list --count "$after..$before") commit(s)" >&2
echo " $branch only: $(git -C lib/scribe rev-list --count "$before..$after") commit(s)" >&2
echo "Resolve upstream, then re-run. The pin is unchanged." >&2
exit 1
fi
echo "Scribe $branch has moved:"
git -C lib/scribe log --oneline --no-decorate "$before..$after" | sed 's/^/ /'
if [ "$check_only" = yes ]; then
echo
echo "Run scripts/update-scribe.sh (without --check) to bump the pin."
exit 1
fi
git -C lib/scribe checkout --quiet --detach "$after"
git add lib/scribe
echo
echo "Bumped lib/scribe: $(git -C lib/scribe rev-parse --short "$before") -> $(git -C lib/scribe rev-parse --short "$after") (staged)."
echo "Run the test suites, then commit."