diff options
author | Toon Claes <toon@gitlab.com> | 2022-07-13 18:01:17 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2022-07-18 12:04:56 +0300 |
commit | d052f272062fcf4a730eaf18511542538a68aa53 (patch) | |
tree | 9376995a671ecbe457fb66840b5af698f47620b4 | |
parent | 0794639e74b217d79944d7af64886c3292de3783 (diff) |
gittest: Validate hashes using correct oid format
When a repository is configured to use sha256 hashes, the validation of
commit hashes should be adapted to expect the correct length of object
ids. This change uses the correct validator depending on go build tag
gitaly_test_sha256.
-rw-r--r-- | internal/git/gittest/commit.go | 2 | ||||
-rw-r--r-- | internal/git/gittest/sha1.go | 9 | ||||
-rw-r--r-- | internal/git/gittest/sha256.go | 12 |
3 files changed, 22 insertions, 1 deletions
diff --git a/internal/git/gittest/commit.go b/internal/git/gittest/commit.go index d0a3f9a01..2cbb69280 100644 --- a/internal/git/gittest/commit.go +++ b/internal/git/gittest/commit.go @@ -210,7 +210,7 @@ func WriteCommit(t testing.TB, cfg config.Cfg, repoPath string, opts ...WriteCom Stdin: stdin, Env: env, }, commitArgs...) - oid, err := git.NewObjectIDFromHex(text.ChompBytes(stdout)) + oid, err := NewObjectIDFromHex(text.ChompBytes(stdout)) require.NoError(t, err) if writeCommitConfig.branch != "" { diff --git a/internal/git/gittest/sha1.go b/internal/git/gittest/sha1.go index 4630cf524..7246c400a 100644 --- a/internal/git/gittest/sha1.go +++ b/internal/git/gittest/sha1.go @@ -2,4 +2,13 @@ package gittest +import "gitlab.com/gitlab-org/gitaly/v15/internal/git" + var initRepoExtraArgs = []string{} + +// NewObjectIDFromHex constructs a new ObjectID from the given hex +// representation of the object ID. Returns ErrInvalidObjectID if the given +// OID is not valid. +func NewObjectIDFromHex(hex string) (git.ObjectID, error) { + return git.NewObjectIDFromHex(hex) +} diff --git a/internal/git/gittest/sha256.go b/internal/git/gittest/sha256.go index 791e429df..5d5bc243a 100644 --- a/internal/git/gittest/sha256.go +++ b/internal/git/gittest/sha256.go @@ -2,4 +2,16 @@ package gittest +import ( + "gitlab.com/gitlab-org/gitaly/v15/internal/git" + "gitlab.com/gitlab-org/gitaly/v15/internal/git/sha256" +) + var initRepoExtraArgs = []string{"--object-format=sha256"} + +// NewObjectIDFromHex constructs a new ObjectID from the given hex +// representation of the object ID. Returns ErrInvalidObjectID if the given +// OID is not valid. +func NewObjectIDFromHex(hex string) (git.ObjectID, error) { + return sha256.NewObjectIDFromHex(hex) +} |