2012-10-10 41 views
3

我使用https://github.com/thuss/standalone-migrations在cakephp環境中執行數據庫遷移。我最終嘗試通過使用post-checkout git鉤子檢出不同版本的代碼後自動執行數據庫遷移。使用rake db:在git鉤子中遷移 - 未定義的類/模塊編碼

在cli bundle exec rake db:migrate上正常運行正常,rake db:migrate或任何其他命令都正常工作。如果我把命令放在.git/hooks/post-checkout中,它會發出一個錯誤,抱怨undefined class/module Encoding

git鉤子命令是bundle exec rake db:migrate --trace

平臺:Mac OS X Lion的10.7.5

這是整個錯誤:

 
rake aborted! 
undefined class/module Encoding 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/lib/json/ext/parser.bundle 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/lib/json/ext.rb:13 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/lib/json.rb:58:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/lib/json.rb:58 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/object/to_json.rb:3:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/object/to_json.rb:3 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/object.rb:10:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext/object.rb:10 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext.rb:2:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext.rb:2 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext.rb:1:in `each' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/core_ext.rb:1 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/all.rb:3:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.2.8/lib/active_support/all.rb:3 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/standalone_migrations/configurator.rb:1:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/standalone_migrations/configurator.rb:1 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/standalone_migrations.rb:8:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/standalone_migrations.rb:8 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/tasks/standalone_migrations.rb:9:in `require' 
/Users/andy/.rvm/gems/ruby-1.9.3-p194/gems/standalone_migrations-2.0.1/lib/tasks/standalone_migrations.rb:9 
/Users/andy/source/idio/cake/Rakefile:6:in `require' 
/Users/andy/source/idio/cake/Rakefile:6 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling' 
/Users/andy/.rvm/gems/[email protected]/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run' 
/usr/bin/rake:31 

我不是紅寶石太熱。我嘗試過各種技巧,刪除所有寶石,重新安裝等。總是一樣的。

謝謝。

回答

1

原來,這是一個問題,在鉤子內將git重新附加到$ PATH/usr/bin。這會導致調用操作系統版本的ruby(位於/ usr/bin)而不是我的rvm版本。 OS版本是1.8.7,沒有合適的寶石等我使用1.9.3。

要解決您需要在鉤子內源代碼的rvm安裝腳本。例如:

#!/usr/bin/env bash 
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" 

# ...rest of the post commit commands