Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Importing script.

  • Loading branch information...
commit d2debf709fb9700b508c0b0515aa5fe6892d27d5 1 parent 2941778
Guilherme Chapiewski authored

Showing 1 changed file with 67 additions and 0 deletions. Show diff stats Hide diff stats

  1. +67 0 git2svn.sh
67 git2svn.sh
... ... @@ -0,0 +1,67 @@
  1 +#!/bin/bash
  2 +BASE_DIR=`pwd`
  3 +GIT_DIR="/Users/gc/Temp/git_repo"
  4 +SVN_DIR="/Users/gc/Temp/svn_repo"
  5 +
  6 +# The SVN_AUTH variable can be used in case you need credentials to commit
  7 +#SVN_AUTH="--username guilherme.chapiewski@gmail.com --password XPTO"
  8 +SVN_AUTH=""
  9 +
  10 +function svn_checkin {
  11 + echo '... adding files'
  12 + for file in `svn st ${SVN_DIR} | awk -F" " '{print $1 "|" $2}'`; do
  13 + fstatus=`echo $file | cut -d"|" -f1`
  14 + fname=`echo $file | cut -d"|" -f2`
  15 +
  16 + if [ "$fstatus" == "?" ]; then
  17 + if [[ "$fname" == *@* ]]; then
  18 + svn add $fname@;
  19 + else
  20 + svn add $fname;
  21 + fi
  22 + fi
  23 + if [ "$fstatus" == "!" ]; then
  24 + if [[ "$fname" == *@* ]]; then
  25 + svn rm $fname@;
  26 + else
  27 + svn rm $fname;
  28 + fi
  29 + fi
  30 + if [ "$fstatus" == "~" ]; then
  31 + rm -rf $fname;
  32 + svn up $fname;
  33 + fi
  34 + done
  35 + echo '... finished adding files'
  36 +}
  37 +
  38 +function svn_commit {
  39 + echo "... committing -> [$author]: $msg";
  40 + cd $SVN_DIR && svn $SVN_AUTH commit -m "[$author]: $msg" && cd $BASE_DIR;
  41 + echo '... committed!'
  42 +}
  43 +
  44 +for commit in `cd $GIT_DIR && git rev-list --all --reverse && cd $BASE_DIR`; do
  45 + echo "Committing $commit...";
  46 + author=`cd ${GIT_DIR} && git log -n 1 --pretty=format:%an ${commit} && cd ${BASE_DIR}`;
  47 + msg=`cd ${GIT_DIR} && git log -n 1 --pretty=format:%s ${commit} && cd ${BASE_DIR}`;
  48 +
  49 + # Checkout the current commit on git
  50 + echo '... checking out commit on Git'
  51 + cd $GIT_DIR && git checkout $commit && cd $BASE_DIR;
  52 +
  53 + # Delete everything from SVN and copy new files from Git
  54 + echo '... copying files'
  55 + rm -rf $SVN_DIR/*;
  56 + cp -prf $GIT_DIR/* $SVN_DIR/;
  57 +
  58 + # Remove Git specific files from SVN
  59 + for ignorefile in `find ${SVN_DIR} | grep .git | grep .gitignore`;
  60 + do
  61 + rm -rf $ignorefile;
  62 + done
  63 +
  64 + # Add new files to SVN and commit
  65 + svn_checkin && svn_commit;
  66 +done
  67 +

1 comment on commit d2debf7

Guilherme Chapiewski

Don't use this unless you have a very good reason, like I did. And as I said in the docs, don't ask me why :)

Please sign in to comment.
Something went wrong with that request. Please try again.