提交 7527447b 编写于 作者: J Jeremy Kemper

Git support for script/generate. Closes #10690.


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8772 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 95af4686
*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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册