Created
July 10, 2014 13:20
-
-
Save digitalmoksha/ad63d491d3b77abebafc to your computer and use it in GitHub Desktop.
Add / Remove / Commit files to subversion (svn) automatically
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
#!/usr/bin/env ruby | |
#------------------------------------------------------------------------------ | |
#------------------------------------------------------------------------------ | |
def usage | |
puts "" | |
puts "usage: #{File.basename( __FILE__ )} [-t] PATH" | |
puts "" | |
puts "Automatically commits the changes of svn working copy located in PATH." | |
puts "The new files are automatically added and the files that have been removed" | |
puts "are removed." | |
puts "" | |
puts "-t test mode - will not commit anything" | |
puts "" | |
puts "-- Converted to Ruby from original shell script by Gael Varoquaux" | |
exit(1) | |
end | |
#------------------------------- Process the options ------------------------- | |
if ARGV.length == 1 | |
workingdir = ARGV[0] | |
testmode = false | |
elsif ARGV.length == 2 && ARGV[0] == '-t' | |
workingdir = ARGV[1] | |
testmode = true | |
else | |
usage | |
end | |
if !Dir.exists?(workingdir) | |
puts "\n==> #{workingdir} is not an accessible path" | |
usage | |
end | |
#------------------------------- Find out what has changed ------------------- | |
Dir.chdir workingdir | |
svnstatus = `svn status #{workingdir}` | |
added = svnstatus.scan(/^[?] *(.*)/).flatten | |
removed = svnstatus.scan(/^[!] *(.*)/).flatten | |
puts "\n--- Current status" | |
puts svnstatus | |
unless added.empty? | |
puts "\n--- Adding to repository" | |
puts added.join("\n") | |
unless testmode | |
added.each do |add| | |
add << '@' if add.include?('@') # must add an @ to end of files like test@2x.jpg | |
`svn add #{add}` | |
end | |
end | |
end | |
unless removed.empty? | |
puts "\n--- Removing from repository" | |
puts removed.join("\n") | |
unless testmode | |
removed.each do |remove| | |
remove << '@' if remove.include?('@') # must add an @ to end of files like test@2x.jpg | |
`svn remove #{remove}` | |
end | |
end | |
end | |
#--- use system() so output is sent to stdout | |
puts "\n--- Committing..." | |
system('svn commit -m "autocommit"') unless testmode |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment