I have been trying to use the ruby-git gem to make commits etc from with in a ruby script however the method to check the current status always throws an error. My understanding is that this code, although not doing too much, should be valid.
#gem install git
require 'rubygems'
require 'git'
g = Git.init
g.status
but it returns:
Git::GitExecuteError: git diff-index “HEAD” 2>&1:fatal: ambiguous argument ‘HEAD’: >unknown revision or path not in the working tree.
Use ‘–‘ to separate paths from revisions
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:700:incommand'command_lines’
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:672:in
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/lib.rb:287:indiff_index'construct_status’
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/status.rb:99:in
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/status.rb:8:ininitialize'new’
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/base.rb:175:in
from /Users/X/bin/ruby-ee-1.8.7/lib/ruby/gems/1.8/gems/git-1.2.5/lib/git/base.rb:175:in `status’
from (irb):5
Does any one have examples of how to get the current git status within ruby (using ruby-git)?
Pages I have looked at:
http://rubygems.org/gems/git
http://git.rubyforge.org/
Thanks
Path may be the important bit of that error message
in a directory that has no git repo, and it blew up like yours did.
After
cding into the root directory of a project with a git repo, it worked.Check that you are in the root of a git repo. There should be a
.gitdirectory in it. If not, you could also pass the path toGit.initifcding is inconvenient for some reason.