From 68e5b28e7df1b608d93cfc19c8a7233a3d60da37 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sat, 19 Jul 2025 18:02:28 -0700 Subject: [PATCH] add test --- modules/git/diff_test.go | 3 ++- modules/git/repo_commit_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/modules/git/diff_test.go b/modules/git/diff_test.go index 4f124648af0..4ff5763bc00 100644 --- a/modules/git/diff_test.go +++ b/modules/git/diff_test.go @@ -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) diff --git a/modules/git/repo_commit_test.go b/modules/git/repo_commit_test.go index e9f469accdf..cf964e66d9b 100644 --- a/modules/git/repo_commit_test.go +++ b/modules/git/repo_commit_test.go @@ -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]) +}