eclipse-jgit / jgit

JGit, the Java implementation of git
https://www.eclipse.org/jgit/
Other
92 stars 31 forks source link

Pull: MissingObjectException #60

Open stefandrissen opened 1 month ago

stefandrissen commented 1 month ago

Version

6.9.0

Operating System

Windows

Bug description

When using Pull (from Azure DevOps remote repository) it can (often) fail with MissingObjectException.

The native Git client has no problems and happily pulls, after which JGit will pull and report no changes.

Deleting the local repo and cloning it again alleviates the problem temporarily, until there are more commits in the repo.

Actual behavior

Git pull from remote repo.

Pulling 1 repository
Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown 542a7b7366423cb0592f27aaacffdbf2d59bfd91
Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown 542a7b7366423cb0592f27aaacffdbf2d59bfd91

I am getting the MissingObjectException on the same id from another VM.

Expected behavior

A successful pull. Having to switch out from Eclipse to native git for a successful pull is disturbing.

Relevant log output

!ENTRY org.eclipse.egit.core 4 0 2024-05-30 13:56:17.003
!MESSAGE Pulling 1 repository
!SUBENTRY 1 org.eclipse.egit.core 4 0 2024-05-30 13:56:17.003
!MESSAGE Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown 542a7b7366423cb0592f27aaacffdbf2d59bfd91
!STACK 0
org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown 542a7b7366423cb0592f27aaacffdbf2d59bfd91
    at org.eclipse.jgit.api.MergeCommand.call(MergeCommand.java:425)
    at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:374)
    at org.eclipse.egit.core.op.PullOperation$PullJob.run(PullOperation.java:256)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing unknown 542a7b7366423cb0592f27aaacffdbf2d59bfd91
    at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:136)
    at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:216)
    at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:1144)
    at org.eclipse.jgit.internal.storage.file.RefDirectory.doPeel(RefDirectory.java:574)
    at org.eclipse.jgit.internal.storage.file.RefDirectory.peel(RefDirectory.java:554)
    at org.eclipse.jgit.api.MergeCommand.call(MergeCommand.java:243)
    ... 3 more

Other information

$ git fsck --full
Checking object directories: 100% (256/256), done.
Checking objects: 100% (215602/215602), done.
dangling commit 395a6eb2959f26dc59e2871a056e79c374929588

After which a git pull from Eclipse is still failing.

msohn commented 1 month ago

Is the missing object available in the local repository after the merge command failed ? You can check using e.g. git show <objectId>

stefandrissen commented 1 month ago

From VM in missing state:

git show 542a7b7366423cb0592f27aaacffdbf2d59bfd91
fatal: bad object 542a7b7366423cb0592f27aaacffdbf2d59bfd91

The commit is present on the remote repo and it is also present after a native git pull. I currently have one VM still in missing object state, so I can run some tests.

From local PC after native git pull:

$ git show 542a7b7366423cb0592f27aaacffdbf2d59bfd91
commit 542a7b7366423cb0592f27aaacffdbf2d59bfd91 (HEAD -> 7.37/dev, origin/7.37/dev)
Merge: 191cb4e7e 395a6eb29
Author: <me>
Date:   Thu May 30 11:22:02 2024 +0000

    Merged PR 94008: <snip>
stefandrissen commented 1 month ago

Another commit has been merged into the remote repo (via PR) and jgit pull is failing again:

Pulling 1 repository
Exception caught during execution of merge command. org.eclipse.jgit.errors.MissingObjectException: Missing unknown f9110b0715ca1fae513d6ec86a2f41a20a07ebf3

Native git:

$ git show f9110b0715ca1fae513d6ec86a2f41a20a07ebf3
fatal: bad object f9110b0715ca1fae513d6ec86a2f41a20a07ebf3

$ git pull
remote: Azure Repos
remote: Found 4 objects to send. (1772 ms)
Unpacking objects: 100% (4/4), 3.04 KiB | 172.00 KiB/s, done.
From https://dev.azure.com/<org>/<project>/_git/<repo>
   542a7b736..f9110b071  7.37/dev   -> origin/7.37/dev
Updating 542a7b736..f9110b071
Fast-forward
 bl/ifall/search/initialize.cls | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

$ git show f9110b0715ca1fae513d6ec86a2f41a20a07ebf3
commit f9110b0715ca1fae513d6ec86a2f41a20a07ebf3 (HEAD -> 7.37/dev, origin/7.37/dev)
Merge: 542a7b736 fd68c6303
Author: <me>
Date:   Thu May 30 15:44:26 2024 +0000

    Merged PR 94410: <snip>
msohn commented 1 month ago

Does the local branch you are pulling from track an upstream branch ?

This is hard to analyze without having access to the repository. Can you reproduce this problem on any public repository ?

stefandrissen commented 1 month ago

Does the local branch you are pulling from track an upstream branch ?

Yes, this is our main repository. The main branch is '7.37/dev', this normally only contains commits that are the result of a Pull Request from a branch created from '7.37/dev', ie '7.37/dev-branch'.

While I have never had this problem persistently, in the past co-workers have had this issue more often.

Which does lead me to suspect that this may be the result of an earlier unintended PR which merged a change from a '7.36/dev-branch' into '7.37/dev' (instead of into '7.36/dev'). The '7.37/dev' branch was created from the '7.36/dev' branch.

This is hard to analyze without having access to the repository. Can you reproduce this problem on any public repository ?

I understand, is there any extended debug logging or so that I can turn on that may shed some light on the issue?

stefandrissen commented 1 month ago

Rereading that definition of upstream branch, I think my previous answer was incorrect, I do not think that we are tracking an upstream branch (unless the accidental PR has resulted in '7.36/dev' being considered a tracked upstream?)

image

stefandrissen commented 1 month ago

Since this is still bugging me, I installed the egit / jgit dev environment and can now debug (be gentle: I am not a java dev).

The fetch result contains a ref to my base branch (7.37/dev) which contains as object id the commit id that is considered missing.

image

[0] HEAD=SymbolicRef[HEAD -> refs/heads/7.37/dev=114d72b3e0b84726e838b365b2ec251568062b56(-1)]

followed by multiple version branches and then the actual head

[35] refs/heads/7.37/dev=Ref[refs/heads/7.37/dev=114d72b3e0b84726e838b365b2ec251568062b56(-1)]

followed by multiple feature branches until

[45] refs/heads/7.37/dev-990642=Ref[refs/heads/7.37/dev-990642=440f8ae546184f1221e4a45d89e05ff0646e0972(-1)]

which is then followed by something else:

[46] refs/pull/25368/merge=Ref[refs/pull/25368/merge=a9f8522c428b73b536ddb1437d6bc21ba52d16d0(-1)] ... [59] refs/pull/96824/merge=Ref[refs/pull/96824/merge=54e2f2a4fd6c62220edc7868c1d07b681a6dfa12(-1)]

I am rather out of my depth here.