-
Notifications
You must be signed in to change notification settings - Fork 307
/
sync
executable file
·49 lines (40 loc) · 1.77 KB
/
sync
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
#!/usr/bin/env bash
# This script implements a two-way mirroring bewteen a GH wiki for a repo `R`
# (called `DOTREMOTE` below) with a public repo `R-wiki` (intended for external
# contributions, called `DASHREMOTE` below). See `sync.yml` for how it is
# triggered: it is a minimal-ish yaml file that should be added to both sides
# (`R` and `R-wiki`), with a `push` trigger on `R-wiki` (and optionally a
# schedule) and a `gollum` trigger on `R`. The action spec is careful to
# always checkout `R-wiki` (`DASHREMOTE`) since checking out `R` would be
# useless. It then merges in changes in `DOTREMOTE` and pushes the results to
# both. Pushing the merged version will trigger an action on the other side,
# but that would be very quick (both the `merge` and pushing it will be
# no-ops.)
set -ue
shopt -s extglob
PUSHER="${PUSHER// +( )/ }"; PUSHER="${PUSHER# }"; PUSHER="${PUSHER% }"
NAME="${PUSHER% <*}"
EMAIL="${PUSHER##* <}"; EMAIL="${EMAIL%>}"
echo "Setting git username to \"$NAME\" and email to \"$EMAIL\""
export GIT_AUTHOR_NAME="$NAME"
export GIT_AUTHOR_EMAIL="$EMAIL"
export GIT_COMMITTER_NAME="$NAME"
export GIT_COMMITTER_EMAIL="$EMAIL"
DASHREMOTE="$(git remote get-url origin)"
DOTREMOTE="${DASHREMOTE//-wiki/.wiki}"
echo "DASHREMOTE = $DASHREMOTE, DOTREMOTE = $DOTREMOTE"
for r in "$DASHREMOTE" "$DOTREMOTE"; do
if [[ "$(git ls-remote --symref "$r" HEAD | grep "^ref:")" \
!= $'ref: refs/heads/master\tHEAD' ]]; then
echo "Unexpected branch name at $r: expected to see \"master\""
fi
done
echo ">>> Adding and fetching DOTREMOTE"
git remote add dot "$DOTREMOTE"
git fetch dot
echo ">>> Merging changes"
git pull --no-edit --no-rebase dot "master"
echo ">>> Pushing merges to DASHREMOTE"
git push origin
echo ">>> Pushing merges to DOTREMOTE"
git push dot main:master