Bug 544894 - MissingObjectException when using DiffFormatter on DiffEntry with working tree entry
Summary: MissingObjectException when using DiffFormatter on DiffEntry with working tre...
Status: NEW
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 5.2   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-02-27 14:05 EST by Björn Kautler CLA
Modified: 2019-02-27 14:05 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Björn Kautler CLA 2019-02-27 14:05:59 EST
When executing the following code with a file changed in the worktree:

Repository repo = new RepositoryBuilder().findGitDir(new File("path/to/repo")).setMustExist(true).build();
DiffFormatter diffFormatter = new DiffFormatter(System.out);
diffFormatter.setRepository(repo);
diffFormatter.format(new Git(repo).diff().setOldTree(new EmptyTreeIterator()).call().iterator().next());

you get a missing object exception.
In my case it is

org.eclipse.jgit.errors.MissingObjectException: Missing blob cb188f8580dd4e09a90757478e8be4b7b69f7c37
	at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:170)
	at org.eclipse.jgit.diff.ContentSource$ObjectReaderSource.open(ContentSource.java:145)
	at org.eclipse.jgit.diff.ContentSource$Pair.open(ContentSource.java:282)
	at org.eclipse.jgit.diff.DiffFormatter.open(DiffFormatter.java:1073)
	at org.eclipse.jgit.diff.DiffFormatter.createFormatResult(DiffFormatter.java:1001)
	at org.eclipse.jgit.diff.DiffFormatter.format(DiffFormatter.java:706)
	at org.eclipse.jgit.diff.DiffFormatter$format$3.call(Unknown Source)
	at ConsoleScript15.run(ConsoleScript15:17)


Where the blob that is missing is the blob of the file in the work tree:

$ git diff
diff --git a/file-in-first-commit.xoo b/file-in-first-commit.xoo
index bd4a117..cb188f8 100644
--- a/file-in-first-commit.xoo
+++ b/file-in-first-commit.xoo
@@ -1,3 +1,4 @@
...