Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 8772

Show
Ignore:
Timestamp:
02/02/08 02:55:14 (1 year ago)
Author:
bitsweat
Message:

Git support for script/generate. Closes #10690.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r8629 r8772  
    11*SVN* 
     2 
     3* Git support for script/generate.  #10690 [ssoroka] 
    24 
    35* Update scaffold to use labels instead of bold tags.  Closes #10757 [zach-inglis-lt3] 
  • trunk/railties/lib/rails_generator/commands.rb

    r8615 r8772  
    256256          end 
    257257 
    258           # Optionally add file to subversion 
     258          # Optionally add file to subversion or git 
    259259          system("svn add #{destination}") if options[:svn] 
     260          system("git add -v #{relative_destination}") if options[:git] 
    260261        end 
    261262 
     
    304305 
    305306        # Create a directory including any missing parent directories. 
    306         # Always directories which exist. 
     307        # Always skips directories which exist. 
    307308        def directory(relative_path) 
    308309          path = destination_path(relative_path) 
     
    313314                  unless options[:pretend] 
    314315                    FileUtils.mkdir_p(path) 
     316                    # git doesn't require adding the paths, adding the files later will 
     317                    # automatically do a path add. 
    315318               
    316319                    # Subversion doesn't do path adds, so we need to add 
     
    429432                # has no modifications so we can simply remove it 
    430433                  system("svn rm #{destination}") 
    431                 end   
     434                end 
     435              elsif options[:git] 
     436                if options[:git][:new][relative_destination] 
     437                  # file has been added, but not committed 
     438                  system("git reset HEAD #{relative_destination}") 
     439                  FileUtils.rm(destination) 
     440                elsif options[:git][:modified][relative_destination] 
     441                  # file is committed and modified 
     442                  system("git rm -f #{relative_destination}") 
     443                else 
     444                  # If the directory is not in the status list, it 
     445                  # has no modifications so we can simply remove it 
     446                  system("git rm #{relative_destination}") 
     447                end 
    432448              else 
    433449                FileUtils.rm(destination) 
     
    466482                      system("svn rm #{path}") 
    467483                    end 
     484                  # I don't think git needs to remove directories?.. 
     485                  # or maybe they have special consideration... 
    468486                  else 
    469487                    FileUtils.rmdir(path) 
  • trunk/railties/lib/rails_generator/options.rb

    r4502 r8772  
    137137            end 
    138138          end 
     139          opt.on('-g', '--git', 'Modify files with git. (Note: git must be in path)') do 
     140            options[:git] = `git status`.inject({:new => {}, :modified => {}}) do |opt, e| 
     141              opt[:new][e.chomp[14..-1]] = true if e =~ /new file:/ 
     142              opt[:modified][e.chomp[14..-1]] = true if e =~ /modified:/ 
     143              opt 
     144            end 
     145          end 
    139146        end 
    140147