From 7527447ba178d9862b6782c7752d669e8bd32f85 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 2 Feb 2008 02:55:14 +0000 Subject: Git support for script/generate. Closes #10690. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- railties/lib/rails_generator/commands.rb | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'railties/lib/rails_generator/commands.rb') diff --git a/railties/lib/rails_generator/commands.rb b/railties/lib/rails_generator/commands.rb index f6e503282d..2f65918796 100644 --- a/railties/lib/rails_generator/commands.rb +++ b/railties/lib/rails_generator/commands.rb @@ -255,8 +255,9 @@ HELP FileUtils.chmod(file_options[:chmod], destination) end - # Optionally add file to subversion + # Optionally add file to subversion or git system("svn add #{destination}") if options[:svn] + system("git add -v #{relative_destination}") if options[:git] end # Checks if the source and the destination file are identical. If @@ -303,7 +304,7 @@ HELP end # Create a directory including any missing parent directories. - # Always directories which exist. + # Always skips directories which exist. def directory(relative_path) path = destination_path(relative_path) if File.exist?(path) @@ -312,6 +313,8 @@ HELP logger.create relative_path unless options[:pretend] FileUtils.mkdir_p(path) + # git doesn't require adding the paths, adding the files later will + # automatically do a path add. # Subversion doesn't do path adds, so we need to add # each directory individually. @@ -428,7 +431,20 @@ end_message # If the directory is not in the status list, it # has no modifications so we can simply remove it system("svn rm #{destination}") - end + end + elsif options[:git] + if options[:git][:new][relative_destination] + # file has been added, but not committed + system("git reset HEAD #{relative_destination}") + FileUtils.rm(destination) + elsif options[:git][:modified][relative_destination] + # file is committed and modified + system("git rm -f #{relative_destination}") + else + # If the directory is not in the status list, it + # has no modifications so we can simply remove it + system("git rm #{relative_destination}") + end else FileUtils.rm(destination) end @@ -465,6 +481,8 @@ end_message # has no modifications so we can simply remove it system("svn rm #{path}") end + # I don't think git needs to remove directories?.. + # or maybe they have special consideration... else FileUtils.rmdir(path) end -- cgit v1.2.3