aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-02-02 02:55:14 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-02-02 02:55:14 +0000
commit7527447ba178d9862b6782c7752d669e8bd32f85 (patch)
tree92391ac02a603efc51fc692f8de804adf02a5568 /railties/lib
parent95af46861a80463833081c049f3a723e90c7ec01 (diff)
downloadrails-7527447ba178d9862b6782c7752d669e8bd32f85.tar.gz
rails-7527447ba178d9862b6782c7752d669e8bd32f85.tar.bz2
rails-7527447ba178d9862b6782c7752d669e8bd32f85.zip
Git support for script/generate. Closes #10690.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/rails_generator/commands.rb24
-rw-r--r--railties/lib/rails_generator/options.rb7
2 files changed, 28 insertions, 3 deletions
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
diff --git a/railties/lib/rails_generator/options.rb b/railties/lib/rails_generator/options.rb
index 042e05107d..5f6aefa921 100644
--- a/railties/lib/rails_generator/options.rb
+++ b/railties/lib/rails_generator/options.rb
@@ -136,6 +136,13 @@ module Rails
opt
end
end
+ opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do
+ options[:git] = `git status`.inject({:new => {}, :modified => {}}) do |opt, e|
+ opt[:new][e.chomp[14..-1]] = true if e =~ /new file:/
+ opt[:modified][e.chomp[14..-1]] = true if e =~ /modified:/
+ opt
+ end
+ end
end
end