diff options
author | John Cai <jcai@gitlab.com> | 2022-11-13 05:10:03 +0300 |
---|---|---|
committer | John Cai <jcai@gitlab.com> | 2023-03-07 21:55:12 +0300 |
commit | 573d18b37702af30b8792c305e4ba7b5800dc9fc (patch) | |
tree | ac111f1e7b515dd41b42e9c31cdddc0b4132ea7a /internal/gitaly/service/operations/submodules_test.go | |
parent | 50b8b65c9f6795eb4d3f9424eeae2af49bd9efa0 (diff) |
operations: Reimplement UserUpdateSubmodule using git plumbing commands
Updating a submodule is simply updating the oid of the commit at the
path. We can do this by manually rewriting trees and writing a new
commit. If we impelement it this way, we don't need to rely on Git2Go.
Diffstat (limited to 'internal/gitaly/service/operations/submodules_test.go')
-rw-r--r-- | internal/gitaly/service/operations/submodules_test.go | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go index 8047932fc..88d2306e7 100644 --- a/internal/gitaly/service/operations/submodules_test.go +++ b/internal/gitaly/service/operations/submodules_test.go @@ -4,6 +4,7 @@ package operations import ( "bytes" + "context" "fmt" "path/filepath" "testing" @@ -14,6 +15,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v15/internal/git/localrepo" "gitlab.com/gitlab-org/gitaly/v15/internal/git/lstree" "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/structerr" "gitlab.com/gitlab-org/gitaly/v15/internal/testhelper" "gitlab.com/gitlab-org/gitaly/v15/proto/go/gitalypb" @@ -22,7 +24,11 @@ import ( func TestUserUpdateSubmodule(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.SubmoduleInGit). + Run(t, testUserUpdateSubmodule) +} + +func testUserUpdateSubmodule(t *testing.T, ctx context.Context) { ctx, cfg, client := setupOperationsServiceWithoutRepo(t, ctx) type setupData struct { @@ -454,6 +460,38 @@ func TestUserUpdateSubmodule(t *testing.T) { }, }, { + desc: "failure due to invalid submodule path", + subPath: "sub", + branch: "master", + setup: func(repoPath, subRepoPath string, repoProto, subRepoProto *gitalypb.Repository) setupData { + subCommitID := gittest.WriteCommit(t, cfg, subRepoPath) + gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"), gittest.WithTreeEntries( + gittest.TreeEntry{ + Mode: "100644", + Path: ".gitmodules", + Content: fmt.Sprintf(`[submodule "%s"]\n\tpath = %s\n\turl = file://%s`, "sub", "sub", subRepoPath), + }, + gittest.TreeEntry{OID: subCommitID, Mode: "160000", Path: "sub"}, + )) + commitID := gittest.WriteCommit(t, cfg, subRepoPath, gittest.WithParents(subCommitID)) + + return setupData{ + request: &gitalypb.UserUpdateSubmoduleRequest{ + User: gittest.TestUser, + CommitSha: string(commitID), + Branch: []byte("master"), + Repository: repoProto, + Submodule: []byte("foobar/does/not/exist"), + CommitMessage: []byte("Updating Submodule: sub"), + }, + expectedResponse: &gitalypb.UserUpdateSubmoduleResponse{ + CommitError: "Invalid submodule path", + }, + verify: func(t *testing.T) {}, + } + }, + }, + { desc: "failure due to same submodule reference", subPath: "sub", branch: "master", @@ -485,6 +523,35 @@ func TestUserUpdateSubmodule(t *testing.T) { }, }, { + desc: "failure due to submodule path not pointing to a submodule", + subPath: "sub", + branch: "master", + setup: func(repoPath, subRepoPath string, repoProto, subRepoProto *gitalypb.Repository) setupData { + commitID := gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"), gittest.WithTreeEntries( + gittest.TreeEntry{ + Mode: "100644", + Path: "VERSION", + Content: "version string", + }, + )) + + return setupData{ + request: &gitalypb.UserUpdateSubmoduleRequest{ + Repository: repoProto, + User: gittest.TestUser, + CommitSha: commitID.String(), + Branch: []byte("master"), + Submodule: []byte("VERSION"), + CommitMessage: []byte("Updating Submodule: sub"), + }, + expectedResponse: &gitalypb.UserUpdateSubmoduleResponse{ + CommitError: "Invalid submodule path", + }, + verify: func(t *testing.T) {}, + } + }, + }, + { desc: "failure due to empty repository", subPath: "sub", branch: "master", |