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:
authorIgor Drozdov <idrozdov@gitlab.com>2020-10-20 11:36:46 +0300
committerIgor Drozdov <idrozdov@gitlab.com>2020-11-04 10:34:54 +0300
commit1e2963ad1f0233084e8010413fe0b032419c3781 (patch)
tree0cf27d93dfddcb30fee76466f526079ebda3968d /cmd/gitaly-git2go
parentd66d46a0832214cd64cadf0fefd25939178c3416 (diff)
Move cmd conflicts in a separate package
Diffstat (limited to 'cmd/gitaly-git2go')
-rw-r--r--cmd/gitaly-git2go/conflicts/conflicts.go (renamed from cmd/gitaly-git2go/conflicts.go)9
-rw-r--r--cmd/gitaly-git2go/conflicts/conflicts_test.go (renamed from cmd/gitaly-git2go/conflicts_test.go)17
-rw-r--r--cmd/gitaly-git2go/main.go4
-rw-r--r--cmd/gitaly-git2go/merge_test.go44
-rw-r--r--cmd/gitaly-git2go/revert_test.go17
-rw-r--r--cmd/gitaly-git2go/testhelper/testhelper.go48
6 files changed, 82 insertions, 57 deletions
diff --git a/cmd/gitaly-git2go/conflicts.go b/cmd/gitaly-git2go/conflicts/conflicts.go
index 85f3c5a9c..ac29e68cf 100644
--- a/cmd/gitaly-git2go/conflicts.go
+++ b/cmd/gitaly-git2go/conflicts/conflicts.go
@@ -1,6 +1,6 @@
// +build static,system_libgit2
-package main
+package conflicts
import (
"context"
@@ -17,11 +17,12 @@ import (
"google.golang.org/grpc/status"
)
-type conflictsSubcommand struct {
+// Subcommand contains params to performs conflicts calculation from main
+type Subcommand struct {
request string
}
-func (cmd *conflictsSubcommand) Flags() *flag.FlagSet {
+func (cmd *Subcommand) Flags() *flag.FlagSet {
flags := flag.NewFlagSet("conflicts", flag.ExitOnError)
flags.StringVar(&cmd.request, "request", "", "git2go.ConflictsCommand")
return flags
@@ -83,7 +84,7 @@ func conflictError(code codes.Code, message string) error {
}
// Run performs a merge and prints resulting conflicts to stdout.
-func (cmd *conflictsSubcommand) Run(context.Context, io.Reader, io.Writer) error {
+func (cmd *Subcommand) Run(context.Context, io.Reader, io.Writer) error {
request, err := git2go.ConflictsCommandFromSerialized(cmd.request)
if err != nil {
return err
diff --git a/cmd/gitaly-git2go/conflicts_test.go b/cmd/gitaly-git2go/conflicts/conflicts_test.go
index 4cef16c12..f1bf44ed0 100644
--- a/cmd/gitaly-git2go/conflicts_test.go
+++ b/cmd/gitaly-git2go/conflicts/conflicts_test.go
@@ -1,16 +1,25 @@
// +build static,system_libgit2
-package main
+package conflicts
import (
+ "os"
"testing"
"github.com/stretchr/testify/require"
+ cmdtesthelper "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/git2go"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
)
+func TestMain(m *testing.M) {
+ defer testhelper.MustHaveNoChildProcess()
+ testhelper.Configure()
+ testhelper.ConfigureGitalyGit2Go()
+ os.Exit(m.Run())
+}
+
func TestConflicts(t *testing.T) {
testcases := []struct {
desc string
@@ -165,9 +174,9 @@ func TestConflicts(t *testing.T) {
_, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- base := buildCommit(t, repoPath, nil, tc.base)
- ours := buildCommit(t, repoPath, base, tc.ours)
- theirs := buildCommit(t, repoPath, base, tc.theirs)
+ base := cmdtesthelper.BuildCommit(t, repoPath, nil, tc.base)
+ ours := cmdtesthelper.BuildCommit(t, repoPath, base, tc.ours)
+ theirs := cmdtesthelper.BuildCommit(t, repoPath, base, tc.theirs)
t.Run(tc.desc, func(t *testing.T) {
ctx, cancel := testhelper.Context()
diff --git a/cmd/gitaly-git2go/main.go b/cmd/gitaly-git2go/main.go
index 68c9a8a0b..488300ba2 100644
--- a/cmd/gitaly-git2go/main.go
+++ b/cmd/gitaly-git2go/main.go
@@ -8,6 +8,8 @@ import (
"fmt"
"io"
"os"
+
+ "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/conflicts"
)
type subcmd interface {
@@ -16,8 +18,8 @@ type subcmd interface {
}
var subcommands = map[string]subcmd{
- "conflicts": &conflictsSubcommand{},
"commit": commitSubcommand{},
+ "conflicts": &conflicts.Subcommand{},
"merge": &mergeSubcommand{},
"revert": &revertSubcommand{},
"resolve": &resolveSubcommand{},
diff --git a/cmd/gitaly-git2go/merge_test.go b/cmd/gitaly-git2go/merge_test.go
index c201560a0..0a2b6bbab 100644
--- a/cmd/gitaly-git2go/merge_test.go
+++ b/cmd/gitaly-git2go/merge_test.go
@@ -9,6 +9,7 @@ import (
git "github.com/libgit2/git2go/v30"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ cmdtesthelper "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/git2go"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -82,43 +83,6 @@ func TestMergeFailsWithInvalidRepositoryPath(t *testing.T) {
require.Contains(t, err.Error(), "merge: could not open repository")
}
-func buildCommit(t testing.TB, repoPath string, parent *git.Oid, fileContents map[string]string) *git.Oid {
- repo, err := git.OpenRepository(repoPath)
- require.NoError(t, err)
- defer repo.Free()
-
- odb, err := repo.Odb()
- require.NoError(t, err)
-
- treeBuilder, err := repo.TreeBuilder()
- require.NoError(t, err)
-
- for file, contents := range fileContents {
- oid, err := odb.Write([]byte(contents), git.ObjectBlob)
- require.NoError(t, err)
- treeBuilder.Insert(file, oid, git.FilemodeBlob)
- }
-
- tree, err := treeBuilder.Write()
- require.NoError(t, err)
-
- committer := git.Signature{
- Name: "Foo",
- Email: "foo@example.com",
- When: time.Date(2020, 1, 1, 1, 1, 1, 1, time.FixedZone("UTC+2", 2*60*60)),
- }
-
- var commit *git.Oid
- if parent != nil {
- commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree, parent)
- } else {
- commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree)
- }
- require.NoError(t, err)
-
- return commit
-}
-
func TestMergeTrees(t *testing.T) {
testcases := []struct {
desc string
@@ -210,9 +174,9 @@ func TestMergeTrees(t *testing.T) {
_, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- base := buildCommit(t, repoPath, nil, tc.base)
- ours := buildCommit(t, repoPath, base, tc.ours)
- theirs := buildCommit(t, repoPath, base, tc.theirs)
+ base := cmdtesthelper.BuildCommit(t, repoPath, nil, tc.base)
+ ours := cmdtesthelper.BuildCommit(t, repoPath, base, tc.ours)
+ theirs := cmdtesthelper.BuildCommit(t, repoPath, base, tc.theirs)
authorDate := time.Date(2020, 7, 30, 7, 45, 50, 0, time.FixedZone("UTC+2", +2*60*60))
diff --git a/cmd/gitaly-git2go/revert_test.go b/cmd/gitaly-git2go/revert_test.go
index 6c62b9f93..8e6036baa 100644
--- a/cmd/gitaly-git2go/revert_test.go
+++ b/cmd/gitaly-git2go/revert_test.go
@@ -9,6 +9,7 @@ import (
git "github.com/libgit2/git2go/v30"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
+ cmdtesthelper "gitlab.com/gitlab-org/gitaly/cmd/gitaly-git2go/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/git2go"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -81,15 +82,15 @@ func TestRevert_trees(t *testing.T) {
{
desc: "trivial revert succeeds",
setupRepo: func(t testing.TB, repoPath string) (ours, revert string) {
- baseOid := buildCommit(t, repoPath, nil, map[string]string{
+ baseOid := cmdtesthelper.BuildCommit(t, repoPath, nil, map[string]string{
"a": "apple",
"b": "banana",
})
- revertOid := buildCommit(t, repoPath, baseOid, map[string]string{
+ revertOid := cmdtesthelper.BuildCommit(t, repoPath, baseOid, map[string]string{
"a": "apple",
"b": "pineapple",
})
- oursOid := buildCommit(t, repoPath, revertOid, map[string]string{
+ oursOid := cmdtesthelper.BuildCommit(t, repoPath, revertOid, map[string]string{
"a": "apple",
"b": "pineapple",
"c": "carrot",
@@ -109,13 +110,13 @@ func TestRevert_trees(t *testing.T) {
{
desc: "conflicting revert fails",
setupRepo: func(t testing.TB, repoPath string) (ours, revert string) {
- baseOid := buildCommit(t, repoPath, nil, map[string]string{
+ baseOid := cmdtesthelper.BuildCommit(t, repoPath, nil, map[string]string{
"a": "apple",
})
- revertOid := buildCommit(t, repoPath, baseOid, map[string]string{
+ revertOid := cmdtesthelper.BuildCommit(t, repoPath, baseOid, map[string]string{
"a": "pineapple",
})
- oursOid := buildCommit(t, repoPath, revertOid, map[string]string{
+ oursOid := cmdtesthelper.BuildCommit(t, repoPath, revertOid, map[string]string{
"a": "carrot",
})
@@ -126,7 +127,7 @@ func TestRevert_trees(t *testing.T) {
{
desc: "nonexistent ours fails",
setupRepo: func(t testing.TB, repoPath string) (ours, revert string) {
- revertOid := buildCommit(t, repoPath, nil, map[string]string{
+ revertOid := cmdtesthelper.BuildCommit(t, repoPath, nil, map[string]string{
"a": "apple",
})
@@ -137,7 +138,7 @@ func TestRevert_trees(t *testing.T) {
{
desc: "nonexistent revert fails",
setupRepo: func(t testing.TB, repoPath string) (ours, revert string) {
- oursOid := buildCommit(t, repoPath, nil, map[string]string{
+ oursOid := cmdtesthelper.BuildCommit(t, repoPath, nil, map[string]string{
"a": "apple",
})
diff --git a/cmd/gitaly-git2go/testhelper/testhelper.go b/cmd/gitaly-git2go/testhelper/testhelper.go
new file mode 100644
index 000000000..3a7a24b0d
--- /dev/null
+++ b/cmd/gitaly-git2go/testhelper/testhelper.go
@@ -0,0 +1,48 @@
+// +build static,system_libgit2
+
+package testhelper
+
+import (
+ "testing"
+ "time"
+
+ git "github.com/libgit2/git2go/v30"
+ "github.com/stretchr/testify/require"
+)
+
+func BuildCommit(t testing.TB, repoPath string, parent *git.Oid, fileContents map[string]string) *git.Oid {
+ repo, err := git.OpenRepository(repoPath)
+ require.NoError(t, err)
+ defer repo.Free()
+
+ odb, err := repo.Odb()
+ require.NoError(t, err)
+
+ treeBuilder, err := repo.TreeBuilder()
+ require.NoError(t, err)
+
+ for file, contents := range fileContents {
+ oid, err := odb.Write([]byte(contents), git.ObjectBlob)
+ require.NoError(t, err)
+ treeBuilder.Insert(file, oid, git.FilemodeBlob)
+ }
+
+ tree, err := treeBuilder.Write()
+ require.NoError(t, err)
+
+ committer := git.Signature{
+ Name: "Foo",
+ Email: "foo@example.com",
+ When: time.Date(2020, 1, 1, 1, 1, 1, 1, time.FixedZone("UTC+2", 2*60*60)),
+ }
+
+ var commit *git.Oid
+ if parent != nil {
+ commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree, parent)
+ } else {
+ commit, err = repo.CreateCommitFromIds("", &committer, &committer, "Message", tree)
+ }
+ require.NoError(t, err)
+
+ return commit
+}