JGit并找到头部 [英] JGit and finding the Head

查看:320
本文介绍了JGit并找到头部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  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 (头)

我发现它打开回购罚款,但 value设置为 null 。我想知道为什么它找不到HEAD?



我正在阅读本文档: http://wiki.eclipse.org/JGit/User_Guide



存储库的构建方式与doc相同, RevWalk 。我正在使用来自 <?c $ c> 2.0.0.201206130900-r 的最新版JGit http://download.eclipse.org/jgit/maven



我的问题:我需要在代码中更改以获取JGit以返回 RevCommit 而不是 null 的实际情况如现在这样吗?



  val git =新的Git(回购)
val日志:Iterable [RevCommit] = git.log()。call()。asInstanceOf [Iterable [RevCommit]]

给我这个例外:不存在HEAD并且没有指定明确的开始修订



很奇怪,因为一个简单的 git rev-parse HEAD 告诉我 0b0e8bf2cae9201f30833d93cc248986276a4d75 ,这意味着存储库中有一个HEAD 。我已经尝试了不同的存储库,我的和其他人。

解决方案

您需要指向Git元数据目录code> setGitDir ,而不是工作目录(<$ c $> code> /www/test-repo/.git )

我必须承认我不确定 findGitDir / www / test-repo / code>应该这样做,但我之前遇到过这个问题,并指定了 .git 目录。


I'm trying to get my hands on the HEAD commit with JGit:

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)

I find that it opens the repo fine, but head value is set to null. I wonder why it can't find HEAD?

I'm reading this documentation: http://wiki.eclipse.org/JGit/User_Guide

The repository is constructed just like the doc says, and the RevWalk as well. I'm using the latest version of JGit which is 2.0.0.201206130900-r from http://download.eclipse.org/jgit/maven.

My question: what do I need to change in my code to get JGit to return actual instances of RevCommit instead of null like it now does?

Update: This code:

val git = new Git(repo)
val logs: Iterable[RevCommit] = git.log().call().asInstanceOf[Iterable[RevCommit]]

Gives me this exception: No HEAD exists and no explicit starting revision was specified

The exception is odd, because a simple git rev-parse HEAD tells me 0b0e8bf2cae9201f30833d93cc248986276a4d75, which means there is a HEAD in the repository. I've tried different repositories, mine and from other people.

解决方案

You need to point to the Git metadata directory (probably /www/test-repo/.git) when you call setGitDir, not to the working directory (/www/test-repo).

I have to admit I'm not sure what findGitDir is supposed to do, but I've run into this problem before and specifying the .git directory worked.

这篇关于JGit并找到头部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆