Refactor gitdiff test (#33507)

This commit is contained in:
wxiaoguang 2025-02-06 00:09:58 +08:00 committed by GitHub
parent 7e596bd7a9
commit fa0c8ae50f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 10 additions and 25 deletions

View File

@ -5,6 +5,7 @@
package gitdiff
import (
"context"
"strconv"
"strings"
"testing"
@ -628,23 +629,25 @@ func TestDiffLine_GetCommentSide(t *testing.T) {
}
func TestGetDiffRangeWithWhitespaceBehavior(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, "./testdata/academic-module")
gitRepo, err := git.OpenRepository(context.Background(), "../../modules/git/tests/repos/repo5_pulls")
require.NoError(t, err)
defer gitRepo.Close()
for _, behavior := range []git.TrustedCmdArgs{{"-w"}, {"--ignore-space-at-eol"}, {"-b"}, nil} {
diffs, err := GetDiff(db.DefaultContext, gitRepo,
diffs, err := GetDiff(context.Background(), gitRepo,
&DiffOptions{
AfterCommitID: "bd7063cc7c04689c4d082183d32a604ed27a24f9",
BeforeCommitID: "559c156f8e0178b71cb44355428f24001b08fc68",
AfterCommitID: "d8e0bbb45f200e67d9a784ce55bd90821af45ebd",
BeforeCommitID: "72866af952e98d02a73003501836074b286a78f6",
MaxLines: setting.Git.MaxGitDiffLines,
MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters,
MaxFiles: setting.Git.MaxGitDiffFiles,
MaxFiles: 1,
WhitespaceBehavior: behavior,
})
assert.NoError(t, err, "Error when diff with %s", behavior)
require.NoError(t, err, "Error when diff with WhitespaceBehavior=%s", behavior)
assert.True(t, diffs.IsIncomplete)
assert.Len(t, diffs.Files, 1)
for _, f := range diffs.Files {
assert.NotEmpty(t, f.Sections, "%s should have sections", f.Name)
assert.NotEmpty(t, f.Sections, "Diff file %q should have sections", f.Name)
}
}
}

View File

@ -1 +0,0 @@
ref: refs/heads/master

View File

@ -1,10 +0,0 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[branch "master"]
remote = origin
merge = refs/heads/master

Binary file not shown.

View File

@ -1 +0,0 @@
0000000000000000000000000000000000000000 bd7063cc7c04689c4d082183d32a604ed27a24f9 Lunny Xiao <xiaolunwen@gmail.com> 1574829684 +0800 clone: from https://try.gitea.io/shemgp-aiias/academic-module

View File

@ -1 +0,0 @@
0000000000000000000000000000000000000000 bd7063cc7c04689c4d082183d32a604ed27a24f9 Lunny Xiao <xiaolunwen@gmail.com> 1574829684 +0800 clone: from https://try.gitea.io/shemgp-aiias/academic-module

View File

@ -1 +0,0 @@
0000000000000000000000000000000000000000 bd7063cc7c04689c4d082183d32a604ed27a24f9 Lunny Xiao <xiaolunwen@gmail.com> 1574829684 +0800 clone: from https://try.gitea.io/shemgp-aiias/academic-module

View File

@ -1,2 +0,0 @@
# pack-refs with: peeled fully-peeled sorted
bd7063cc7c04689c4d082183d32a604ed27a24f9 refs/remotes/origin/master

View File

@ -1 +0,0 @@
bd7063cc7c04689c4d082183d32a604ed27a24f9

View File

@ -1 +0,0 @@
ref: refs/remotes/origin/master