Browse Source

Fix NPE in CommitOnlyTest#getHead

Change-Id: I05abd00d151cf9834d1a097dd16dc280b62a7edd
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-5.1
Matthias Sohn 5 years ago
parent
commit
41da8de001
  1. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitOnlyTest.java

@ -1294,9 +1294,15 @@ public class CommitOnlyTest extends RepositoryTestCase {
try { try {
final Repository repo = git.getRepository(); final Repository repo = git.getRepository();
final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}"); final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
if (headId == null) {
return "";
}
try (RevWalk rw = new RevWalk(repo)) { try (RevWalk rw = new RevWalk(repo)) {
final TreeWalk tw = TreeWalk.forPath(repo, path, final TreeWalk tw = TreeWalk.forPath(repo, path,
rw.parseTree(headId)); rw.parseTree(headId));
if (tw == null) {
return "";
}
return new String(tw.getObjectReader().open(tw.getObjectId(0)) return new String(tw.getObjectReader().open(tw.getObjectId(0))
.getBytes()); .getBytes());
} }

Loading…
Cancel
Save