简体   繁体   English

在Thor任务的git子模块中运行命令时出错

[英]Error when running commands inside git submodule from Thor task

I have a Rails 3.2 project that is a git repo and inside the vendor/autotest-new directory I have a git submodule. 我有一个Rails 3.2项目,它是一个git repo,在vendor/autotest-new目录中,我有一个git子模块。

I want to use Thor to automate some actions. 我想使用雷神(Thor)自动执行某些操作。 For example I need to perform cucumber -d -f json > test.json inside the git submodule. 例如,我需要在git子模块中执行cucumber -d -f json > test.json

Manually it works fine, but when I run the thor task it throws an error: 手动可以正常工作,但是当我运行thor任务时会抛出错误:

/home/user/.rvm/gems/ruby-2.0.0-p247@global/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': cucumber is not part of the bundle. Add it to Gemfile. (Gem::LoadError)
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/cucumber:22:in `<main>'
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/ruby_noexec_wrapper:14:in `eval'
  from /home/user/.rvm/gems/ruby-2.0.0-p247@rails32/bin/ruby_noexec_wrapper:14:in `<main>'

I've already run bundle install inside the submodule. 我已经在子模块中运行了bundle install

The thor task is: 我们的任务是:

class DB < Thor

  include Thor::Actions

  desc 'test_task',  "test task"
  def test_task
    Dir.chdir("vendor/autotest-new") do
      puts `bundle exec cucumber -d -f json > test.json`
    end
  end
end

I've also tried 我也尝试过

run "bundle exec cucumber -d -f json > test.json"
system "bundle exec cucumber -d -f json > test.json"

But it didn't help. 但这没有帮助。

It's not Thor, it's bundler. 不是雷神,它是捆扎机。

Answer is here https://github.com/bundler/bundler/issues/1579 答案在这里https://github.com/bundler/bundler/issues/1579

I need to use execute that commands in the block 我需要在块中使用执行该命令

Bundler.with_clean_env do
  #my commands
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM