gpt4 book ai didi

ruby - 使用 rake 数据库 :migrate in git hook - undefined class/module Encoding

转载 作者:数据小太阳 更新时间:2023-10-29 08:09:51 26 4
gpt4 key购买 nike

我正在使用 https://github.com/thuss/standalone-migrations在 cakephp 环境中执行数据库迁移。我最终尝试在使用 check out 后 git 钩子(Hook) check out 不同版本的代码后自动执行数据库迁移。

在 cli bundle exec rake db:migrate 上正常运行工作正常,rake 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

这是整个错误:

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/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

我不太喜欢 ruby 。我尝试了各种技巧,删除了所有 gem,重新安装等。总是一样。

谢谢。

最佳答案

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

要修复,您需要在 Hook 中获取 rvm 设置脚本。像这样的东西:

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

# ...rest of the post commit commands

关于ruby - 使用 rake 数据库 :migrate in git hook - undefined class/module Encoding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12817158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com