schacon/ruby-git — pull request #205 by othatbrian (2014-12-07 07:12:27+00:00)
Title: Fix issue #184 (Git status crashes on empty repo)

When a repo is created, but before a commit is made, the index does not exist. ruby-git is trying to do a diff using HEAD; because the index doesn't exist, HEAD doesn't exist, so it explodes.

The solution below fixes this issue. Yes, I know "unless !" == "if", but I thought it was a little more clean that the conditional is there to protect against the case where the file does not exist. Feel free to change it to an "if" or move it to the front with an "&&".

I didn't specifically see anywhere else where the use of HEAD on an empty repo would occur, but I'm not terribly familiar with this project. This seemed a more direct solution that trying to implement an "GitObjectNotFound" kind of error.