mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 06:35:59 +00:00
fix: ignore existence of commits for force pushes (#9262)
- Because we wish to show the status of the old and new commit of a force push, ignore that the commit doesn't exist and return a commit with only its ID filled. This is enough to still show the CI status of this commit although the commit itself is no longer reachable. - Add unit test. - Add integration test. - Resolves forgejo/forgejo#9250 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9262 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org> Co-authored-by: Gusted <postmaster@gusted.xyz> Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
parent
60cab1bafd
commit
b816bf9232
6 changed files with 81 additions and 5 deletions
|
@ -458,14 +458,28 @@ func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error)
|
|||
return branches, nil
|
||||
}
|
||||
|
||||
// GetCommitsFromIDs get commits from commit IDs
|
||||
func (repo *Repository) GetCommitsFromIDs(commitIDs []string) []*Commit {
|
||||
// GetCommitsFromIDs get commits from commit IDs. If ignoreExistence is
|
||||
// specified, then commits that no longer exists are still returned but
|
||||
// without any information except the ID.
|
||||
func (repo *Repository) GetCommitsFromIDs(commitIDs []string, ignoreExistence bool) []*Commit {
|
||||
commits := make([]*Commit, 0, len(commitIDs))
|
||||
|
||||
for _, commitID := range commitIDs {
|
||||
commit, err := repo.GetCommit(commitID)
|
||||
if err == nil && commit != nil {
|
||||
commits = append(commits, commit)
|
||||
} else if ignoreExistence && IsErrNotExist(err) {
|
||||
// It's entirely possible the commit no longer exists, we only care
|
||||
// about the status and verification. Verification is no longer possible,
|
||||
// but getting the status is still possible with just the ID. We do have
|
||||
// to assumme the commitID is not shortened, we cannot recover the full
|
||||
// commitID.
|
||||
id, err := NewIDFromString(commitID)
|
||||
if err == nil {
|
||||
commits = append(commits, &Commit{
|
||||
ID: id,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue