Created
December 3, 2011 14:16
-
-
Save wtaysom/1427232 to your computer and use it in GitHub Desktop.
SVN ignore is a pain. This script soothes it.
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 -wKU | |
## A response to <http://jacobian.org/writing/svn-usability/>. | |
USAGE = <<USAGE | |
usage: svnignore [--stop] [FILE...] | |
Tells SVN to ignore each FILE. | |
Recurses into directories as needed. | |
--stop stops SVN from ignoring each FILE. | |
USAGE | |
if ARGV.empty? | |
puts USAGE | |
exit 1 | |
end | |
if STOP_IGNORING = ARGV.first == "--stop" | |
ARGV.shift | |
end | |
TMP_FILE = ".svnignore-temporary-file--feel-free-to-rm" | |
files_grouped_by_directory = ARGV.group_by{|file| File.dirname(file)} | |
files_grouped_by_directory.each do |directory, files| | |
unless Dir.exists?(directory) | |
$stderr.puts "svnignore: #{directory}: No such directory" | |
next | |
end | |
files = files.map{|file| File.basename(file)} | |
already_ignoring = `svn propget svn:ignore #{directory}`.split | |
ignore = if STOP_IGNORING | |
already_ignoring - files | |
else | |
(already_ignoring + files).uniq | |
end | |
begin | |
File.open(TMP_FILE, 'w'){|io| ignore.each{|f| io.puts(f)}} | |
puts `svn propset svn:ignore --file #{TMP_FILE} #{directory}` | |
ensure | |
File.delete(TMP_FILE) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment