Skip to content

Instantly share code, notes, and snippets.

@wtaysom
Created December 3, 2011 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtaysom/1427232 to your computer and use it in GitHub Desktop.
Save wtaysom/1427232 to your computer and use it in GitHub Desktop.
SVN ignore is a pain. This script soothes it.
#!/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