This commit is contained in:
Lunny Xiao 2025-07-19 18:02:28 -07:00
parent be18643bfd
commit 68e5b28e7d
No known key found for this signature in database
GPG Key ID: C3B7C91B632F738A
2 changed files with 25 additions and 1 deletions

View File

@ -4,6 +4,7 @@
package git
import (
"path/filepath"
"strings"
"testing"
@ -196,7 +197,7 @@ func TestParseDiffHunkString(t *testing.T) {
}
func Test_GetAffectedHunksForTwoCommitsSpecialFile(t *testing.T) {
repoPath := "./tests/repos/repo4_commitsbetween"
repoPath := filepath.Join(testReposDir, "repo4_commitsbetween")
hunks, err := GetAffectedHunksForTwoCommitsSpecialFile(t.Context(), repoPath, "fdc1b615bdcff0f0658b216df0c9209e5ecb7c78", "a78e5638b66ccfe7e1b4689d3d5684e42c97d7ca", "test.txt")
assert.NoError(t, err)
assert.Len(t, hunks, 1)

View File

@ -148,3 +148,26 @@ func TestCommitsByFileAndRange(t *testing.T) {
require.NoError(t, err)
assert.Len(t, commits, 1)
}
func Test_CommitIDsBetween(t *testing.T) {
defer test.MockVariableValue(&setting.Git.CommitsRangeSize, 2)()
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := openRepositoryWithDefaultContext(bareRepo1Path)
require.NoError(t, err)
defer bareRepo1.Close()
// Test with empty beforeCommitID
commitIDs, err := CommitIDsBetween(bareRepo1.Ctx, bareRepo1.Path, "", "master")
require.NoError(t, err)
assert.Len(t, commitIDs, 7)
assert.Equal(t, "ce064814f4a0d337b333e646ece456cd39fab612", commitIDs[0])
assert.Equal(t, "95bb4d39648ee7e325106df01a621c530863a653", commitIDs[6])
// Test with a specific beforeCommitID
commitIDs, err = CommitIDsBetween(bareRepo1.Ctx, bareRepo1.Path, "37991dec2c8e592043f47155ce4808d4580f9123", "master")
require.NoError(t, err)
assert.Len(t, commitIDs, 2)
assert.Equal(t, "ce064814f4a0d337b333e646ece456cd39fab612", commitIDs[0])
assert.Equal(t, "feaf4ba6bc635fec442f46ddd4512416ec43c2c2", commitIDs[1])
}