radicle: Be more lenient when applying merge ops

Before this change, if a merge op referred to a commit that was not on
the default branch, the merge op and all descendant ops would be pruned.

This is a bad idea because the state of the default branch can change
*after* the merge op is created, which is out of the control of the
merge op author.

Therefore, instead of exiting, we keep processing ops (but ignore the
merge), in case the merge is invalid for this specific reason.
This commit is contained in:
Alexis Sellier 2023-05-25 10:28:02 +02:00
parent ac06e319cd
commit e18f01cab4
No known key found for this signature in database
1 changed files with 9 additions and 2 deletions

View File

@ -436,11 +436,18 @@ impl store::FromHistory for Patch {
}
let proj = doc.project()?;
let branch = git::refs::branch(proj.default_branch());
// Nb. We don't return an error in case the merge commit is not an
// ancestor of the default branch. The default branch can change
// *after* the merge action is created, which is out of the control
// of the merge author. We simply skip it, which allows archiving in
// case of a rebase off the master branch, or a redaction of the
// merge.
let Ok(head) = repo.reference_oid(&op.author, &branch) else {
return Err(ApplyError::InvalidMerge(op.id));
continue;
};
if commit != head && !repo.is_ancestor_of(commit, head)? {
return Err(ApplyError::InvalidMerge(op.id));
continue;
}
}
}