| 1 |
#!/usr/bin/env bash |
| 2 |
|
| 3 |
# Ensures that the working tree is clean, and Documentation/ is up to |
| 4 |
# date, and then commits Documentation/*.1 to the man branch, and |
| 5 |
# Documentation/*.html to the html branch. |
| 6 |
|
| 7 |
set -uexo pipefail |
| 8 |
|
| 9 |
test "$#" -eq 2 |
| 10 |
|
| 11 |
# Must be full ref name, i.e. refs/heads/man, etc. |
| 12 |
man_ref="$1" |
| 13 |
html_ref="$2" |
| 14 |
|
| 15 |
if ! git diff-index --quiet HEAD --; then |
| 16 |
echo 'error: uncommitted changes' |
| 17 |
exit 2 |
| 18 |
fi |
| 19 |
|
| 20 |
git rev-parse --verify "$man_ref" |
| 21 |
git rev-parse --verify "$html_ref" |
| 22 |
echo "$man_ref" | grep -qE '^refs/heads' |
| 23 |
echo "$html_ref" | grep -qE '^refs/heads' |
| 24 |
|
| 25 |
"${MAKE:-make}" |
| 26 |
|
| 27 |
mkdir -p t/tmp |
| 28 |
tmpdir="$(mktemp -d "t/tmp/update-doc-branches-XXXXXX")" |
| 29 |
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT |
| 30 |
tmpidx="$tmpdir/git-index.tmp" |
| 31 |
|
| 32 |
for fmt in man html; do |
| 33 |
rm -f "$tmpidx" |
| 34 |
for f in $(git ls-files 'Documentation/*.md'); do |
| 35 |
base="$(basename "$f" .md)" |
| 36 |
if test "$fmt" = man; then |
| 37 |
ref="$man_ref" |
| 38 |
GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base" |
| 39 |
else |
| 40 |
ref="$html_ref" |
| 41 |
GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base.html" |
| 42 |
fi |
| 43 |
done |
| 44 |
msg="Update $fmt pages for $(git describe --always)" |
| 45 |
tree=$(GIT_INDEX_FILE="$tmpidx" git write-tree --prefix=Documentation) |
| 46 |
commit=$(echo "$msg" | git commit-tree "$tree" -p refs/heads/"$fmt") |
| 47 |
git update-ref "$ref" "$commit" |
| 48 |
done |