Permalink
Browse files

Git support for script/generate. Closes #10690.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 95af468 commit 7527447ba178d9862b6782c7752d669e8bd32f85 @jeremy jeremy committed Feb 2, 2008
Showing with 30 additions and 3 deletions.
  1. +2 −0 railties/CHANGELOG
  2. +21 −3 railties/lib/rails_generator/commands.rb
  3. +7 −0 railties/lib/rails_generator/options.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Git support for script/generate. #10690 [ssoroka]
+
* Update scaffold to use labels instead of bold tags. Closes #10757 [zach-inglis-lt3]
* Resurrect WordNet synonym lookups. #10710 [tom./, matt]
@@ -255,8 +255,9 @@ def file(relative_source, relative_destination, file_options = {}, &block)
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 @@ def complex_template(relative_source, relative_destination, template_options = {
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 @@ def directory(relative_path)
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 @@ def file(relative_source, relative_destination, file_options = {})
# 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 @@ def directory(relative_path)
# 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
@@ -136,6 +136,13 @@ def add_general_options!(opt)
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

0 comments on commit 7527447

Please sign in to comment.