Created
November 18, 2021 20:12
-
-
Save truongvinht/3d85628517b56b716ff683ea02bc9ebe to your computer and use it in GitHub Desktop.
Bash Script for svn to git migration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script checkout SVN as git repository | |
#constants | |
SVN_TMP_FILE=svnlog.txt | |
BRANCH_FILE=branch.txt | |
LATEST_ANNUAL="" | |
#variables | |
revision="" | |
project="" | |
#ARGUMENTS: SVN-URL BRANCHES | |
SVN_URL=$1 | |
FILTER_YEAR=$2 | |
if [[ $1 == "" ]]; then | |
echo "Missing SVN-URL: svnmigration.sh SVN-URL" | |
exit 0 | |
fi | |
#get folder / project name | |
delimiter=/ | |
s=$SVN_URL$delimiter | |
project="" | |
while [[ $s ]]; do | |
project=( "${s%%"$delimiter"*}" ); | |
s=${s#*"$delimiter"}; | |
done; | |
echo "###### ${project} #####" | |
echo "Checking for latest revision in ${SVN_URL}..." | |
svn log $SVN_URL > $SVN_TMP_FILE | |
while read row; do | |
# filter only commits (commit/user/date/details) | |
if [[ $row == *"|"* ]]; then | |
# split REV | USER | DATE | LINE | |
# echo "${row}" | |
IFS="|" read -ra list <<< "$row" | |
#revision | |
svn_revision="${list[0]}" | |
#date | |
commit_date="${list[2]}" | |
year=${commit_date:0:5} | |
#echo "${svn_revision} - ${year}" | |
if [[ "$year" -ge "$FILTER_YEAR" ]]; then | |
#echo "${year} - ${FILTER_YEAR}" | |
revision="${svn_revision}" | |
fi | |
fi | |
done < $SVN_TMP_FILE | |
#remote tmp file | |
rm -f $SVN_TMP_FILE | |
#trim spaces | |
revision="$(echo -e "${revision}" | tr -d '[:space:]')" | |
echo "Latest SVN revision: ${revision} (${FILTER_YEAR})" | |
#clone svn repository | |
echo "Clone ${SVN_URL}..." | |
clone_argument="-${revision}:HEAD" | |
git svn clone -s $clone_argument $SVN_URL | |
echo "######################################" | |
echo "SVN preparation finished" | |
echo "Next step:" | |
echo "git remote add origin URL\ngit push -u origin --all\ngit push origin --tags" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment