mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-09-30 14:45:56 +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
|
@ -199,3 +199,40 @@ func TestCommitsByFileAndRange(t *testing.T) {
|
|||
assert.Len(t, commits, testCase.ExpectedCommitCount, "file: '%s', page: %d", testCase.File, testCase.Page)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetCommitsFromIDs(t *testing.T) {
|
||||
bareRepo1, err := openRepositoryWithDefaultContext(filepath.Join(testReposDir, "repo1_bare"))
|
||||
require.NoError(t, err)
|
||||
|
||||
commitIDs := []string{"2839944139e0de9737a044f78b0e4b40d989a9e3", "2839944139e0de9737a044f78b0e4b40d989a9e4"}
|
||||
|
||||
t.Run("Normal", func(t *testing.T) {
|
||||
commits := bareRepo1.GetCommitsFromIDs(commitIDs, false)
|
||||
if assert.Len(t, commits, 1) {
|
||||
assert.Equal(t, "2839944139e0de9737a044f78b0e4b40d989a9e3", commits[0].ID.String())
|
||||
assert.Equal(t, "Example User", commits[0].Author.Name)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Ignore existence", func(t *testing.T) {
|
||||
commits := bareRepo1.GetCommitsFromIDs(commitIDs, true)
|
||||
if assert.Len(t, commits, 2) {
|
||||
assert.Equal(t, "2839944139e0de9737a044f78b0e4b40d989a9e3", commits[0].ID.String())
|
||||
assert.Equal(t, "Example User", commits[0].Author.Name)
|
||||
|
||||
assert.Equal(t, "2839944139e0de9737a044f78b0e4b40d989a9e4", commits[1].ID.String())
|
||||
assert.Nil(t, commits[1].Author)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Not full commit ID", func(t *testing.T) {
|
||||
commits := bareRepo1.GetCommitsFromIDs(append(commitIDs, "abba"), true)
|
||||
if assert.Len(t, commits, 2) {
|
||||
assert.Equal(t, "2839944139e0de9737a044f78b0e4b40d989a9e3", commits[0].ID.String())
|
||||
assert.Equal(t, "Example User", commits[0].Author.Name)
|
||||
|
||||
assert.Equal(t, "2839944139e0de9737a044f78b0e4b40d989a9e4", commits[1].ID.String())
|
||||
assert.Nil(t, commits[1].Author)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue