83's

Top > Tags > svk

svk

タイトル一覧を表示 | 本文を表示

script/destroyと同時にsvk rmとかsvk revert November 26, 2006 09:51

少々てこずったYO! 保証はしません。

./script/destroyを以下で置き換え。

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/destroy'
require "#{RAILS_ROOT}/config/environment"
require 'rails_generator'
require 'rails_generator/scripts/destroy'

module Rails::Generator::Options
  alias _add_general_options! add_general_options!

  protected
  def add_general_options!(opt)
    _add_general_options!(opt)
    opt.on("-S", "--svk", "Modify files with svk.") do
      options[:svk] = `svk status`.inject({}) do |opt, e|
        opt[e.split(/\s+/)[1]] = true
        opt
      end
    end
  end
end

class Rails::Generator::Commands::Destroy
  def file(relative_source, relative_destination, file_options = {})
    destination = destination_path(relative_destination)
    if File.exists?(destination)
      logger.rm relative_destination
      unless options[:pretend]
        if options[:svn]
          # If the file has been marked to be added
          # but has not yet been checked in, revert and delete
          if options[:svn][relative_destination]
            system("svn revert #{destination}")
            FileUtils.rm(destination)
          else
            # If the directory is not in the status list, it
            # has no modifications so we can simply remove it
            system("svn rm #{destination}")
          end
        elsif options[:svk]
          # If the file has been marked to be added
          # but has not yet been checked in, revert and delete
          if options[:svk][relative_destination]
            system("svk revert #{destination}")
            FileUtils.rm(destination)
          else
            # If the directory is not in the status list, it
            # has no modifications so we can simply remove it
            system("svk rm #{destination}")
          end
        else
          FileUtils.rm(destination)
        end
      end
    else
      logger.missing relative_destination
      return
    end
  end

  alias_method :template, :file

  def directory(relative_path)
    parts = relative_path.split('/')
    until parts.empty?
      partial = File.join(parts)
      path = destination_path(partial)
      if File.exists?(path)
        if Dir[File.join(path, '*')].empty?
          logger.rmdir partial
          unless options[:pretend]
            if options[:svn]
              # If the directory has been marked to be added
              # but has not yet been checked in, revert and delete
              if options[:svn][relative_path]
                system("svn revert #{path}")
                FileUtils.rmdir(path)
              else
                # If the directory is not in the status list, it
                # has no modifications so we can simply remove it
                system("svn rm #{path}")
              end
            elsif options[:svk]
              # If the directory has been marked to be added
              # but has not yet been checked in, revert and delete
              if options[:svk][relative_path]
                system("svk revert #{path}")
                FileUtils.rmdir(path)
              else
                # If the directory is not in the status list, it
                # has no modifications so we can simply remove it
                system("svk rm #{path}")
              end
            else
              FileUtils.rmdir(path)
            end
          end
        else
          logger.notempty partial
        end
      else
        logger.missing partial
      end
      parts.pop
    end
  end
end

ARGV.shift if ['--help', '-h'].include?(ARGV[0])
Rails::Generator::Scripts::Destroy.new.run(ARGV)

まんま上書きな感じ。

-Sオプションをつけるとsvk rmとかします。

% ./script/destroy model -S AA
    notempty  db/migrate
    notempty  db
          rm  db/migrate/001_create_aas.rb
D   script/../config/../db/migrate/001_create_aas.rb
          rm  test/fixtures/aas.yml
D   script/../config/../test/fixtures/aas.yml
          rm  test/unit/aa_test.rb
D   script/../config/../test/unit/aa_test.rb
          rm  app/models/aa.rb
D   script/../config/../app/models/aa.rb
       rmdir  test/fixtures
D   script/../config/../test/fixtures/aas.yml
D   script/../config/../test/fixtures
    notempty  test
       rmdir  test/unit
D   script/../config/../test/unit/aa_test.rb
D   script/../config/../test/unit
    notempty  test
       rmdir  app/models
D   script/../config/../app/models/aa.rb
D   script/../config/../app/models
    notempty  app

ありゃ、aliasとalias_methodがごちゃまぜだ。 動作確認めんどいからそのままにしておこう。

alias_methodは初めて知った。そうするとaliasはキモいね。もうalias使うのやめよっと。

忘れてた November 26, 2006 06:28

あーscript/destroy忘れてたよ。 そのうちやろう。

頭痛くなってきた。

rails.vimでRgenerateでsvk add November 26, 2006 05:19

rails.vimでは:Rgenerate model Bookとかやると./script/generate model Bookが走る上に .svnがあると-cオプションをつけてくれるのでsubversionにファイルを追加してくれて 激しく便利なんだけど、これがsvkだとそうはいかないのでrails.vimをちと変えるよ!

1062     let file = ""
1063   endif
1064   if !s:rubyexe("script/generate ".target.(s:usesubversion()?' -c':' -S').str) && file != ""
1065     exe "edit ".s:ra()."/".file
1066   endif

3項演算子らしきものがあるのでそこに-Sを追加。 オレオレscript/generateとの併用でsvk addしてくれます。

これ、.svnがないと無条件でsvk使おうとするんだけど、 svnもsvkも使わないのが許されるのは確か小学生までなんで大丈夫だろうきっと。 vimスクリプトには突撃したくないのでとりあえずいいよオレはこれで。 あーでもちょっとRailsった場合はウザいかも。

ちょっと元気になってきた。オレはいつ寝たらいいんだろう。 とりあえずベッドに横たわってみる。

script/generateで生成したファイルを自動でsvk add November 26, 2006 05:03

script/generateに-cオプションをつけると生成されたファイルやディレクトリを 自動でsvn addしてくれるのは有名な話ですが、svkはどーしたんだってことで、 先にググれば良かったけど最近慢性的に眠いせいで頭が働かず、手が先に出た。

他にスマートな方法があるといいなぁ。 けだるすぎてググる気にならん。動悸がするお……。 寝たほうがいいんだろうけど特に眠くないしなーどうしよ。

以下のように#{RAILS_ROOT}/script/generateをいじってたら動いたみたい。

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
#require 'commands/generate'

require "#{RAILS_ROOT}/config/environment"
require 'rails_generator'
require 'rails_generator/scripts/generate'

module Rails::Generator::Options
  alias _add_general_options! add_general_options!

  protected
  def add_general_options!(opt)
    _add_general_options!(opt)
    opt.on("-S", "--svk", "Modify files with svk.") { options[:svk] = true }
  end
end

class Rails::Generator::Commands::Create
  alias _file file

  def file(relative_source, relative_destination, file_options = {}, &block)
    destination = destination_path(relative_destination)

    _file(relative_source, relative_destination, file_options, &block)

    system("svk add #{destination}") if options[:svk]
  end

  alias _directory directory

  def directory(relative_path)
    path = destination_path(relative_path)

    _directory(relative_path)

    unless File.exists?(path)
      system("svk add #{path}") if options[:svk]
    end
  end
end

ARGV.shift if ['--help', '-h'].include?(ARGV[0])
Rails::Generator::Scripts::Generate.new.run(ARGV)

-hで見ればわかるけど、svk addするには-Sオプションをつけます。

% ./script/generate model -S a
      exists  app/models/
      exists  test/unit/
      exists  test/fixtures/
      create  app/models/a.rb
A   script/../config/../app/models/a.rb
      create  test/unit/a_test.rb
A   script/../config/../test/unit/a_test.rb
      create  test/fixtures/as.yml
A   script/../config/../test/fixtures/as.yml
      exists  db/migrate
      create  db/migrate/005_create_as.rb
A   script/../config/../db/migrate/005_create_as.rb

ktkr!!!!!!!

といってもgrepかけてそれらしいところを追ってって変更しただけなんで結構怪しい。