This repository has been archived by the owner on Jul 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
/
run.sh
executable file
·191 lines (158 loc) · 5.07 KB
/
run.sh
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/sh
# Split this repository into smaller repositories
# Only tested with macOS
# Exit on error
set -e
# --- Config settings ---------------------------------------------------------
# Directory where the new split repositories will live
# Can be overridden when running the script with -d /PATH/TO/DIR
DIR="/Users/john/repositories/GF-SPLIT"
# Repository names
REP_PRISTINE="pristine"
REP_CORE="gf-core"
REP_RGL="gf-rgl"
# Push to remotes?
PUSH="true"
# Text prefix to include in commit messages created by this script
COMMIT_PREFIX="[GF Split] "
# Directory name suffix for backups/clones
BACKUP_SUFFIX="_copy"
CLONED_SUFFIX="_cloned"
# --- Are you sure? -----------------------------------------------------------
echo "GF repository split script"
echo "Usage: run.sh [-d PATH] [-y]"
echo
CONFIRM=""
while getopts "yd:" FLAG; do
case "$FLAG" in
y) CONFIRM="true" ;;
d) DIR="$OPTARG" ;;
*) exit 1
esac
done
if [ "$CONFIRM" != true ]; then
echo "This script will [re]create the following directories:"
echo " ${DIR}/${REP_PRISTINE}"
echo " ${DIR}/${REP_CORE}"
echo " ${DIR}/${REP_CORE}${BACKUP_SUFFIX}"
echo " ${DIR}/${REP_CORE}${CLONED_SUFFIX}"
echo " ${DIR}/${REP_RGL}"
echo " ${DIR}/${REP_RGL}${BACKUP_SUFFIX}"
echo " ${DIR}/${REP_RGL}${CLONED_SUFFIX}"
echo "To change the path, set the DIR variable in this script or use the -d flag."
echo "When you are sure, re-run this script with the -y flag."
exit 0
fi
# --- Setting up --------------------------------------------------------------
# Make a brand new clone which is copied for each sub repo
mkdir -p "$DIR"
cd "$DIR"
echo "# $REP_PRISTINE"
if [ -d "$REP_PRISTINE" ]; then
echo "Pulling..."
cd "$REP_PRISTINE"
git pull --quiet
echo "Cleaning..."
git clean -x --force
cd ..
else
echo "Cloning..."
git clone git@github.com:GrammaticalFramework/GF.git "$REP_PRISTINE"
fi
# --- Begin building repos ----------------------------------------------------
# === core ===
# - remove RGL (filter out lib directory)
# - shrink
# - update build scripts
echo
echo "# ${REP_CORE}"
echo "Copying..."
rm -rf "$REP_CORE"
cp -R "$REP_PRISTINE" "$REP_CORE"
echo "Filtering (this will take some time)..."
cd "$REP_CORE"
RM_DIRS="lib split"
# git filter-branch --tree-filter "rm -rf ${RM_DIRS}" --prune-empty HEAD
git filter-branch --index-filter "git rm --cached --ignore-unmatch --quiet -r -- ${RM_DIRS}" --prune-empty HEAD
echo "Backing up filtered repository..."
cd ..
cp -R "$REP_CORE" "${REP_CORE}${BACKUP_SUFFIX}"
cd "$REP_CORE"
echo "Cloning..."
cd ..
git clone "file://`pwd`/$REP_CORE" "${REP_CORE}${CLONED_SUFFIX}"
rm -rf "$REP_CORE"
mv "${REP_CORE}${CLONED_SUFFIX}" "$REP_CORE"
cd "$REP_CORE"
echo "Shrinking..."
# git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# git reflog expire --expire=now --all
git gc --prune=now --aggressive
echo "Post-split updates..."
CP_FILES="Setup.hs"
for FILE in $CP_FILES ; do
cp "${DIR}/${REP_PRISTINE}/split/${REP_CORE}/${FILE}" .
done
git apply "${DIR}/${REP_PRISTINE}/split/${REP_CORE}/diff.patch"
git add .
git commit -m "${COMMIT_PREFIX}Post-split updates" --quiet
echo "Set origin to git@github.com:GrammaticalFramework/${REP_CORE}.git"
git remote set-url origin "git@github.com:GrammaticalFramework/${REP_CORE}.git"
if [ "$PUSH" = true ]; then
echo "Pushing..."
git push --set-upstream --force origin master
fi
cd ..
# === RGL ===
# - filter just `lib` directory
# - shrink
# - clean up
# - update build scripts
echo
echo "# ${REP_RGL}"
echo "Copying..."
rm -rf "$REP_RGL"
cp -R -- "$REP_PRISTINE" "$REP_RGL"
echo "Filtering (this will take some time)..."
cd "$REP_RGL"
git filter-branch --prune-empty --subdirectory-filter lib --tag-name-filter cat -- --all
echo "Backing up filtered repository..."
cd ..
cp -R "$REP_RGL" "${REP_RGL}${BACKUP_SUFFIX}"
cd "$REP_RGL"
echo "Cloning..."
cd ..
git clone "file://`pwd`/$REP_RGL" "${REP_RGL}${CLONED_SUFFIX}"
rm -rf "$REP_RGL"
mv "${REP_RGL}${CLONED_SUFFIX}" "$REP_RGL"
cd "$REP_RGL"
echo "Shrinking..."
# git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
# git reflog expire --expire=now --all
git gc --prune=now --aggressive
echo "Post-split updates..."
CP_FILES=".gitignore Make.hs Make.sh Make.bat Makefile README.md"
for FILE in $CP_FILES ; do
cp "${DIR}/${REP_PRISTINE}/split/${REP_RGL}/${FILE}" .
done
git add .
git rm --quiet "src/Makefile"
git rm -r --quiet "src/old-demo"
git mv "src/mkPresent" .
git commit -m "${COMMIT_PREFIX}Post-split updates" --quiet
echo "Set origin to git@github.com:GrammaticalFramework/${REP_RGL}.git"
git remote set-url origin "git@github.com:GrammaticalFramework/${REP_RGL}.git"
if [ "$PUSH" = true ]; then
echo "Pushing..."
git push --set-upstream --force origin master
fi
cd ..
# --- Finally ----------------------------------------------------------------
echo
echo "Done. Your new repositories are at:"
echo " ${DIR}/${REP_CORE}"
echo " ${DIR}/${REP_RGL}"
echo "You may want to delete these repositories:"
echo " ${DIR}/${REP_PRISTINE}"
echo " ${DIR}/${REP_CORE}${BACKUP_SUFFIX}"
echo " ${DIR}/${REP_RGL}${BACKUP_SUFFIX}"