Errors in dumping a remote Git based SVN repository over HTTP Errors in dumping a remote Git based SVN repository over HTTP bash bash

Errors in dumping a remote Git based SVN repository over HTTP


@SimonSobisch

Per Simons request, here is the scripts that I ended up writing to move Subversion into GH

#!/usr/local/env bash# Converter for GitHub -> Subversion Repositories# CPR : Jd Daniel :: Ehime-ken# MOD : 2013-03-09 @ 16:26:53; 2017-01-31 @ 13:36:15 Simon Sobisch# VER : Version 1c# the Github SVN url to clone fromURL={THE_SVN_URL} # https://github.com/user/repo/# the SVN url to clone toREPO={THE_REPO_ROOT} in # svn+ssh://user@domain.com/api/svn_name# the SVN structureSVNTRUNK=${SVN_TRUNK-trunk}SVNTAGS=${SVN_TAGS-tags}SVNBRANCHES=${SVN_BRANCHES-branches}# use the trunk, branch, etc... I'm using the trunkSVN="${REPO}/$SVNTRUNK"clear || cls;                  # set -x #debug## if you want to burn and rebuild your repo, uncomment below##echo "Burning Repo..."#svn rm    $REPO/{$SVNTRUNK,$SVNTAGS,$SVNBRANCHES} -m "Burning..."#echo "Rebuilding Repo...."#svn mkdir $REPO/{$SVNTRUNK,$SVNTAGS,$SVNBRANCHES} -m "Rebuilding..."# cleanupfind -maxdepth 1 -type d ! -name '.*' |xargs rm -rf; # tmp# dirsSVN_FOLDER=`pwd`"/svn"GIT_FOLDER=`pwd`"/git"# revsENDREV=`svn info $URL |grep Revision: |awk '{print $2}'`CURREV=1  mkdir -p $SVN_FOLDER $GIT_FOLDERecho -e "\nLinking SVN repo\n"  cd $SVN_FOLDER  svn co $SVN .echo -e "\nDownloading GIT repo\n"  cd $GIT_FOLDER  git svn init -s $URL \  -T $SVNTRUNK \  -t $SVNTAGS \  -b $SVNBRANCHES \  --prefix=svn/  # Set authors so we get prettier authors  if [ -f "../authors" ]; then     git config svn.authorsfile ../authors  fi  echo -e "\nFound ${ENDREV} revisions\n"  for (( REVISION=$CURREV; REVISION<$ENDREV+1; REVISION++ ))  do    cd $GIT_FOLDER    echo -e "\n---> FETCHING: ${REVISION}\n"    git svn fetch -r$REVISION;                echo -e "\n"    git rebase `git svn find-rev r$REVISION`; echo -e "\n"    # STATUS: git log -p -1 `git svn find-rev r19` --pretty=format: --name-only --diff-filter=A | sort -u    ADD=$(git log -p -1 `git svn find-rev r$REVISION` --pretty=format: --name-only --diff-filter=A |awk '{printf "%s ", $1}')    MOD=$(git log -p -1 `git svn find-rev r$REVISION` --pretty=format: --name-only --diff-filter=M |awk '{printf "%s ", $1}')    DEL=$(git log -p -1 `git svn find-rev r$REVISION` --pretty=format: --name-only --diff-filter=D |awk '{printf "%s ", $1}')      # copy new files      for i in $ADD      do         cp --parents $i $SVN_FOLDER/      done      # copy modified files      for i in $MOD      do         cp --parents $i $SVN_FOLDER/      done    # set opts for SVN logging    HASH=$(git log -1 --pretty=format:'Hash: %h <%H>')    AUTHOR='Jd Daniel <dodomeki@gmail.com>'  # or $(git log -1 --pretty="%cn <%cE>")    TMPDATE=$(git log -1 --pretty=%ad --date=iso8601)    DATE=$(date --date "$TMPDATE" -u +"%Y-%m-%dT%H:%M:%S.%N" |sed 's/.....$/Z/g')    LOGMSG=$(git log -1 --pretty=%s)    # move to svn    cd $SVN_FOLDER    # burn file if it exists....    if [ "$DEL" != "" ]; then      for i in $DEL      do         test -f $i && svn --force rm $i      done    fi    # first round of additions....    [ -z "$ADD" ] || svn --force add $ADD    [ -z "$MOD" ] || svn --force add $MOD    # try 2 for adding in case we missed ? files    ADDTRY=$(svn st . |grep "^?" |awk '{print $2}')    [ -z "$ADDTRY" ] || svn --force add $ADDTRY    # do commit    svn ci -m "$LOGMSG"$'\n\n'"$HASH"    # servers pre-revprop-change    #  cp hooks/pre-revprop-change.tmpl pre-revprop-change; chmod +x pre-revprop-change    #  if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:author" ]; then exit 0; fi    #  if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:date" ]; then exit 0; fi    #  echo "Changing revision properties other than svn:log, svn:author and svn:date is prohibited" >&2    # change this commits author and date    svn propset --revprop -r HEAD svn:author "$AUTHOR"    svn propset --revprop -r HEAD svn:date   "$DATE"  doneexit

Anyway, git-svn supports this really well, with just a slight variation on the usual git svn clone.

Instead of the standard project/trunk|branches|tags we use a slightly different parent/trunk|branches|tags/projectso you’ll see I specify the -T/-t/-b flags.

git svn init

Here is what I do, from the existing local git repo:

# Create the project directory in subversion$ /usr/bin/svn mkdir  https://example.com/svn/parent/trunk/project  -m "Make project directory."Committed revision 200.# Initialize git-svn, doesn't fetch anything yet$ git svn init https://example.com/svn/  -T parent/trunk/project  -t parent/tags/project  -b parent/branches/project  --prefix=svn/# Set authors so we get prettier authors$ git config svn.authorsfile ../authors# Now pull down the svn commits$ git svn fetchW: Ignoring error from SVN, ...W: Do not be alarmed at the above message git-svn ...This may take a while on large repositoriesr200 = (guid) (refs/remotes/svn/trunk)# We should now see our svn trunk setup under our svn remote$ git branch -av* master            c3a7161 The latest git commit.  remotes/svn/trunk 3b7fed6 Make project directory.# Now we want to take all of our local commits and # rebase them on top of the new svn/trunk$ git rebase svn/trunkFirst, rewinding head to replay your work on top of it...Applying: First git commitApplying: The latest git commit# Now we should see our local commits applied# on top of svn/trunk$ git lg* 52b7977 (HEAD, master) The latest git commit* a34e162 First git commit* 3b7fed6 (svn/trunk) Make project directory.# Everything is cool, push it back to svn$ git svn dcommitCommitting to https://example.com/svn/parent/trunk/project...–prefix=svn

One flag I especially like lately, which you can also use with git svn clone, is --prefix=svn/.

This will prefix all of your tracking branches of the remote Subversion branches, tags, and trunk with svn/, making it look a whole lot like the usual origin/ idiom used by regular git remotes.

With the tracking branches having a prefix, you can also use them as local branch names, e.g.:

# Name your copy of svn/trunk "trunk" instead of "master"$ git checkout -b trunk masterSwitched to a new branch 'trunk'$ git branch -d masterDeleted branch master (was 33c3136).$ git branch -av* trunk             33c3136 Latest svn commit* remotes/svn/trunk 33c3136 Latest svn commit

Then if you have other branches you want to track:

$ git checkout -b featurea svn/featurea