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
|
#!/usr/bin/env bash
# Ensures that the working tree is clean, and Documentation/ is up to
# date, and then commits Documentation/*.1 to the man branch, and
# Documentation/*.html to the html branch.
set -uexo pipefail
test "$#" -eq 2
# Must be full ref name, i.e. refs/heads/man, etc.
man_ref="$1"
html_ref="$2"
if ! git diff-index --quiet HEAD --; then
echo 'error: uncommitted changes'
exit 2
fi
git rev-parse --verify "$man_ref"
git rev-parse --verify "$html_ref"
echo "$man_ref" | grep -qE '^refs/heads'
echo "$html_ref" | grep -qE '^refs/heads'
"${MAKE:-make}"
mkdir -p t/tmp
tmpdir="$(mktemp -d "t/tmp/update-doc-branches-XXXXXX")"
trap "$(printf 'rm -rf %q' "$tmpdir")" EXIT
tmpidx="$tmpdir/git-index.tmp"
for fmt in man html; do
rm -f "$tmpidx"
for f in $(git ls-files 'Documentation/*.md'); do
base="$(basename "$f" .md)"
if test "$fmt" = man; then
ref="$man_ref"
GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base"
else
ref="$html_ref"
GIT_INDEX_FILE="$tmpidx" git add -f "Documentation/$base.html"
fi
done
msg="Update $fmt pages for $(git describe --always)"
tree=$(GIT_INDEX_FILE="$tmpidx" git write-tree --prefix=Documentation)
commit=$(echo "$msg" | git commit-tree "$tree" -p refs/heads/"$fmt")
git update-ref "$ref" "$commit"
done
|