Skip to content

Instantly share code, notes, and snippets.

@calebpower
Last active December 23, 2024 00:50
Show Gist options
  • Select an option

  • Save calebpower/1cb746df582d75d60af28a38dd0d1730 to your computer and use it in GitHub Desktop.

Select an option

Save calebpower/1cb746df582d75d60af28a38dd0d1730 to your computer and use it in GitHub Desktop.
Port SVN tags over to GIT
#!/usr/local/bin/bash
# Assumes you've already got a SVN server up and running.
# Also assumes that you've converted your commits over already.
if [ "$#" -ne 3 ]; then
printf 'Usage: %s <svn_url> <svn_repo> <git_dir>\n' "$0"
printf 'Example: %s svn://127.0.0.1/freshports-1 periodics /freshports/periodics\n' "$0"
exit 1
fi
SVN_URL="$1"
SVN_REPO="$2"
GIT_LOCAL="$3"
cd "$GIT_LOCAL"
svn_tags=($(svn list "${SVN_URL}/${SVN_REPO}/tags" | sed -e 's/\///g'))
for svn_tag in ${svn_tags[@]}; do
svn_rev=$(svn info "${SVN_URL}/${SVN_REPO}/tags/${svn_tag}" | grep -E '^Last Changed Rev:' | cut -d' ' -f4)
svn_log="$(svn log -r $svn_rev "${SVN_URL}" --xml)"
author=$(echo "${svn_log}" | htmlq --text 'author')
svn_date_raw="$(echo "${svn_log}" | htmlq --text 'date')"
svn_date="$(echo "${svn_date_raw}" | sed -E 's/T/ /; s/\..*Z$//') +0000"
svn_msg="$(echo "${svn_log}" | htmlq --text 'msg' | sed "s/^'//;s/'\$//")"
git_log="$(git log --until="${svn_date}" --max-count=1 --author-date-order --pretty=format:"%h %ad %s" --date=iso)"
git_commit=$(echo $git_log | cut -d' ' -f1)
git_date=$(echo $git_log | cut -d' ' -f2,3,4)
git_msg=$(echo $git_log | cut -d' ' -f5-)
printf -- '--------------------------\n'
printf 'SVN tag: %s; rev: %s; author: %s; timestamp: %s\n' \
"${svn_tag}" "${svn_rev}" "${author}" "${svn_date}"
printf 'SVN message: %s\n' "${svn_msg}"
printf 'GIT commit: %s; timestamp: %s\n' "${git_commit}" "${git_date}"
printf 'GIT message: %s\n' "${git_msg}"
if [ "" == "${svn_msg}" ]; then
GIT_COMMITTER_DATE="${svn_date_raw}" git tag $svn_tag $git_commit
else
GIT_COMMITTER_DATE="${svn_date_raw}" git tag -a $svn_tag $git_commit -m "${svn_msg}"
fi
# You should review the tags and then `git push --tags` manually.
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment