From 5e21ed0341fa32da8a182ba28acd1772ec16584b Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 14:54:01 +0100 Subject: [PATCH 01/23] Add extra variables to tune svn clone Add environment variables to overwrite default SVN branch name and layout. Also add a variable to specify authors file. --- install/git-repository-from-svn.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index bb847b8..0b22318 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -20,6 +20,10 @@ if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_S exit 1 fi +: ${GIT_SVN_SYNC_BRANCH:="svn"} +: ${GIT_SVN_LAYOUT:="--stdlayout"} +: ${GIT_SVN_AUTHORS:="--authors-file=${GIT_SVN_SYNC_BASE}/authors.txt"} + project=${1?No project name provided} svn_url=${2?No svn url provided} git_url=${3?No git url provided} @@ -31,7 +35,7 @@ if [ -d $client ] ; then fi # Sync client -git svn clone ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } +git svn clone ${GIT_SVN_LAYOUT} ${GIT_SVN_AUTHORS} ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } cd ${client} git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; } From fb748d152e74cf513e6bb2a0cc20114e065aad84 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 17:35:07 +0100 Subject: [PATCH 02/23] Quote to handle space in file paths --- install/git-repository-from-svn.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 0b22318..3085b07 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -24,23 +24,23 @@ fi : ${GIT_SVN_LAYOUT:="--stdlayout"} : ${GIT_SVN_AUTHORS:="--authors-file=${GIT_SVN_SYNC_BASE}/authors.txt"} -project=${1?No project name provided} -svn_url=${2?No svn url provided} -git_url=${3?No git url provided} -client=${GIT_SVN_SYNC_BASE}/${project} +project="${1?No project name provided}" +svn_url="${2?No svn url provided}" +git_url="${3?No git url provided}" +client="${GIT_SVN_SYNC_BASE}/${project}" -if [ -d $client ] ; then +if [ -d "$client" ] ; then echo "The folder for the git sync client already exists" exit 1 fi # Sync client -git svn clone ${GIT_SVN_LAYOUT} ${GIT_SVN_AUTHORS} ${svn_url} ${client} || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } +git svn clone "${GIT_SVN_LAYOUT}" "${GIT_SVN_AUTHORS}" "${svn_url}" "${client}" || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } -cd ${client} +cd "${client}" 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; } for hook in pre-receive pre-commit ; do - ln -s ${GIT_SCRIPTS}/sync-client-hooks/always-reject ${client}/.git/hooks/${hook} + ln -s "${GIT_SCRIPTS}/sync-client-hooks/always-reject" "${client}/.git/hooks/${hook}" done From 2f6f1527b82fddce2d8365448bd45e479659e0c4 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 17:36:31 +0100 Subject: [PATCH 03/23] Quote to handle space in file paths --- git-sync-with-svn.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/git-sync-with-svn.sh b/git-sync-with-svn.sh index 4986f64..3e2ddac 100755 --- a/git-sync-with-svn.sh +++ b/git-sync-with-svn.sh @@ -25,21 +25,21 @@ # # Usage: git-sync-with-svn.sh project_name -destination=${GIT_SVN_SYNC_EMAIL} -project=${1?No project provided} -location=${GIT_SVN_SYNC_BASE}/${project} +destination="${GIT_SVN_SYNC_EMAIL}" +project="${1?No project provided}" +location="${GIT_SVN_SYNC_BASE}/${project}" -if [ ! -d $location ] ; then +if [ ! -d "$location" ] ; then echo "The folder where the synchronization repository is supposed to be does not exist" exit 1 fi unset GIT_DIR -cd $location +cd "$location" report () { echo $1 - sh ${GIT_SCRIPTS}/report-error.sh $destination "$project" "$1" + sh "${GIT_SCRIPTS}/report-error.sh" "$destination" "$project" "$1" } # Get changes from git repository From 8b918213e1a997fd1ff7e274cfeb66328420874c Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:12:06 +0100 Subject: [PATCH 04/23] Add option to copy rather than link hooks As it's not always elegant to refer to external script and the hooks are rather simple, I've added a simple environment variable to replace "ln -s" by "cp" for instance. --- install/git-repository-from-svn.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 3085b07..8286c5d 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -6,12 +6,16 @@ # Initializes a git repository that is synchronized with an existing # svn repository. # -# Required environment variabless: +# Required environment variables: # - 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. +# +# Optional environment variables: +# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with +# subversion (default = svn). +# - GIT_SVN_LAYOUT: SVN layout options to override (default --stdlayout) +# - GIT_SVN_AUTHORS: authors-file option (default none) # # Usage: git-repository-from-svn.sh project svn_url git_url @@ -20,9 +24,11 @@ if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_S exit 1 fi +# Set optional variables : ${GIT_SVN_SYNC_BRANCH:="svn"} : ${GIT_SVN_LAYOUT:="--stdlayout"} -: ${GIT_SVN_AUTHORS:="--authors-file=${GIT_SVN_SYNC_BASE}/authors.txt"} +[ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}"} +: ${GIT_HOOK_CMD:="ln -s"} project="${1?No project name provided}" svn_url="${2?No svn url provided}" @@ -42,5 +48,5 @@ git remote add origin ${git_url} || { echo "Could not set up server as remote fr 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}" + ${GIT_HOOK_CMD} "${GIT_SCRIPTS}/sync-client-hooks/always-reject" "${client}/.git/hooks/${hook}" done From 3d2d683a3ceff100074b1a7cb7e4ecc23eead5b4 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:14:04 +0100 Subject: [PATCH 05/23] Make the SVN branch name optional --- git-sync-with-svn.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/git-sync-with-svn.sh b/git-sync-with-svn.sh index 3e2ddac..81c5feb 100755 --- a/git-sync-with-svn.sh +++ b/git-sync-with-svn.sh @@ -19,10 +19,12 @@ # - 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. # - GIT_SVN_SYNC_EMAIL: email to send error reports to # +# Optional environment variables: +# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with +# subversion (default = svn). +# # Usage: git-sync-with-svn.sh project_name destination="${GIT_SVN_SYNC_EMAIL}" From 6e639e31f16443d20e916da6576344273a77dc19 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:15:07 +0100 Subject: [PATCH 06/23] Default SVN branch to svn-sync --- install/git-repository-from-svn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 8286c5d..c899e75 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -13,7 +13,7 @@ # # Optional environment variables: # - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with -# subversion (default = svn). +# subversion (default = svn-sync). # - GIT_SVN_LAYOUT: SVN layout options to override (default --stdlayout) # - GIT_SVN_AUTHORS: authors-file option (default none) # @@ -25,7 +25,7 @@ if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] || [ -z "${GIT_SVN_S fi # Set optional variables -: ${GIT_SVN_SYNC_BRANCH:="svn"} +: ${GIT_SVN_SYNC_BRANCH:="svn-sync"} : ${GIT_SVN_LAYOUT:="--stdlayout"} [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}"} : ${GIT_HOOK_CMD:="ln -s"} From 674c7bae46558599404c4a78a7dceaedaba500aa Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:16:01 +0100 Subject: [PATCH 07/23] Default SVN branch to svn-sync --- git-sync-with-svn.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-sync-with-svn.sh b/git-sync-with-svn.sh index 81c5feb..e2593de 100755 --- a/git-sync-with-svn.sh +++ b/git-sync-with-svn.sh @@ -23,10 +23,13 @@ # # Optional environment variables: # - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with -# subversion (default = svn). +# subversion (default = svn-sync). # # Usage: git-sync-with-svn.sh project_name +# Set optional variables +: ${GIT_SVN_SYNC_BRANCH:="svn-sync"} + destination="${GIT_SVN_SYNC_EMAIL}" project="${1?No project provided}" location="${GIT_SVN_SYNC_BASE}/${project}" From 92c267738340a3254cebdf17a0e4c71936c7eaff Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:38:43 +0100 Subject: [PATCH 08/23] Make SVN branch really optional --- install/git-repository-from-svn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index c899e75..65da619 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -19,8 +19,8 @@ # # Usage: git-repository-from-svn.sh project svn_url git_url -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" +if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] ] ; then + echo "The following variables are required for the synchronization to work: GIT_SCRIPTS GIT_SVN_SYNC_BASE" exit 1 fi From a4ca54f8aa291423f73475948f76e804706a0f4e Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:42:48 +0100 Subject: [PATCH 09/23] Make email report optional And fail if any required variables are not set. --- git-sync-with-svn.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/git-sync-with-svn.sh b/git-sync-with-svn.sh index e2593de..bc7ee24 100755 --- a/git-sync-with-svn.sh +++ b/git-sync-with-svn.sh @@ -19,14 +19,19 @@ # - GIT_SCRIPTS: directory where the git sync scripts are located # - GIT_SVN_SYNC_BASE: directory where the sync repositories are # stored. -# - GIT_SVN_SYNC_EMAIL: email to send error reports to # # Optional environment variables: -# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with +# - GIT_SVN_SYNC_EMAIL: email to send error reports to +# - GIT_SVN_SYNC_BRANCH: name of the branch that is synchronized with # subversion (default = svn-sync). # # Usage: git-sync-with-svn.sh project_name +if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] ] ; then + echo "The following variables are required for the synchronization to work: GIT_SCRIPTS GIT_SVN_SYNC_BASE" + exit 1 +fi + # Set optional variables : ${GIT_SVN_SYNC_BRANCH:="svn-sync"} @@ -44,7 +49,7 @@ cd "$location" report () { echo $1 - sh "${GIT_SCRIPTS}/report-error.sh" "$destination" "$project" "$1" + [ -z "${destination}" ] || sh "${GIT_SCRIPTS}/report-error.sh" "$destination" "$project" "$1" } # Get changes from git repository From 1ed801468686aec00e317fc170414962c3788db3 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:44:36 +0100 Subject: [PATCH 10/23] Fix syntax error in condition --- install/git-repository-from-svn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 65da619..7695752 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -19,7 +19,7 @@ # # Usage: git-repository-from-svn.sh project svn_url git_url -if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] ] ; then +if [ -z "${GIT_SCRIPTS}" ] || [ -z "${GIT_SVN_SYNC_BASE}" ] ; then echo "The following variables are required for the synchronization to work: GIT_SCRIPTS GIT_SVN_SYNC_BASE" exit 1 fi From 22f9e5840e4346ebb2ead5d3dade5d3ca3a7fc98 Mon Sep 17 00:00:00 2001 From: Ben Date: Wed, 14 Dec 2016 22:51:31 +0100 Subject: [PATCH 11/23] Fix typo --- install/git-repository-from-svn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 7695752..95b97e6 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -27,7 +27,7 @@ fi # Set optional variables : ${GIT_SVN_SYNC_BRANCH:="svn-sync"} : ${GIT_SVN_LAYOUT:="--stdlayout"} -[ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}"} +[ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} project="${1?No project name provided}" From ca48abc98426d8c3bd12b99d473485e12f46b7ae Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 15 Dec 2016 17:31:50 +0100 Subject: [PATCH 12/23] Add convertion of tags --- install/git-repository-from-svn.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 95b97e6..55f1fb2 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -44,6 +44,21 @@ fi git svn clone "${GIT_SVN_LAYOUT}" "${GIT_SVN_AUTHORS}" "${svn_url}" "${client}" || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } cd "${client}" + +# Convert SVN tags for Git +git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags \ +| while read BRANCH REF +do + TAG_NAME=${BRANCH#*/} + BODY="$(git log -1 --format=format:%B $REF)" + + echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2 + + git tag -a -m "$BODY" $TAG_NAME $REF^ \ + && git branch -r -d $BRANCH \ + || { echo "Could not convert tag $TAG_NAME" ; exit 1; } + done + 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; } From d560e4e8b643d4834acef44c87f9cc875e46e38e Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 15 Dec 2016 23:45:12 +0100 Subject: [PATCH 13/23] Ignore branch/tag with revision suffix --- install/git-repository-from-svn.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 55f1fb2..a0da59a 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -41,7 +41,8 @@ if [ -d "$client" ] ; then fi # Sync client -git svn clone "${GIT_SVN_LAYOUT}" "${GIT_SVN_AUTHORS}" "${svn_url}" "${client}" || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } +git svn clone "${GIT_SVN_LAYOUT}" "${GIT_SVN_AUTHORS}" "${svn_url}" "${client}" \ + || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } cd "${client}" @@ -54,9 +55,13 @@ do echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2 - git tag -a -m "$BODY" $TAG_NAME $REF^ \ - && git branch -r -d $BRANCH \ + # Only convert tag without revision suffix + [[ $TAG_NAME =~ ^.+@[0-9]+$ ]] \ + || git tag -a -m "$BODY" $TAG_NAME $REF^ \ || { echo "Could not convert tag $TAG_NAME" ; exit 1; } + # Delete branch/tag + git branch -r -d $BRANCH \ + || { echo "Could not delete branch $TAG_NAME" ; exit 1; } done git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; } From f21e0e359c5e750c9b0bc1a29dfeab712337d8eb Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 10:56:03 +0100 Subject: [PATCH 14/23] Try to convert branches as well --- install/git-repository-from-svn.sh | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index a0da59a..199c8ff 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -29,6 +29,7 @@ fi : ${GIT_SVN_LAYOUT:="--stdlayout"} [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} +: ${GIT_SVN_REMOTE:="--prefix "svn"} project="${1?No project name provided}" svn_url="${2?No svn url provided}" @@ -41,27 +42,42 @@ if [ -d "$client" ] ; then fi # Sync client -git svn clone "${GIT_SVN_LAYOUT}" "${GIT_SVN_AUTHORS}" "${svn_url}" "${client}" \ +git svn clone ${GIT_SVN_LAYOUT} ${GIT_SVN_AUTHORS} ${GIT_SVN_REMOTE} "${svn_url}" "${client}" \ || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } cd "${client}" -# Convert SVN tags for Git -git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/tags \ +# Convert SVN tags and branches for remote Git +git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/${GIT_SVN_REMOTE} \ | while read BRANCH REF do - TAG_NAME=${BRANCH#*/} + NAME=${BRANCH#*/} BODY="$(git log -1 --format=format:%B $REF)" - echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$TAG_NAME body=$BODY" >&2 + echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$NAME body=$BODY" >&2 - # Only convert tag without revision suffix - [[ $TAG_NAME =~ ^.+@[0-9]+$ ]] \ - || git tag -a -m "$BODY" $TAG_NAME $REF^ \ - || { echo "Could not convert tag $TAG_NAME" ; exit 1; } + # Ignore branches with revision suffix + # TODO: Implement an ignore regexp option + if [[ $NAME =~ ^.+@[0-9]+$ ]]; then + case $BRANCH in + tags/*) + # Convert to local Git tags + git tag -a -m "$BODY" $NAME $REF^ \ + || { echo "Could not convert tag $NAME" ; exit 1; } + ;; + trunk) + # Preserve the trunk + ;; + *) + # Copy to local Git branch + git branch $NAME $BRANCH \ + || { echo "Could not convert branche $NAME" ; exit 1; } + ;; + esac + fi # Delete branch/tag git branch -r -d $BRANCH \ - || { echo "Could not delete branch $TAG_NAME" ; exit 1; } + || { echo "Could not delete branch $NAME" ; exit 1; } done git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; } From a757ac6babdabb07a96910bc3564e3850087473d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 11:00:45 +0100 Subject: [PATCH 15/23] Fix syntax error --- install/git-repository-from-svn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 199c8ff..276b2ca 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -29,7 +29,7 @@ fi : ${GIT_SVN_LAYOUT:="--stdlayout"} [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} -: ${GIT_SVN_REMOTE:="--prefix "svn"} +: ${GIT_SVN_REMOTE:="--prefix svn"} project="${1?No project name provided}" svn_url="${2?No svn url provided}" @@ -71,7 +71,7 @@ do *) # Copy to local Git branch git branch $NAME $BRANCH \ - || { echo "Could not convert branche $NAME" ; exit 1; } + || { echo "Could not convert branch $NAME" ; exit 1; } ;; esac fi From 8a71c6f67ea02fd6853d416810c818d97eee685b Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 11:01:50 +0100 Subject: [PATCH 16/23] Prefix must have a trailing slash --- install/git-repository-from-svn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 276b2ca..9a02ca9 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -29,7 +29,7 @@ fi : ${GIT_SVN_LAYOUT:="--stdlayout"} [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} -: ${GIT_SVN_REMOTE:="--prefix svn"} +: ${GIT_SVN_REMOTE:="--prefix svn/"} project="${1?No project name provided}" svn_url="${2?No svn url provided}" From 55208621dee6fe2d98cdf66e0acb94a33ce69f21 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 11:21:35 +0100 Subject: [PATCH 17/23] Fix prefix option and preserve trunk --- install/git-repository-from-svn.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 9a02ca9..4a9fa90 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -29,7 +29,7 @@ fi : ${GIT_SVN_LAYOUT:="--stdlayout"} [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} -: ${GIT_SVN_REMOTE:="--prefix svn/"} +: ${GIT_SVN_REMOTE:="svn"} project="${1?No project name provided}" svn_url="${2?No svn url provided}" @@ -42,7 +42,7 @@ if [ -d "$client" ] ; then fi # Sync client -git svn clone ${GIT_SVN_LAYOUT} ${GIT_SVN_AUTHORS} ${GIT_SVN_REMOTE} "${svn_url}" "${client}" \ +git svn clone ${GIT_SVN_LAYOUT} ${GIT_SVN_AUTHORS} --prefix "${GIT_SVN_REMOTE}/" "${svn_url}" "${client}" \ || { echo "Could not clone svn repository at ${svn_url} in ${client}" ; exit 1; } cd "${client}" @@ -54,7 +54,7 @@ do NAME=${BRANCH#*/} BODY="$(git log -1 --format=format:%B $REF)" - echo "ref=$REF parent=$(git rev-parse $REF^) tagname=$NAME body=$BODY" >&2 + echo "ref=$REF parent=$(git rev-parse $REF^) name=$NAME body=$BODY" >&2 # Ignore branches with revision suffix # TODO: Implement an ignore regexp option @@ -75,8 +75,9 @@ do ;; esac fi - # Delete branch/tag - git branch -r -d $BRANCH \ + # Delete all svn branches, but trunk + if [[ $NAME =~ ^.+@[0-9]+$ ]]; then + git branch -r -d $BRANCH \ || { echo "Could not delete branch $NAME" ; exit 1; } done From a0b54311a23b664d83c86d07c0af767d5c3cdb20 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 11:27:13 +0100 Subject: [PATCH 18/23] Print rather than comment steps --- install/git-repository-from-svn.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 4a9fa90..d030d34 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -1,4 +1,4 @@ -# -*- mode: Shell-script-*- + # -*- mode: Shell-script-*- #!/usr/bin/bash # # Author: Mario Fernandez @@ -61,22 +61,22 @@ do if [[ $NAME =~ ^.+@[0-9]+$ ]]; then case $BRANCH in tags/*) - # Convert to local Git tags + echo "Converting tag $NAME as local Git tag..." git tag -a -m "$BODY" $NAME $REF^ \ || { echo "Could not convert tag $NAME" ; exit 1; } ;; trunk) - # Preserve the trunk + echo "Preserving the trunk" ;; *) - # Copy to local Git branch + echo "Copying branch $NAME as local Git branch..." git branch $NAME $BRANCH \ || { echo "Could not convert branch $NAME" ; exit 1; } ;; esac fi # Delete all svn branches, but trunk - if [[ $NAME =~ ^.+@[0-9]+$ ]]; then + if [[ $NAME =~ ^trunk$ ]]; then git branch -r -d $BRANCH \ || { echo "Could not delete branch $NAME" ; exit 1; } done From ddb8b226556a71a02ac29a7decac259f755e8514 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 11:46:15 +0100 Subject: [PATCH 19/23] Fix syntax error --- install/git-repository-from-svn.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index d030d34..e28147f 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -79,7 +79,8 @@ do if [[ $NAME =~ ^trunk$ ]]; then git branch -r -d $BRANCH \ || { echo "Could not delete branch $NAME" ; exit 1; } - done + fi +done 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; } From e142323f19fc20ad3384be9843316af64ed6ed7d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 12:03:27 +0100 Subject: [PATCH 20/23] Fix condition to convert branches --- install/git-repository-from-svn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index e28147f..136e357 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -58,7 +58,7 @@ do # Ignore branches with revision suffix # TODO: Implement an ignore regexp option - if [[ $NAME =~ ^.+@[0-9]+$ ]]; then + if ! [[ $NAME =~ ^.+@[0-9]+$ ]]; then case $BRANCH in tags/*) echo "Converting tag $NAME as local Git tag..." From 676d85ed9734fb01ccc2db5fb9517c666a615f8c Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 12:09:23 +0100 Subject: [PATCH 21/23] Deal with prefix when converting --- install/git-repository-from-svn.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 136e357..1a7f78a 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -51,7 +51,7 @@ cd "${client}" git for-each-ref --format="%(refname:short) %(objectname)" refs/remotes/${GIT_SVN_REMOTE} \ | while read BRANCH REF do - NAME=${BRANCH#*/} + NAME=${BRANCH##*/} BODY="$(git log -1 --format=format:%B $REF)" echo "ref=$REF parent=$(git rev-parse $REF^) name=$NAME body=$BODY" >&2 @@ -59,7 +59,7 @@ do # Ignore branches with revision suffix # TODO: Implement an ignore regexp option if ! [[ $NAME =~ ^.+@[0-9]+$ ]]; then - case $BRANCH in + case ${BRANCH#*/} in tags/*) echo "Converting tag $NAME as local Git tag..." git tag -a -m "$BODY" $NAME $REF^ \ From 6a8ebef7753aa379a30efb4cf886cec2a95be2b4 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 12:41:12 +0100 Subject: [PATCH 22/23] Add option to push tags and branches --- install/git-repository-from-svn.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index 1a7f78a..c49093d 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -30,6 +30,7 @@ fi [ -z "${GIT_SVN_AUTHORS}" ] || GIT_SVN_AUTHORS="--authors-file=${GIT_SVN_AUTHORS}" : ${GIT_HOOK_CMD:="ln -s"} : ${GIT_SVN_REMOTE:="svn"} +: ${GIT_PUSH:=1} project="${1?No project name provided}" svn_url="${2?No svn url provided}" @@ -82,7 +83,13 @@ do fi done +# Add the remote Git repo and push if requested git remote add origin ${git_url} || { echo "Could not set up server as remote from sync" ; exit 1; } +if [ ${GIT_PUSH} -eq 1 ]; then + git push --all + git push --tags +fi + git branch ${GIT_SVN_SYNC_BRANCH} || { echo "Could not create svn sync branch" ; exit 1; } for hook in pre-receive pre-commit ; do From fbb9f10e89dc7fbd821212dde5d06df973076a39 Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 16 Dec 2016 13:52:16 +0100 Subject: [PATCH 23/23] Make the deletion effective --- install/git-repository-from-svn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/install/git-repository-from-svn.sh b/install/git-repository-from-svn.sh index c49093d..0db73b8 100755 --- a/install/git-repository-from-svn.sh +++ b/install/git-repository-from-svn.sh @@ -77,7 +77,7 @@ do esac fi # Delete all svn branches, but trunk - if [[ $NAME =~ ^trunk$ ]]; then + if ! [[ $NAME =~ ^trunk$ ]]; then git branch -r -d $BRANCH \ || { echo "Could not delete branch $NAME" ; exit 1; } fi