title: JGit and finding the Head
body: <p>I'm trying to get my hands on the HEAD commit with JGit:</p>
  
  <pre><code>val builder = new FileRepositoryBuilder()
  val repo = builder.setGitDir(new File("/www/test-repo"))
    .readEnvironment()
    .findGitDir()
    .build()
  
  val walk: RevWalk = new RevWalk(repo, 100)
  
  val head: ObjectId = repo.resolve(Constants.HEAD)
  val headCommit: RevCommit = walk.parseCommit(head)
  </code></pre>
  
  <p>I find that it opens the repo fine, but <code>head</code> value is set to <code>null</code>. I wonder why it can't find HEAD?</p>
  
  <p>I'm reading this documentation: <a href="http://wiki.eclipse.org/JGit/User_Guide">http://wiki.eclipse.org/JGit/User_Guide</a></p>
  
  <p>The repository is constructed just like the doc says, and the <code>RevWalk</code> as well. I'm using the latest version of JGit which is <code>2.0.0.201206130900-r</code> from <a href="http://download.eclipse.org/jgit/maven">http://download.eclipse.org/jgit/maven</a>.</p>
  
  <p>My question: what do I need to change in my code to get JGit to return actual instances of <code>RevCommit</code> instead of <code>null</code> like it now does?</p>
  
  <p><strong>Update:</strong> This code:</p>
  
  <pre><code>val git = new Git(repo)
  val logs: Iterable[RevCommit] = git.log().call().asInstanceOf[Iterable[RevCommit]]
  </code></pre>
  
  <p>Gives me this exception: <code>No HEAD exists and no explicit starting revision was specified</code></p>
  
  <p>The exception is odd, because a simple <code>git rev-parse HEAD</code> tells me <code>0b0e8bf2cae9201f30833d93cc248986276a4d75</code>, which means there is a HEAD in the repository. I've tried different repositories, mine and from other people.</p>