2012-05-30 09:58:42 +00:00
|
|
|
# -*- mode: Shell-script-*-
|
|
|
|
#!/usr/bin/bash
|
|
|
|
#
|
|
|
|
# Author: Mario Fernandez
|
|
|
|
#
|
|
|
|
# Initializes a git repository that is synchronized with an existing
|
|
|
|
# svn repository.
|
|
|
|
#
|
|
|
|
# Required environment variabless:
|
|
|
|
# - GIT_SCRIPTS: directory where the git sync scripts are located
|
|
|
|
# - GIT_SVN_SYNC_BASE: directory where the sync repositories are
|
|
|
|
# stored.
|
|
|
|
# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with
|
|
|
|
# subversion.
|
|
|
|
#
|
2014-11-12 02:03:38 +00:00
|
|
|
# Usage: git-repository-from-svn.sh project svn_url git_url
|
2012-05-30 09:58:42 +00:00
|
|
|
|
2014-11-12 02:03:38 +00:00
|
|
|
if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_SYNC_BRANCH}" ] ; then
|
2012-05-30 09:58:42 +00:00
|
|
|
echo "The following variables are required for the synchronization to work: GIT_SCRIPTS GIT_SVN_SYNC_BASE GIT_SVN_SYNC_BRANCH"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
project=${1?No project name provided}
|
|
|
|
svn_url=${2?No svn url provided}
|
2014-11-12 02:03:38 +00:00
|
|
|
git_url=${3?No git url provided}
|
2012-05-30 09:58:42 +00:00
|
|
|
client=${GIT_SVN_SYNC_BASE}/${project}
|
|
|
|
|
|
|
|
if [ -d $client ] ; then
|
|
|
|
echo "The folder for the git sync client already exists"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Sync client
|
2014-11-12 02:03:38 +00:00
|
|
|
git svn clone --parent ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; }
|
2012-05-30 09:58:42 +00:00
|
|
|
|
|
|
|
cd ${client}
|
2014-11-12 02:03:38 +00:00
|
|
|
git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; }
|
2012-05-30 09:58:42 +00:00
|
|
|
git branch ${GIT_SVN_SYNC_BRANCH} || { echo "Could not create svn sync branch" ; exit 1; }
|
|
|
|
|
|
|
|
for hook in pre-receive pre-commit ; do
|
|
|
|
ln -s ${GIT_SCRIPTS}/sync-client-hooks/always-reject ${client}/.git/hooks/${hook}
|
|
|
|
done
|