From 6537ae771e1bbf7707af47e1beb98e4662e51251 Mon Sep 17 00:00:00 2001 From: squeek Date: Tue, 11 Nov 2014 18:03:38 -0800 Subject: [PATCH] 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 --- git-sync-with-svn.sh | 5 ++++- install/git-repository-from-svn.sh | 19 +++++-------------- server-hooks/post-receive | 19 ------------------- server-hooks/pre-receive | 23 ----------------------- 4 files changed, 9 insertions(+), 57 deletions(-) delete mode 100755 server-hooks/post-receive delete mode 100755 server-hooks/pre-receive diff --git a/git-sync-with-svn.sh b/git-sync-with-svn.sh index 561c315..4986f64 100755 --- a/git-sync-with-svn.sh +++ b/git-sync-with-svn.sh @@ -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; } diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 248e4e2..78e5c0c 100644 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -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 diff --git a/server-hooks/post-receive b/server-hooks/post-receive deleted file mode 100755 index 268de15..0000000 --- a/server-hooks/post-receive +++ /dev/null @@ -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 diff --git a/server-hooks/pre-receive b/server-hooks/pre-receive deleted file mode 100755 index 6a85cd0..0000000 --- a/server-hooks/pre-receive +++ /dev/null @@ -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