Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I can't answer the question of how to get the status if no commits have been made, but I can try and explain why it's blowing up.</p> <p>The Git::Status class works by doing a git diff of HEAD against the repository. In Git "HEAD" refers to the current branch &amp; working tree.</p> <p>Since a branch is basically a pointer to a particular commit (the branch pointer gets moved along the history as new commits are made) no branches truly exist (not even master) until there is a commit to point it at. If there are no branches, HEAD doesn't really exist either. Therefore referring to it in a git diff throws an error.</p> <p>This is a great visual guide to understanding HEAD/branches/commits: <a href="http://marklodato.github.com/visual-git-guide/" rel="nofollow noreferrer">http://marklodato.github.com/visual-git-guide/</a></p> <p>So in conclusion, it seems that trying to do anything in a git repo which has no commits is somewhat meaningless. Of course, to do a commit, you need a file. So you probably need to:</p> <pre><code>#gem install git require 'rubygems' require 'git' #Create an empty file FileUtils.touch 'README' g = Git.init g.add('README') g.commit('First Commit') g.status </code></pre> <hr> <p>If you want to check if a file has been added to the repo:</p> <pre><code>#gem install git require 'rubygems' require 'git' #Create an empty file FileUtils.touch 'README' g = Git.init g.ls_files.has_key?("README") #False g.add("README") g.commit("First Commit") g.ls_files.has_key?("README") #True </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload