Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Reads patterns from the .svnignore file in RAILS_ROOT and ignores them
namespace :svn do
desc 'Reads patterns from the .svnignore file in RAILS_ROOT and ignores them'
task :ignore => :environment do
# Set the svnignore filename and define the absolute path to that file
#
svnignore_path = File.join(RAILS_ROOT, '.svnignore')
# Ensure the svnignore file exists
#
raise "File #{svnignore_path} does not exist!" unless File.exists?(svnignore_path)
# Stores the parsed ignore patters
#
ignores = Hash.new { |hash, key| hash[key] = [] }
# Read the patterns from the svn ignore file
#
patterns = File.read(svnignore_path).split("\n")
patterns.each do |pattern|
# Figure out paths
#
path = File.join RAILS_ROOT, pattern
parent = File.dirname(path)
relative_path = parent == RAILS_ROOT ? '.' : File.join(parent.gsub(File.join(RAILS_ROOT, ''), ''), '')
# Check for ** in path (recursive ignore)
#
if relative_path =~ /\*\*\//
relative_path.gsub!(/\*\*\/.*$/, '')
relative_path = '.' if relative_path.blank?
recursive = '-R '
else
recursive = ''
end
ignores[relative_path] << { :pattern => File.basename(pattern), :recursive => recursive }
end
# Ignore the patterns
#
ignores.sort.each do |(relative_path, patterns)|
if patterns.length == 1
options = patterns.first[:recursive]
pattern = "'#{patterns.first[:pattern].gsub(/'/, "\\\\'")}'"
else
options = '-F '
# Create a temporary file to store a newline separated list of files to ignore for this relative path
#
temp_file = Tempfile.new('svn-ignore-', RAILS_ROOT)
temp_file.print patterns.map { |configuration| configuration[:pattern] }.join("\n")
temp_file.flush
pattern = File.basename(temp_file.path)
end
command = "svn propset svn:ignore #{options}#{pattern} #{relative_path}"
# puts command
system command
end
end
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.