I'm trying to display some git version information (via grit) in my rails application footer for debuging. When I want to see the head, it's straightforward:
@git_repository = Grit::Repo.new( Ter::Application.root )
head = @git_repository.heads.first
t '.git_info', :revision => head.commit.id, :branch => head.name, :author => head.commit.author.name, :date => l(head.commit.authored_date, :format => :long)
which works if I'm always using the newest revision (the main head). However I couldn't find a way to show the branch or tag used by the working directory (grit seems to operate only on the repo, not the working directory).
Is there a way to display the working directory info in grit?
Use Grit::Repo#head
instead of #heads
– it will give you the Grit::Head
object corresponding to .git/HEAD
which is the currently checked out commit or ref.
#heads
will give you all branches instead.