Skip to content

Instantly share code, notes, and snippets.

@born2snipe
Created November 12, 2010 02:54
Show Gist options
  • Save born2snipe/673660 to your computer and use it in GitHub Desktop.
Save born2snipe/673660 to your computer and use it in GitHub Desktop.
convert a SVN revision number to a Git hash
commit_hash_pattern="[0-9a-z]{30,40}"
svn_revision_pattern="/.+@([0-9]+)"
git_log="$(git log 2> /dev/null)"
current_git_hash=""
# loop over all given SVN revision numbers
for svnRevisionNumber in "$@"
do
for line in $git_log
do
# see if the current line is a git commit hash
if [[ ${line}} =~ ${commit_hash_pattern} ]]; then
current_git_hash=$line
fi
# see if the current line is the SVN url with revision number
if [[ ${line}} =~ ${svn_revision_pattern} ]]; then
svn_revision=${BASH_REMATCH[1]}
if [[ "$svn_revision" = "$svnRevisionNumber" ]]; then
echo "SVN: $svnRevisionNumber Git: $current_git_hash"
break
fi
fi
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment