forked from morgant/finishGoogleCodeGitHubWikiMigration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinishGoogleCodeGitHubWikiMigration
executable file
·116 lines (109 loc) · 3.9 KB
/
finishGoogleCodeGitHubWikiMigration
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
#!/bin/bash
#
# finishGoogleCodeGitHubWikiMigration
#
# For projects that have been migrated from Google Code to GitHub, move wiki data from the
# 'wiki' branch to the project's README.md & its GitHub wiki.
#
# v0.1 2015-03-15 - Morgan Aldridge <[email protected]>
# Initial version.
# v0.2 2015-03-28 - Morgan Aldridge
# HTTPS support, with thanks to Piper Chester.
# v0.3 2015-09-12 - Morgan Aldridge
# Fixes to HTTPS support.
#
# Copyright (c) 2015 Morgan T. Aldridge
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# validate input
https=false
if [[ ( $# -eq 1 ) && ( "$1" =~ ^[email protected]:([^/]+)/(.+).git ) ]]; then
user="${BASH_REMATCH[1]}"
repo="${BASH_REMATCH[2]}"
elif [[ ( $# -eq 1 ) && ( "$1" =~ https://github.com/([^/]+)/(.+).git ) ]]; then
user="${BASH_REMATCH[1]}"
repo="${BASH_REMATCH[2]}"
https=true
else
echo "$0: Invalid input!"
echo "Exiting."
exit 1
fi
# clone the repo & wiki repos
if [[ ( -e "$repo" ) || ( -e "${repo}.wiki" ) ]]; then
echo "Either '$repo' or '${repo}.wiki' already exist!"
echo "Exiting."
exit 1
fi
echo -n "Cloning '${user}/${repo}'... "
if git clone -q "$1"; then
echo "Done."
else
echo "Error!"
echo "Exiting."
exit 1
fi
echo -n "Cloning '${user}/${repo}.wiki'... "
if $https && git clone -q "https://github.com/${user}/${repo}.wiki.git"; then
echo "Done over HTTPS."
elif ! $https && git clone -q "[email protected]:${user}/${repo}.wiki.git"; then
echo "Done."
else
echo "Error!"
echo "Exiting."
exit 1
fi
# move the ProjectHome page to README in the main repo, if one doesn't exist
echo -n "Moving ProjectHome.md from wiki branch to README.md in master branch... "
if [[ ! -e "${repo}/README.md" ]]; then
cd "$repo"
git checkout -q wiki
if [[ ! -e "ProjectHome.md" ]]; then
echo "ProjectHome.md doesn't exist."
else
cp "ProjectHome.md" "README.md"
sed -i"" -e "s/\(([^\)]+).md\)/(wiki\/\1)/g" README.md
git checkout -q master
git add README.md
git commit -q -m "$0: Moved ProjectHome.md from wiki branch to README.md in master branch."
echo "Done."
fi
cd ..
else
echo "README.md already exists! Skipping."
fi
# copy all the pages from the wiki branch to the wiki repo
echo -n "Moving pages from wiki branch to ${repo}.wiki repo... "
cd "$repo"
git checkout -q wiki
rsync -a -p *.md ../${repo}.wiki/
git checkout -q master
cd ../${repo}.wiki
mv ProjectHome.md Home.md
find . -name "*.md" -exec sed -i"" -e "s/\(([^\)]+).md\)/(\1)/g" '{}' +
# find . -name "*.md" | xargs sed -i "" -e "s/\(([^\)]+).md\)/(\1)/g"
git add *.md
git commit -q -m "$0: Moved pages from $repo wiki branch to ${repo}.wiki master branch."
echo "Done."
# display followup instructions
echo
echo "The '$repo' & '${repo}.wiki' clones have been updated & commits applied."
echo "Please review both (I suggest at least a 'git log' & 'git diff HEAD^1') "
echo "and only perform a 'git push' on each, if the results are satisfactory."