#!/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 # 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" =~ ^git@github.com:([^/]+)/(.+).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 "git@github.com:${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."