jenkinsci / jenkinsci/git-forensics-plugin

git-forensics fails with MissingObjectException when reference build contains removed commits

Open
#1,264 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
43
Forks
29
Avg merge
5d 12h
Merged PRs (30d)
5

Description

### Jenkins and plugins versions report

Environment


```text
Jenkins: 2.555.3
OS: Linux - 4.18.0-553.132.1.el8_10.x86_64
Java: 21.0.11 - Red Hat, Inc. (OpenJDK 64-Bit Server VM)
---
active-directory:2.41.1
analysis-model-api:14.8.0-976.v5097f60f61a_4
antisamy-markup-formatter:173.v680e3a_b_69ff3
any-buildstep:14.ve115ec1484f0
apache-httpcomponents-client-4-api:4.5.14-269.vfa_2321039a_83
apache-httpcomponents-client-5-api:5.6.1-195.v65ffe15189a_d
asm-api:9.10.1-216.va_9256d3b_844b_
authentication-tokens:1.144.v5ff4a_5ec5c33
basic-branch-build-strategies:317.v85b_331d6cc42
bootstrap5-api:5.3.8-1038.vee76a_fe825ff
bouncycastle-api:2.30.1.84-291.v9f17b_21896e2
branch-api:2.1280.v0d4e5b_b_460ef
build-history-manager:1.15.0
build-name-setter:2.5.1
build-timeout:1.40
caffeine-api:3.2.3-194.v31a_b_f7a_b_5a_81
catppuccin-theme:15.v3940ff14e600
checks-api:402.vca_263b_f200e3
cloud-stats:377.vd8a_6c953e98e
cloudbees-folder:6.1100.ve9eed61d16c4
command-launcher:134.v025a_5fcf9dea_
commons-compress-api:1.28.0-82.v4df6c060eb_66
commons-lang3-api:3.20.0-109.ve43756e2d2b_4
commons-text-api:1.15.0-218.va_61573470393
conditional-buildstep:1.5.0
copyartifact:795.ve8e151429b_27
coverage:3.3240.vb_5a_8809f7523
credentials:1502.v5c95e620ddfe
credentials-binding:725.ve52b_2328a_fde
dark-theme:652.vea_da_dfea_e769
data-tables-api:2.3.8-1570.v1cb_1cd2a_0fb_c
dependency-track:6.0.2
disable-failed-job:1.15
disk-usage:573.v5269a_8d16a_db_
display-url-api:2.217.va_6b_de84cc74b_
docker-commons:472.vee120e23d3a_c
docker-java-api:3.7.1-136.v5d70f77a_c3d6
docker-plugin:1316.v75635a_002b_0a_
docker-workflow:634.vedc7242b_eda_7
durable-task:671.v340ff7959010
echarts-api:6.0.0-1287.vfd24c22a_3d00
eddsa-api:0.3.0.1-29.v67e9a_1c969b_b_
email-ext:1933.1935.v276319e3cc47
favorite:2.263.v941d21defef7
flexible-publish:0.16.1
font-awesome-api:7.2.0-990.vf220b_2a_496f9
forensics-api:4.1891.v5e60f3377506
git:5.10.1
git-client:6.6.0
git-forensics:4.2385.va_e15df49d352
github:1.46.0.1
github-api:1.330-492.v3941a_032db_2a_
github-branch-source:1967.1969.v205fd594c821
gitlab-api:6.3.0-126.vd066b_d896159
gitlab-branch-source:740.v04f287f9194d
gson-api:2.14.0-201.v8eefe5515533
handy-uri-templates-2-api:2.1.8-38.vcea_5d521d5f3
htmlpublisher:427.1
instance-identity:203.v15e81a_1b_7a_38
ionicons-api:94.vcc3065403257
jackson-annotations2-api:2.21-7.v4777a_f3a_a_d47
jackson2-api:2.21.2-436.v29efdb_7418ff
jackson3-api:3.1.3-76.vd9b_7cd2e80b_8
jakarta-activation-api:2.1.4-1
jakarta-mail-api:2.1.5-1
jakarta-xml-bind-api:4.0.9-19.v2b_a_5b_44d9a_1c
javadoc:354.vee1a_660b_4990
javax-activation-api:1.2.0-8
javax-mail-api:1.6.2-11
jaxb:2.3.9-143.v5979df3304e6
jdk-tool:83.v417146707a_3d
jersey2-api:2.48-180.ve47b_264f849b_
jersey3-api:3.1.11-4.v77818819c2e1
jjwt-api:0.13.0-141.vd58b_a_9592b_6c
jobConfigHistory:1356.ve360da_6c523a_
joda-time-api:2.14.2-193.v422b_efce56e0
jquery:1.12.4-3
jquery3-api:3.7.1-687.v68d468e40b_30
jsch:0.2.16-95.v3eecb_55fa_b_78
json-api:20260522-217.v0b_18b_8cd4672
json-path-api:3.0.0-218.vcd4dd1355de2
jsoup:1.22.2-95.vc5d00f1eb_42d
junit:1403.vd9d1413fd205
katalon:1.0.34
label-linked-jobs:6.0.1
leastload:71.vb_585f7a_dc4f5
locale:641.v84f22d75fd8b_
mailer:534.v1b_36f5864073
mapdb-api:1.0.9-44.va_1e1310c9118
matlab:1118.va_a_23b_76c161a_
matrix-auth:3.2.10
matrix-project:870.v9db_fcfc2f45b_
maven-plugin:3.27
metrics:4.2.37-494.v06f9a_939d33a_
mina-sshd-api-common:2.17.1-187.v0341274c2905
mina-sshd-api-core:2.17.1-187.v0341274c2905
msbuild:1.42
nunit:648.vdc8c6431f464
okhttp-api:5.3.2-200.vedb_720a_cf1f8
oss-symbols-api:456.v46e634a_63b_99
parameterized-trigger:893.va_383a_9b_a_4c11
pipeline-build-step:584.vdb_a_2cc3a_d07a_
pipeline-graph-analysis:254.v0f63a_a_447dca_
pipeline-graph-view:918.vf572523124f2
pipeline-groovy-lib:798.v5cc688825312
pipeline-input-step:551.vdff487c5998c
pipeline-milestone-step:152.v6e22b_8cfc66c
pipeline-model-api:2.2289.v6f731d0a_02da_
pipeline-model-definition:2.2289.v6f731d0a_02da_
pipeline-model-extensions:2.2289.v6f731d0a_02da_
pipeline-rest-api:2.41
pipeline-stage-step:345.va_96187909426
pipeline-stage-tags-metadata:2.2289.v6f731d0a_02da_
pipeline-stage-view:2.41
pipeline-utility-steps:3.810.va_7672d206740
plain-credentials:199.v9f8e1f741799
plot:2.4.0
plugin-usage-plugin:418.v308c3c863d25
plugin-util-api:7.1341.v039f146993d9
prism-api:1.30.0-727.vc475481f034d
pubsub-light:1.19
ranorex-integration:1.0.2
run-condition:276.v97298f3a_cd51
scm-api:728.vc30dcf7a_0df5
script-security:1402.v94c9ce464861
sloccount:1.27
snakeyaml-api:2.5-149.v72471e9c6371
snakeyaml-engine-api:3.0.1-5.vd98ea_ff3b_92e
sse-gateway:1.29
ssh-agent:396.vcc7d84e622ec
ssh-credentials:372.va_250881b_08cd
ssh-slaves:3.1097.v868116049892
sshd:3.384.vc89b_5e138cf9
structs:362.va_b_695ef4fdf9
subversion:1303.vcfd9679fb_c12
test-results-analyzer:309.vda_3a_a_f100542
text-finder:1.33
theme-manager:346.v06cca_64c6a_37
thinBackup:2.1.4
timestamper:1.30
token-macro:477.vd4f0dc3cb_cf1
trilead-api:2.284.v1974ea_324382
variant:70.va_d9f17f859e0
versioncolumn:400.v3c5c3004f31d
warnings-ng:13.10097.v277a_958a_b_c09
woodstox-core-api:7.1.1-1.v4d297985f397
workflow-aggregator:608.v67378e9d3db_1
workflow-api:1413.v2ff1a_5e720fa_
workflow-basic-steps:1098.v808b_fd7f8cf4
workflow-cps:4331.v9d06ed4658ff
workflow-durable-task-step:1479.v56e587f413a_7
workflow-job:1571.1580.v18e46842c125
workflow-multibranch:821.vc3b_4ea_780798
workflow-scm-step:466.va_d69e602552b_
workflow-step-api:724.v538c2362b_dfb_
workflow-support:1015.v785e5a_b_b_8b_22
xray-connector:2.6.2

```

### What Operating System are you using (both controller, and any agents involved in the problem)?

Controller: Linux
Agent: Windows

### Reproduction steps

1. Configure a multibranch pipeline (GitLab MR setup) using Warnings NG + git-forensics:
```groovy
mineRepository(scm: scmId)

discoverGitReferenceBuild(
scm: scmId,
maxCommits: 1000,
skipUnknownCommits: true
)
2. Run builds normally to establish a baseline.
3. Perform a rebase or force-push that removes older commits from the repository history.
4. Trigger a new MR build.

### Expected Results

If a commit referenced by git-forensics no longer exists:

- the commit should be ignored
- delta computation should skip invalid commits or be disabled
- the analysis should continue without failing

### Actual Results

- Build fails during delta computation with:
```
org.eclipse.jgit.errors.MissingObjectException:
Missing unknown 123412351234
```
- The error occurs even though:
- the repository is valid (git fsck --full shows no issues)
- the commit cannot be fetched (git fetch origin fails)
- the workspace is freshly cloned

### Anything else?

- The missing commit is stored in the plugin’s internal state:
```
GitCommitsRecord (reference build #45):
latest: 123412351234
```
- This commit is no longer part of the Git repository (likely removed via rebase or force push).
- During delta computation (DeltaRepositoryCallback.calculateDelta()), the plugin attempts to resolve this commit via JGit without verifying its existence, leading to a crash.
- MR builds always fall back to the latest successful target branch build, even if that build references commits no longer present in the repository.
- skipUnknownCommits does not prevent this failure because it is not applied during delta calculation.

## Impact

- MR builds fail after rebases or force pushes
- Cleaning workspace and deleting builds does not resolve the issue
- Breaks normal Git workflows with rewritten history

## Related issues

This appears to be related to:
- https://github.com/jenkinsci/git-forensics-plugin/issues/1168

That issue describes incorrect behavior when a previously recorded commit no longer exists.
However, in this case, the same situation leads to a `MissingObjectException` during delta computation, causing build failure instead of degraded results.

### Are you interested in contributing a fix?

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at DeltaRepositoryCallback.calculateDelta() and inspect how the GitCommitsRecord for reference build #45 is resolved, using the reported MissingObjectException and the skipUnknownCommits behavior as context. Reproduce with a rebased or force-pushed repository, then verify that an unavailable commit is skipped or disables delta computation without failing the MR build.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.