aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib/rails_generator
diff options
context:
space:
mode:
authorMarcel Molina <marcel@vernix.org>2005-10-08 16:56:36 +0000
committerMarcel Molina <marcel@vernix.org>2005-10-08 16:56:36 +0000
commitd451044ece8254f41c2e2e569e31f13eb45014ce (patch)
tree472f54726471cb435f7f8c3df8d11c07566b131a /railties/lib/rails_generator
parent31baeeef1b4572aac6f4727aa5b278929f52b6bc (diff)
downloadrails-d451044ece8254f41c2e2e569e31f13eb45014ce.tar.gz
rails-d451044ece8254f41c2e2e569e31f13eb45014ce.tar.bz2
rails-d451044ece8254f41c2e2e569e31f13eb45014ce.zip
Make the generator skip a file if it already exists and is identical to the new file.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2493 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib/rails_generator')
-rw-r--r--railties/lib/rails_generator/commands.rb13
1 files changed, 10 insertions, 3 deletions
diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb
index 5f37992d77..e6795efdb9 100644
--- a/railties/lib/rails_generator/commands.rb
+++ b/railties/lib/rails_generator/commands.rb
@@ -146,11 +146,13 @@ module Rails
# the user what to do.
def file(relative_source, relative_destination, file_options = {})
# Determine full paths for source and destination files.
- source = source_path(relative_source)
- destination = destination_path(relative_destination)
+ source = source_path(relative_source)
+ destination = destination_path(relative_destination)
+ destination_exists = File.exists?(destination)
+ return logger.identical(relative_destination) if destination_exists and identical?(source, destination)
# Check for and resolve file collisions.
- if File.exists?(destination)
+ if destination_exists
# Make a choice whether to overwrite the file. :force and
# :skip already have their mind made up, but give :ask a shot.
@@ -207,6 +209,11 @@ module Rails
system("svn add #{destination}") if options[:svn]
end
+ # Checks if the source and the destination file are identical.
+ def identical?(source, destination)
+ IO.read(source) == IO.read(destination)
+ end
+
# Generate a file for a Rails application using an ERuby template.
# Looks up and evalutes a template by name and writes the result.
#