|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# |
| 4 | +# For projects that have been migrated from Google Code to GitHub, move wiki data from the |
| 5 | +# 'wiki' branch to the project's README.md & its GitHub wiki. |
| 6 | +# |
| 7 | +# v0.1 2015-03-14 - Morgan Aldridge <[email protected]> |
| 8 | +# Initial version. |
| 9 | +# |
| 10 | + |
| 11 | +# validate input |
| 12 | +if [[ ( $# -eq 1 ) && ( "$1" = ~ ^ [email protected]:([^/]+)/(.+).git ) ]] ; then |
| 13 | + user="${BASH_REMATCH[1]}" |
| 14 | + repo="${BASH_REMATCH[2]}" |
| 15 | +else |
| 16 | + echo "$0: Invalid input!" |
| 17 | + echo "Exiting." |
| 18 | + exit 1 |
| 19 | +fi |
| 20 | + |
| 21 | +# clone the repo & wiki repos |
| 22 | +if [[ ( -e "$repo" ) || ( -e "${repo}.wiki" ) ]]; then |
| 23 | + echo "Either '$repo' or '${repo}.wiki' already exist!" |
| 24 | + echo "Exiting." |
| 25 | + exit 1 |
| 26 | +fi |
| 27 | +echo -n "Cloning '${user}/${repo}'... " |
| 28 | +if git clone -q "$1"; then |
| 29 | + echo "Done." |
| 30 | +else |
| 31 | + echo "Error!" |
| 32 | + echo "Exiting." |
| 33 | + exit 1 |
| 34 | +fi |
| 35 | +echo -n "Cloning '${user}/${repo}.wiki'... " |
| 36 | +if git clone -q "[email protected]:${user}/${repo}.wiki.git"; then |
| 37 | + echo "Done." |
| 38 | +else |
| 39 | + echo "Error!" |
| 40 | + echo "Exiting." |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +# move the ProjectHome page to README in the main repo, if one doesn't exist |
| 45 | +echo -n "Moving ProjectHome.md from wiki branch to README.md in master branch... " |
| 46 | +if [[ ! -e "${repo}/README.md" ]]; then |
| 47 | + cd "$repo" |
| 48 | + git checkout -q wiki |
| 49 | + if [[ ! -e "ProjectHome.md" ]]; then |
| 50 | + echo "ProjectHome.md doesn't exist." |
| 51 | + else |
| 52 | + cp "ProjectHome.md" "README.md" |
| 53 | + git checkout -q master |
| 54 | + git add README.md |
| 55 | + git commit -q -m "$0: Moved ProjectHome.md from wiki branch to README.md in master branch." |
| 56 | + echo "Done." |
| 57 | + fi |
| 58 | + cd .. |
| 59 | +else |
| 60 | + echo "README.md already exists! Skipping." |
| 61 | +fi |
| 62 | + |
| 63 | +# copy all the pages from the wiki branch to the wiki repo |
| 64 | +echo -n "Moving pages from wiki branch to ${repo}.wiki repo... " |
| 65 | +cd "$repo" |
| 66 | +git checkout -q wiki |
| 67 | +rsync -aE *.md ../${repo}.wiki/ |
| 68 | +git checkout -q master |
| 69 | +cd ../${repo}.wiki |
| 70 | +mv ProjectHome.md Home.md |
| 71 | +git add *.md |
| 72 | +git commit -q -m "$0: Moved pages from $repo wiki branch to ${repo}.wiki master branch." |
| 73 | +echo "Done." |
| 74 | + |
| 75 | +# display followup instructions |
| 76 | +echo |
| 77 | +echo "The '$repo' & '${repo}.wiki' clones have been updated & commits applied." |
| 78 | +echo "Please review both (I suggest at least a 'git log' & 'git diff HEAD^1') " |
| 79 | +echo "and perform a 'git push' on each, if the results are satisfactory." |
| 80 | + |
0 commit comments