Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parentCommit invalid memory address or nil pointer dereference. #33204

Merged
merged 11 commits into from
Jan 19, 2025
Prev Previous commit
Next Next commit
Add test
hiifong committed Jan 14, 2025

Verified

This commit was signed with the committer’s verified signature.
hiifong hiifong
commit 2a559c929aebc6dd1f66fac2404cf366efb6c27b
12 changes: 12 additions & 0 deletions services/gitdiff/gitdiff_test.go
Original file line number Diff line number Diff line change
@@ -667,3 +667,15 @@ func TestNoCrashes(t *testing.T) {
ParsePatch(db.DefaultContext, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(testcase.gitdiff), "")
}
}

func TestParentCommitNotExits(t *testing.T) {
gitRepo, err := git.OpenRepository(git.DefaultContext, "./testdata/parent-commit-not-exits")
require.NoError(t, err)
defer gitRepo.Close()

diff, err := GetDiff(git.DefaultContext, gitRepo, &DiffOptions{
AfterCommitID: "d01637fe74c3727d9d1e5f691f343988d3e5342f",
})
assert.ErrorContains(t, err, "object does not exist [id: af35b81c4c8bd963b77b51b207ae4dc90e1904af, rel_path: ]")
assert.Nil(t, diff)
}