pol-svn_ignore_rails 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ History.rdoc
2
+ License.txt
3
+ README.rdoc
4
+ Upgrade.rdoc
@@ -0,0 +1,6 @@
1
+ === Version 1.0.2 ===
2
+ * fixed a typo in the deploy.rb removal commit message
3
+ * added an automatic svn commit message for the database.yml removal
4
+
5
+ === Version 1.0 ===
6
+ * initial release
@@ -0,0 +1,24 @@
1
+ (The MIT License)
2
+
3
+ ====================================================================
4
+ ==== Svn_Ignore_Rails
5
+ Copyright (c) 2009 Pol Llovet, Montana State University
6
+ ====================================================================
7
+
8
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
9
+ this software and associated documentation files (the "Software"), to deal in
10
+ the Software without restriction, including without limitation the rights to
11
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
12
+ of the Software, and to permit persons to whom the Software is furnished to do
13
+ so, subject to the following conditions:
14
+
15
+ The above copyright notice and this permission notice shall be included in all
16
+ copies or substantial portions of the Software.
17
+
18
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
+ SOFTWARE.
@@ -0,0 +1,13 @@
1
+ .document
2
+ generators/svn_ignore
3
+ generators/svn_ignore/CHANGES
4
+ generators/svn_ignore/svn_ignore_generator.rb
5
+ generators/svn_ignore/templates/svn_ignore.rake
6
+ History.rdoc
7
+ init.rb
8
+ License.txt
9
+ Manifest.txt
10
+ Rakefile
11
+ README.rdoc
12
+ TODO.txt
13
+ Upgrade.rdoc
@@ -0,0 +1,42 @@
1
+ = SVN_Ignore_Rails Rake Task
2
+
3
+ == DESCRIPTION:
4
+
5
+ Sensible SVN file removal/ignore from a Rails app
6
+
7
+ svn_ignore_rails is a simple rails generator that puts a rake task in your app
8
+ that allows you to remove and ignore files from your rails app that shouldn't
9
+ be in your repository.
10
+
11
+ == FEATURES:
12
+
13
+ * Doesn't delete any files, just removes them from the repository (uses the --keep-local option)
14
+ * Doesn't delete any directories, but recurses into them, ignoring files if appropriate
15
+ * Commits along the way so you can revert back to a particular step if necessary
16
+ * Has command-line options for verbose and simulation
17
+ * Do a 'rake -T svn' to see what all it does
18
+
19
+ == INSTALL:
20
+
21
+ * Run (sudo if necessary): gem install git://github.com/pol-svn_ignore_rails.git
22
+ * Run (in your rails app): script/generate svn_ignore_rails
23
+
24
+ == USAGE:
25
+
26
+ All operations should be performed within the the root of the rails app.
27
+ It is expected that the app is entirely checked into SVN, at the very least, the
28
+ repository is set. Running 'svn update' from the root of the app should work.
29
+
30
+ Run a simulation:
31
+ $ rake svn:setup OPTIONS='simulation'
32
+
33
+ Run a verbose simulation:
34
+ $ rake svn:setup OPTIONS='simulation,verbose'
35
+
36
+ Run just the config/ removals
37
+ $ rake svn:remove_config
38
+
39
+ Run the whole set of tasks
40
+ $ rake svn:setup
41
+
42
+ See the rake file for more information.
File without changes
@@ -0,0 +1,3 @@
1
+ * Make the default behavior sensible when the app has not yet been committed to svn
2
+ * Tests
3
+ * Ask for svn repo credentials initially so the tasks don't spam for them
@@ -0,0 +1 @@
1
+ = This is Version 1.0
@@ -0,0 +1,28 @@
1
+ require 'rbconfig'
2
+
3
+ # This generator adds a rake task to a Rails project for svn file ignores
4
+ class SvnIgnoreRailsGenerator < Rails::Generator::Base
5
+ DEFAULT_SHEBANG = File.join(Config::CONFIG['bindir'],
6
+ Config::CONFIG['ruby_install_name'])
7
+
8
+ def initialize(runtime_args, runtime_options = {})
9
+ Dir.mkdir('lib/tasks') unless File.directory?('lib/tasks')
10
+ super
11
+ end
12
+
13
+ def manifest
14
+ record do |m|
15
+ script_options = { :chmod => 0755, :shebang => options[:shebang] == DEFAULT_SHEBANG ? nil : options[:shebang] }
16
+
17
+ m.directory 'lib/tasks'
18
+ m.template 'svn_ignore.rake', 'lib/tasks/svn_ignore.rake'
19
+ end
20
+ end
21
+
22
+ protected
23
+
24
+ def banner
25
+ "Usage: #{$0} svn_ignore_rails"
26
+ end
27
+
28
+ end
@@ -0,0 +1,196 @@
1
+ # This file is copied to ~/lib/tasks when you run 'ruby script/generate svn_ignore_rails'
2
+ # from the project root directory.
3
+ options = {}
4
+ ENV['OPTIONS'].split(',').each { |opt| options[opt.downcase.to_sym] = true } if ENV['OPTIONS']
5
+
6
+ namespace :svn do
7
+ puts "Options: " + options.keys.join(',') unless options.empty?
8
+ abort(help_text) if options[:help]
9
+
10
+ desc "Remove and ignore config/initializers/site_keys.rb"
11
+ task :remove_site_keys_rb do
12
+ tasks = TaskQueue.new
13
+ tasks.concat remove_file_with_example(File.join('config','initializers'),'site_keys.rb')
14
+ tasks.add_msg "Committing..."
15
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore config/initializers/site_keys.rb'"
16
+ tasks.run(options)
17
+ end
18
+
19
+ desc "Remove and ignore config/database.yml"
20
+ task :remove_database_yml do
21
+ tasks = TaskQueue.new
22
+ tasks.concat remove_file_with_example('config','database.yml')
23
+ tasks.add_msg "Committing..."
24
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore config/database.yml'"
25
+ tasks.run(options)
26
+ end
27
+
28
+ desc "Remove and ignore config/deploy.rb"
29
+ task :remove_deploy_rb do
30
+ tasks = TaskQueue.new
31
+ tasks.concat remove_file_with_example('config','deploy.rb')
32
+ tasks.add_msg "Committing..."
33
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore config/deploy.rb'"
34
+ tasks.run(options)
35
+ end
36
+
37
+ desc "Remove and ignore files from tmp/ (recursively, keep dirs)"
38
+ task :remove_tmp do
39
+ tasks = TaskQueue.new
40
+ tasks.concat recursive_delete_and_ignore(File.join(RAILS_ROOT,'tmp'))
41
+ tasks.add_msg "Committing..."
42
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore files from tmp/ (recursively, keep dirs)'"
43
+ tasks.run(options)
44
+ end
45
+
46
+ desc "Remove and ignore files from log/ (recursively, keep dirs)"
47
+ task :remove_log do
48
+ tasks = TaskQueue.new
49
+ tasks.concat recursive_delete_and_ignore(File.join(RAILS_ROOT,'log'))
50
+ tasks.add_msg "Committing..."
51
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore files from log/ (recursively, keep dirs)'"
52
+ tasks.run(options)
53
+ end
54
+
55
+ desc "Remove and ignore db/*.sqlite3"
56
+ task :remove_sqlite3_database do
57
+ tasks = TaskQueue.new
58
+ tasks.concat remove_glob('db','*.sqlite3')
59
+ tasks.add_msg "Committing..."
60
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore db/*.sqlite3'"
61
+ tasks.run(options)
62
+ end
63
+
64
+ desc "Remove and ignore .git* (just in the root of the app)"
65
+ task :remove_git do
66
+ tasks = TaskQueue.new
67
+ tasks.concat remove_glob('.','.git*')
68
+ tasks.add_msg "Committing..."
69
+ tasks.add_cmd "svn commit #{RAILS_ROOT} -m 'Remove and ignore .git* (just in the root of the app)'"
70
+ tasks.run(options)
71
+ end
72
+
73
+ desc "Run each of the config file removal tasks"
74
+ task :remove_config => ['remove_site_keys_rb','remove_database_yml','remove_deploy_rb']
75
+
76
+ desc "Run all of the svn remove and ignore rake tasks"
77
+ task :setup => ['remove_config','remove_tmp','remove_log','remove_sqlite3_database','remove_git']
78
+
79
+ task :default => ['setup']
80
+
81
+ end
82
+
83
+ class TaskQueue < Array
84
+ class Task < String
85
+ def message
86
+ @command = false
87
+ @message = true
88
+ self
89
+ end
90
+
91
+ def command
92
+ @message = false
93
+ @command = true
94
+ self
95
+ end
96
+
97
+ def message?
98
+ @message
99
+ end
100
+
101
+ def command?
102
+ @command
103
+ end
104
+
105
+ def to_vs
106
+ (command? ? "Command: " : "Message: ") + self.to_s
107
+ end
108
+ end
109
+
110
+ def add_msg(task)
111
+ self << Task.new(task).message
112
+ end
113
+
114
+ def add_cmd(task)
115
+ self << Task.new(task).command
116
+ end
117
+
118
+ def run(opt = nil)
119
+ self.each do |t|
120
+ if t.command?
121
+ puts t.to_vs if opt[:verbose]
122
+ system(t) unless opt[:simulate]
123
+ else
124
+ puts opt[:verbose] ? t.to_vs : t.to_s
125
+ end
126
+ end
127
+ end
128
+ end
129
+
130
+ # recursively delete then ignore files
131
+ def recursive_delete_and_ignore(dir)
132
+ tasks = TaskQueue.new
133
+ tasks.add_msg "Removing and ignoring files from #{dir}"
134
+ if File.directory?(dir)
135
+ Dir.glob(dir + '/*').each do |d|
136
+ if File.directory?(d)
137
+ tasks.concat recursive_delete_and_ignore(d)
138
+ else
139
+ tasks.add_cmd("svn rm --keep-local '#{d}'")
140
+ end
141
+ end
142
+ tasks.add_cmd "svn propset svn:ignore '*' '#{dir}'"
143
+ else
144
+ tasks.add_msg "The #{dir} directory doesn't exist"
145
+ end
146
+ tasks
147
+ end
148
+
149
+ def remove_file_with_example(d,f)
150
+ tasks = TaskQueue.new
151
+ fp = File.join(RAILS_ROOT,d,f)
152
+ tasks.add_msg "Copying #{f} to #{f}.example"
153
+ if File.exists?(fp)
154
+ tasks.add_cmd "svn cp #{fp} #{fp}.example"
155
+ tasks.add_cmd "svn rm --keep-local #{fp}"
156
+ else
157
+ tasks.add_msg "The #{f} file doesn't exist"
158
+ end
159
+ tasks.add_msg "Ignoring #{f}"
160
+ ignores = [%x[svn propget svn:ignore '#{File.join(RAILS_ROOT,d)}'].strip, "#{f}"].select {|i| !i.blank? }.join('\n')
161
+ tasks.add_cmd "echo -e #{ignores.dump} | svn propset svn:ignore -F - '#{File.join(RAILS_ROOT,d)}'"
162
+ tasks
163
+ end
164
+
165
+ def remove_glob(d,f)
166
+ tasks = TaskQueue.new
167
+ fp = File.join(RAILS_ROOT,d,f)
168
+ tasks.add_msg "Removing #{f} from #{d}"
169
+ unless Dir.glob(fp).empty?
170
+ tasks.add_cmd "svn rm --keep-local '#{fp}'"
171
+ else
172
+ tasks.add_msg "#{f} glob doesn't exist in #{d}"
173
+ end
174
+ tasks.add_msg "Ignoring #{f} on #{d}"
175
+ tasks.add_cmd "svn propset svn:ignore '#{File.basename(fp)}' #{File.join(RAILS_ROOT,File.dirname(f))}"
176
+ tasks
177
+ end
178
+
179
+ def help_text
180
+ <<-help
181
+ This script expects that you have a new rails app, and that everything
182
+ has been submitted to the svn repo.
183
+
184
+ The script will do the following:
185
+ - recursively remove all files from log and recursively set ignore * on dirs
186
+ - recursively remove all files from tmp and recursively set ignore * on dirs
187
+ - move config/database.yml to config/database.yml.example and ignore database.yml
188
+ - move config/deploy.rb to config/deploy.rb.example and ignore deploy.rb
189
+ - remove db/*.sqlite3 and ignore them
190
+
191
+ All file removal leaves the local copy (your local file is only deleted from the repo)
192
+
193
+ Use the -s option to do a simulated run
194
+ Use the --verbose option for verbose (show the commands being run)
195
+ help
196
+ end
data/init.rb ADDED
@@ -0,0 +1,7 @@
1
+ # Placeholder to placate Rails. (Stolen from rspec-rails)
2
+ #
3
+ # Do NOT add any require statements to this file. Doing
4
+ # so will cause Rails to load this plugin all of the time.
5
+ #
6
+ # Running 'ruby script/generate svn_ignore_rails' will
7
+ # generate the rake file.
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pol-svn_ignore_rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Pol Llovet
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Rails generator for svn ignore rake tasks
17
+ email: pol.llovet+code@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - License.txt
24
+ files:
25
+ - .document
26
+ - generators/svn_ignore
27
+ - generators/svn_ignore/svn_ignore_rails_generator.rb
28
+ - generators/svn_ignore/templates/svn_ignore.rake
29
+ - History.rdoc
30
+ - init.rb
31
+ - License.txt
32
+ - Manifest.txt
33
+ - Rakefile
34
+ - README.rdoc
35
+ - TODO.txt
36
+ - Upgrade.rdoc
37
+ has_rdoc: true
38
+ homepage: http://github.com/pol/svn_ignore_rails
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --inline-source
42
+ - --line-numbers
43
+ - README
44
+ - generators
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.2.0
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Rails generator for svn ignore rake tasks
66
+ test_files: []
67
+