Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Cai <johncai86@gmail.com>2022-12-30 00:32:45 +0300
committerJohn Cai <jcai@gitlab.com>2023-01-09 20:40:14 +0300
commita0ec0b89bbd0ffad1b5e56efe9cd9c0c18818537 (patch)
treee749d63571c0b4cc6bf275bf48099b57c9b3b812
parentbf9c2ffc098cc28a2c1fa3ab98931eab511063bf (diff)
localrepo: Add MustWriteBlob helper
Add a helper for writing test blobs in the localrepo. Going forward, this is meant to be the function to use in tests rather than the gittest package.
-rw-r--r--internal/git/gittest/objects.go1
-rw-r--r--internal/git/localrepo/objects.go11
2 files changed, 12 insertions, 0 deletions
diff --git a/internal/git/gittest/objects.go b/internal/git/gittest/objects.go
index d7499868f..7540b83f7 100644
--- a/internal/git/gittest/objects.go
+++ b/internal/git/gittest/objects.go
@@ -78,6 +78,7 @@ func WriteBlobs(tb testing.TB, cfg config.Cfg, testRepoPath string, n int) []str
}
// WriteBlob writes the given contents as a blob into the repository and returns its OID.
+// Deprecated: internal/git/localrepo package should e used for writing commits
func WriteBlob(tb testing.TB, cfg config.Cfg, testRepoPath string, contents []byte) git.ObjectID {
hex := text.ChompBytes(ExecOpts(tb, cfg, ExecConfig{Stdin: bytes.NewReader(contents)},
"-C", testRepoPath, "hash-object", "-w", "--stdin",
diff --git a/internal/git/localrepo/objects.go b/internal/git/localrepo/objects.go
index d34f6b11e..170326d1c 100644
--- a/internal/git/localrepo/objects.go
+++ b/internal/git/localrepo/objects.go
@@ -7,13 +7,16 @@ import (
"fmt"
"io"
"strings"
+ "testing"
"time"
+ "github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/v15/internal/command"
"gitlab.com/gitlab-org/gitaly/v15/internal/git"
"gitlab.com/gitlab-org/gitaly/v15/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/v15/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/v15/internal/metadata/featureflag"
+ "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb"
)
@@ -321,3 +324,11 @@ func (repo *Repo) IsAncestor(ctx context.Context, parent, child git.Revision) (b
return true, nil
}
+
+// WriteTestBlob is used to write blobs to repositories in tests
+func MustWriteBlob(tb testing.TB, repo *Repo, path, content string) git.ObjectID {
+ oid, err := repo.WriteBlob(testhelper.Context(tb), path, bytes.NewBufferString(content))
+ require.NoError(tb, err)
+
+ return oid
+}