-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup-gh-pages
executable file
·140 lines (114 loc) · 4.05 KB
/
setup-gh-pages
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env bash
#
# Run this script from within the root directory of the git clone of
# your package in order to create a gh-pages subdirectory, containing a
# checkout of your gh-pages branch. If no gh-pages branch exists, it
# also creates one.
#
# Copyright (c) 2018-2019 Max Horn
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
#
set -e
######################################################################
#
# Various little helper functions
# print notices in green
notice() {
printf '\033[32m%s\033[0m\n' "$*"
}
# print warnings in yellow
warning() {
printf '\033[33mWARNING: %s\033[0m\n' "$*"
}
# print error in red and exit
error() {
printf '\033[31mERROR: %s\033[0m\n' "$*"
exit 1
}
######################################################################
# error early on if there already is a gh-pages dir
[[ -d gh-pages ]] && error "You already have a gh-pages directory"
# TODO: make it configurable which remote is used (default: origin)
remote=${remote:-origin}
# TODO: make it configurable how/which gap is used
GAP=${GAP:-gap}
# Based on the git documentation and some experiments, `git worktree add`
# in git 2.7 and newer works as desired. It is possible that 2.6 also
# did, but since I can't easily test that right now, I'll err on the
# safe
git_major=$(git --version | sed -E 's/[^0-9]+([0-9]+).*/\1/')
git_minor=$(git --version | sed -E 's/[^0-9]+[0-9]+\.([0-9]+).*/\1/')
if [[ $git_major -gt 2 || ($git_major -eq 2 && $git_minor -ge 7) ]]
then
UseWorktree=Yes
else
UseWorktree=No
fi
notice "Detected git ${git_major}.${git_minor}, using git worktree: ${UseWorktree}"
# TODO: add /gh-pages/ to .gitignore if it is not already in there
if [[ ${UseWorktree} = No ]]
then
# Create a fresh clone of your repository, and change into it
url=$(git config --get remote.${remote}.url)
git clone ${url} gh-pages
cd gh-pages
fi
# Add a new remote pointing to the GitHubPagesForGAP repository
git remote add -f gh-gap https://github.com/gap-system/GitHubPagesForGAP 2>/dev/null || :
# if there is already a gh-pages branch, do nothing; otherwise, if
# there is a ${remote}/gh-pages branch, create `gh-pages` tracking
# the remote; otherwise, create a fresh `gh-pages` branch
IsNewBranch=No
if git rev-parse -q --verify gh-pages
then
notice "Using existing gh-pages branch"
else
# fetch remote changes, so that we can see if there
# is a remote gh-pages branch
git fetch ${remote}
if git rev-parse -q --verify ${remote}/gh-pages
then
notice "Track existing remote gh-pages branch"
git branch --track gh-pages ${remote}/gh-pages
else
notice "Create a fresh gh-pages branch"
git branch --no-track gh-pages gh-gap/gh-pages
# ... then push it and set up tracking
git push --set-upstream ${remote} gh-pages
# remember that this is a new branch
IsNewBranch=Yes
fi
fi
if [[ ${UseWorktree} = Yes ]]
then
# create a new worktree and change into it
git worktree add gh-pages gh-pages
cd gh-pages
fi
if [[ ${IsNewBranch} = Yes ]]
then
notice "Updating new gh-pages branch"
cp -f ../PackageInfo.g ../README* .
[[ -d doc ]] && git rm -rf doc
mkdir -p doc/
cp -f ../doc/*.{css,html,js,txt} doc/ || :
[[ -d ../htm ]] && cp -r ../htm .
${GAP} update.g
git add .
git commit -m "Setup gh-pages based on GitHubPagesForGAP"
git push --set-upstream ${remote} gh-pages
fi