mirror of
https://github.com/fortressforever/git-svn-sync.git
synced 2024-11-10 06:42:01 +00:00
Allow using a remote git repo and don't assume the svn is write-protected
* The git hooks to trigger the sync will have to be setup independently
This commit is contained in:
parent
4c12f4021f
commit
6537ae771e
4 changed files with 9 additions and 57 deletions
|
@ -21,10 +21,11 @@
|
|||
# stored.
|
||||
# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with
|
||||
# subversion.
|
||||
# - GIT_SVN_SYNC_EMAIL: email to send error reports to
|
||||
#
|
||||
# Usage: git-sync-with-svn.sh project_name
|
||||
|
||||
destination=receiver@host.com
|
||||
destination=${GIT_SVN_SYNC_EMAIL}
|
||||
project=${1?No project provided}
|
||||
location=${GIT_SVN_SYNC_BASE}/${project}
|
||||
|
||||
|
@ -55,6 +56,8 @@ git pull --ff-only origin master || { report "Could not pull changes from git re
|
|||
# Synchronize with SVN
|
||||
echo "Synchronizing with SVN"
|
||||
git checkout ${GIT_SVN_SYNC_BRANCH} || { report "Could not switch to sync branch" ; exit 1; }
|
||||
echo "Pulling any SVN changes"
|
||||
git svn rebase
|
||||
# In case of conflicts, take the master, as we are sure that this is
|
||||
# the correct branch
|
||||
git merge -Xtheirs master || { report "Could not merge changes into sync branch" ; exit 1; }
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with
|
||||
# subversion.
|
||||
#
|
||||
# Usage: git-repository-from-svn.sh project svn_url
|
||||
# Usage: git-repository-from-svn.sh project svn_url git_url
|
||||
|
||||
if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_BASE}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_SYNC_BRANCH}" ] ; then
|
||||
if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_SYNC_BRANCH}" ] ; then
|
||||
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}
|
||||
location=${GIT_BASE}/${project}.git
|
||||
git_url=${3?No git url provided}
|
||||
client=${GIT_SVN_SYNC_BASE}/${project}
|
||||
|
||||
if [ -d $location ] ; then
|
||||
|
@ -37,22 +37,13 @@ if [ -d $client ] ; then
|
|||
exit 1
|
||||
fi
|
||||
|
||||
# Git Server
|
||||
git init --bare ${location} || { echo "Could not initialize git server at ${location}" ; exit 1; }
|
||||
|
||||
# Sync client
|
||||
git svn clone ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; }
|
||||
git svn clone --parent ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; }
|
||||
|
||||
cd ${client}
|
||||
git remote add origin ${location} || { echo "Could not set up server as remote from sync" ; exit 1; }
|
||||
git push origin master || { echo "Could not sync client with server" ; exit 1; }
|
||||
git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; }
|
||||
git branch ${GIT_SVN_SYNC_BRANCH} || { echo "Could not create svn sync branch" ; exit 1; }
|
||||
|
||||
# Set up hooks
|
||||
for hook in pre-receive post-receive ; do
|
||||
ln -s ${GIT_SCRIPTS}/server-hooks/${hook} ${location}/hooks
|
||||
done
|
||||
|
||||
for hook in pre-receive pre-commit ; do
|
||||
ln -s ${GIT_SCRIPTS}/sync-client-hooks/always-reject ${client}/.git/hooks/${hook}
|
||||
done
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
# -*- mode: Shell-script-*-
|
||||
#!/usr/bin/bash
|
||||
#
|
||||
# This hook is intended to be installed for a git server. It calls a
|
||||
# script that synchronizes every change with subversion.
|
||||
#
|
||||
# Required environment variables:
|
||||
# - GIT_SCRIPTS: directory where the git sync scripts are located
|
||||
#
|
||||
# Author: Mario Fernandez
|
||||
|
||||
master="refs/heads/master"
|
||||
|
||||
while read oldrev newrev refname
|
||||
do
|
||||
if [ "$master" == "$refname" ] ; then
|
||||
sh ${GIT_SCRIPTS}/git-sync-with-svn.sh $(basename $PWD .git)
|
||||
fi
|
||||
done
|
|
@ -1,23 +0,0 @@
|
|||
# -*- mode: Shell-script-*-
|
||||
#!/usr/bin/bash
|
||||
#
|
||||
# This hook is intended to be installed for a git server. It calls a
|
||||
# script that synchronizes every change with subversion.
|
||||
#
|
||||
# Required environment variables:
|
||||
# - GIT_SCRIPTS: directory where the git sync scripts are located
|
||||
#
|
||||
# Author: Mario Fernandez
|
||||
|
||||
if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_SYNC_BRANCH}" ] ; then
|
||||
echo "The following variables are required for the synchronization to work: GIT_SCRIPTS GIT_SVN_SYNC_BASE GIT_SVN_SYNC_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
while read oldrev newrev refname
|
||||
do
|
||||
if [ "$refname" == "${GIT_SVN_SYNC_BRANCH}" ] ; then
|
||||
echo "It is not allowed to push a branch named ${GIT_SVN_SYNC_BRANCH} to avoid conflicts when syncing with subversion"
|
||||
exit 1
|
||||
fi
|
||||
done
|
Loading…
Reference in a new issue