3

我正在使用https://github.com/thuss/standalone-migrations在 cakephp 环境中执行数据库迁移。我最终试图在使用 post-checkout git hook 签出不同版本的代码后自动执行数据库迁移。

在 cli 上正常运行可以正常运行bundle exec rake db:migraterake db:migrate与其他任何命令一样。如果我把命令放进去,.git/hooks/post-checkout它会吐出一个错误,抱怨undefined class/module Encoding

git hook 命令是bundle exec rake db:migrate --trace.

平台:Mac OS X Lion 10.7.5

这是整个错误:

耙中止!
未定义的类/模块编码
/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/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/rake_module.rb:25:in `load_rakefile'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:501:in `raw_load_rakefile'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:82:in `load_rakefile'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:81:in `load_rakefile'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:65:in `run'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:133:in `standard_exception_handling'
/Users/andy/.rvm/gems/ruby-1.9.3-p194@global/gems/rake-0.9.2.2/lib/rake/application.rb:63:in `run'
/usr/bin/rake:31

我对红宝石不太感冒。我尝试了各种技巧,删除了所有的 gem,重新安装了等等。总是一样的。

谢谢。

4

1 回答 1

1

原来这是 git 在钩子中将 /usr/bin 重新附加到 $PATH 的问题。这会导致调用 ruby​​ 的操作系统版本(位于 /usr/bin 中)而不是我的 rvm 版本。操作系统版本是 1.8.7,没有正确的 gem 等。我使用的是 1.9.3。

要修复,您需要在挂钩中获取 rvm 设置脚本。就像是:

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

# ...rest of the post commit commands
于 2012-10-11T09:47:56.487 回答