diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-30 11:43:55 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2026-03-30 16:29:22 +0000 |
| commit | e3276e74bc45cb4fb8f158b8249bee3d12a0805f (patch) | |
| tree | cbf4531b6e85eb1cc3e75a36ec058fe2f83d75f3 /src/lib | |
| parent | 33a72aa745ea6b6594bacfb71ea8ff2778f9b748 (diff) | |
fix(patch): accept reconstructed OID when commit id mismatch occurs
When applying a patch, if the reconstructed commit OID doesn't match
the tagged commit id (after the existing amend attempt), accept the
reconstructed OID rather than erroring. The diff is applied correctly
regardless of the mismatch; apply_patch_chain already threads the
actual OID forward via next_parent_override so the chain remains
consistent.
Mismatches can occur for several reasons: GPG-signed commits where
libgit2's commit_create_buffer produces subtly different bytes than
the original git commit, patches produced with non-standard tooling,
or edge cases like the diff.noprefix issue fixed in 7a36aed.
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/git/mod.rs | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index f9ce043..641349c 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs | |||
| @@ -773,13 +773,17 @@ impl RepoActions for Repo { | |||
| 773 | ) | 773 | ) |
| 774 | .context("failed to amend commit to produce new oid")?; | 774 | .context("failed to amend commit to produce new oid")?; |
| 775 | } | 775 | } |
| 776 | if !applied_oid.to_string().eq(commit_id) && pgp_sig.is_none() { | 776 | // If the OID still doesn't match after the amend, accept |
| 777 | bail!( | 777 | // the amend result and continue. The amend always produces |
| 778 | "when applied the patch commit id ({}) doesn't match the one specified in the event tag ({})", | 778 | // an unsigned commit (git_commit_amend goes through |
| 779 | applied_oid, | 779 | // git_commit__create_internal, not |
| 780 | get_commit_id_from_patch(patch)?, | 780 | // commit_create_with_signature) so any GPG sig |
| 781 | ); | 781 | // from the original is stripped — correct |
| 782 | } | 782 | // behaviour since the reconstructed commit object differs |
| 783 | // from what was originally signed. The diff is applied | ||
| 784 | // correctly regardless. apply_patch_chain threads the actual | ||
| 785 | // OID forward via next_parent_override so the chain remains | ||
| 786 | // consistent. | ||
| 783 | } | 787 | } |
| 784 | } | 788 | } |
| 785 | self.git_repo.set_index(&mut existing_index)?; | 789 | self.git_repo.set_index(&mut existing_index)?; |