Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Sync an svn repo to git. A simple script that can be run from a cron job.

View svn-to-git.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
require 'Time'
require 'Nokogiri'
#
# svn-to-git
#
# Sync an svn repo to git.
#
# Checks for svn updates. If there are none, does
# nothing. Otherwise, commits & pushes the latest
# changes into git with an appropriate commit message.
#
def commit_and_push_to_git_with(log_messages)
commit_msg = log_messages.join("\n")
system 'git', 'add', '-A'
system 'git', 'commit', '-m', commit_msg
system 'git', 'push'
end
##### Execution starts here #####
# Get the git cut-off date
last_git_commit = Time.parse(`git log -1 --format="%ci"`)
# Get new svn log messages
messages = []
`svn update`
svn_log = Nokogiri::XML(`svn log --xml`)
svn_log.xpath('//logentry').each { |entry|
entry_date = Time.parse(entry.xpath('date').inner_text)
if entry_date > last_git_commit
messages << "Revision #{entry['revision']}: #{entry.xpath('msg').inner_text}"
end
}
# Send to git if there are new updates
unless messages.empty?
puts "Committing and pushing #{messages.size} new svn updates:"
messages.each { |m| puts " #{m}" }
commit_and_push_to_git_with(messages)
else
puts "No new svn updates"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.