diff --git a/modules/git/blame_sha256_test.go b/modules/git/blame_sha256_test.go index 01de0454a..92f8b5b02 100644 --- a/modules/git/blame_sha256_test.go +++ b/modules/git/blame_sha256_test.go @@ -11,6 +11,8 @@ import ( ) func TestReadingBlameOutputSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + ctx, cancel := context.WithCancel(context.Background()) defer cancel() diff --git a/modules/git/commit_sha256_test.go b/modules/git/commit_sha256_test.go index 82112cb40..916169f4e 100644 --- a/modules/git/commit_sha256_test.go +++ b/modules/git/commit_sha256_test.go @@ -14,6 +14,8 @@ import ( ) func TestCommitsCountSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") commitsCount, err := CommitsCount(DefaultContext, @@ -27,6 +29,8 @@ func TestCommitsCountSha256(t *testing.T) { } func TestCommitsCountWithoutBaseSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") commitsCount, err := CommitsCount(DefaultContext, @@ -41,6 +45,8 @@ func TestCommitsCountWithoutBaseSha256(t *testing.T) { } func TestGetFullCommitIDSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "f004f4") @@ -49,6 +55,8 @@ func TestGetFullCommitIDSha256(t *testing.T) { } func TestGetFullCommitIDErrorSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") id, err := GetFullCommitID(DefaultContext, bareRepo1Path, "unknown") @@ -59,6 +67,8 @@ func TestGetFullCommitIDErrorSha256(t *testing.T) { } func TestCommitFromReaderSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + commitString := `9433b2a62b964c17a4485ae180f45f595d3e69d31b786087775e28c6b6399df0 commit 1114 tree e7f9e96dd79c09b078cac8b303a7d3b9d65ff9b734e86060a4d20409fd379f9e parent 26e9ccc29fad747e9c5d9f4c9ddeb7eff61cc45ef6a8dc258cbeb181afc055e8 @@ -131,6 +141,8 @@ signed commit`, commitFromReader.Signature.Payload) } func TestHasPreviousCommitSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo1_bare_sha256") repo, err := openRepositoryWithDefaultContext(bareRepo1Path) @@ -159,6 +171,8 @@ func TestHasPreviousCommitSha256(t *testing.T) { } func TestGetCommitFileStatusMergesSha256(t *testing.T) { + skipIfSHA256NotSupported(t) + bareRepo1Path := filepath.Join(testReposDir, "repo6_merge_sha256") commitFileStatus, err := GetCommitFileStatus(DefaultContext, bareRepo1Path, "d2e5609f630dd8db500f5298d05d16def282412e3e66ed68cc7d0833b29129a1") diff --git a/modules/git/utils_test.go b/modules/git/utils_test.go new file mode 100644 index 000000000..876a22924 --- /dev/null +++ b/modules/git/utils_test.go @@ -0,0 +1,15 @@ +// Copyright 2024 The Forgejo Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +package git + +import "testing" + +// This file contains utility functions that are used across multiple tests, +// but not in production code. + +func skipIfSHA256NotSupported(t *testing.T) { + if isGogit || CheckGitVersionAtLeast("2.42") != nil { + t.Skip("skipping because installed Git version doesn't support SHA256") + } +}