diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-07-05 13:49:37 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2023-07-06 15:16:15 +0300 |
commit | bde29630a350a48c7b571ef68545a994838ddb14 (patch) | |
tree | 0d949999ed9d6331dc5ece2fae01fd42e601b731 | |
parent | 0e51e48f8fe361f8b03cd4b4a64e88f30d2c7ef3 (diff) |
git: Drop `CheckRefNameFormat()`
We have converted all callsites of `CheckRefNameFormat()` to instead use
`git.ValidateReference()`, which is both more efficient and has better
error reporting. So let's drop `CheckRefNameFormat()`.
-rw-r--r-- | internal/git/reference.go | 30 | ||||
-rw-r--r-- | internal/git/reference_test.go | 43 |
2 files changed, 0 insertions, 73 deletions
diff --git a/internal/git/reference.go b/internal/git/reference.go index 22eed72fc..18f5bd716 100644 --- a/internal/git/reference.go +++ b/internal/git/reference.go @@ -1,12 +1,8 @@ package git import ( - "context" "fmt" - "io" "strings" - - "gitlab.com/gitlab-org/gitaly/v16/internal/command" ) // InternalReferenceType is the type of an internal reference. @@ -201,29 +197,3 @@ func ValidateReference(name string) error { name = tail } } - -// CheckRefFormat checks whether a fully-qualified refname is well -// well-formed using git-check-ref-format -func CheckRefFormat(ctx context.Context, gitCmdFactory CommandFactory, refName string) (bool, error) { - cmd, err := gitCmdFactory.NewWithoutRepo(ctx, - Command{ - Name: "check-ref-format", - Args: []string{refName}, - }, - WithStdout(io.Discard), - WithStderr(io.Discard), - ) - if err != nil { - return false, err - } - - if err := cmd.Wait(); err != nil { - if code, ok := command.ExitStatus(err); ok && code == 1 { - return false, nil - } - - return false, err - } - - return true, nil -} diff --git a/internal/git/reference_test.go b/internal/git/reference_test.go index 2b7645020..0f5e2bfaa 100644 --- a/internal/git/reference_test.go +++ b/internal/git/reference_test.go @@ -9,7 +9,6 @@ import ( "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly/v16/internal/git" "gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest" - "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v16/internal/testhelper/testcfg" ) @@ -183,48 +182,6 @@ func TestValidateReference(t *testing.T) { } } -func TestCheckRefFormat(t *testing.T) { - cfg := testcfg.Build(t) - ctx := testhelper.Context(t) - - gitCmdFactory := gittest.NewCommandFactory(t, cfg) - - for _, tc := range []struct { - desc string - tagName string - ok bool - }{ - // Just trivial tests here, most of this is tested in - // internal/gitaly/service/operations/tags_test.go - { - desc: "unqualified name", - tagName: "my-name", - ok: false, - }, - { - desc: "fully-qualified name", - tagName: "refs/heads/my-name", - ok: true, - }, - { - desc: "basic tag", - tagName: "refs/tags/my-tag", - ok: true, - }, - { - desc: "invalid tag", - tagName: "refs/tags/my tag", - ok: false, - }, - } { - t.Run(tc.desc, func(t *testing.T) { - ok, err := git.CheckRefFormat(ctx, gitCmdFactory, tc.tagName) - require.NoError(t, err) - require.Equal(t, tc.ok, ok) - }) - } -} - func TestReferenceName_NewReferenceNameFromBranchName(t *testing.T) { for _, tc := range []struct { desc string |