Skip to content

Instantly share code, notes, and snippets.

@mgoellnitz
Last active November 16, 2016 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgoellnitz/b39e460eda02de209ebfc7fd63d10dea to your computer and use it in GitHub Desktop.
Save mgoellnitz/b39e460eda02de209ebfc7fd63d10dea to your computer and use it in GitHub Desktop.
Shell script to mirror a Fossil SCM repository to github.com
#!/bin/sh
#
# Copyright 2016 Martin Goellnitz
#
# 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 3 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
BASE=`pwd`
DIR=`basename $BASE`
FOSSIL=`fossil status 2>&1|head -1`
CHECK=`echo $FOSSIL|cut -d ':' -f 1`
if [ "$CHECK" = "repository" ] ; then
FILE=`echo $FOSSIL|cut -d ':' -f 2-200`
cd $BASE/..
else
if [ -z "$1" ] ; then
echo "Must be in opened repository directory or better give the repository database filename as the first parameter to $0"
exit
fi
FILE=$1
fi
if [ "$FILE" = "$1" ] ; then
GIT=$2
else
GIT=$1
fi
if [ -z "$GIT" ] ; then
GIT="git@github.com:mgoellnitz/${DIR}"
fi
echo "File: $FILE - Git: $GIT"
if [ ! -f $FILE ] ; then
echo "$FILE is no repository to clone"
fi
git clone $GIT git-mirror
(cd git-mirror; git config --local push.default matching)
fossil export --git $FILE |(cd git-mirror ; git fast-import)
cd git-mirror
echo "Merging trunk to master to gits sake"
git checkout master
git merge trunk
for b in `git branch -l|sed -e 's/\*//g'` ; do
echo "Last commit on branch $b"
git log|head -5
echo "pushing branch $b"
git push origin $b
done
cd ..
rm -rf git-mirror
cd $BASE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment