   # This command *must* be passed through a formatter before its displayed
   register '_status',
     update: (done) ->
-      return done null, [] unless status = repo?.getStatus()
+      return done null, [] unless status = repo()?.getStatus()
 
       statuses = for path, code of status
         # Hack around weird behavior in libgit2 that treats nested Git repos as submodules
         # https://github.com/libgit2/libgit2/pull/1423
         #
         # Benchmarking suggests this is likely fast enough
-        continue if repo.isIgnored path
+        continue if repo().isIgnored path
 
         new Status path, code
 

git = require 'git-utils'

repo = git.open '.'

module.exports = (Impromptu, register, git) ->
  # Expose the repo object from the git-utils library
  # This will be null when we're not in a repo
  register '_repo',
    update: (done) ->
      done null, repo

  # Helper to figure out if we're in a repo at all
  register 'isRepo',
    update: (done) ->
      done null, !! repo

  # Root path to the repository
  register 'root',
    update: (done) ->
      root = repo?.getPath().replace /\.git\/$/, ''
      done null, root

  # Branch name

  # Returns null in newly-initialized repos (note that isRepo() still returns true in this case)
  register 'branch',
    update: (done) ->
      branch = repo()?.getShortHead()
      done null, branch

  # Determine whether the repo is currently in a detached head state
  # This happens when you checkout, for example, a commit hash
  register 'isDetachedHead',
    update: (done) ->
      branch = repo()?.getHead()
      done null, ! /^refs\/heads\//.test branch

  # Returns an object with 'ahead' and 'behind' keys
