1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// +build static,system_libgit2
package main
import (
"bytes"
"fmt"
"testing"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/git/lstree"
"gitlab.com/gitlab-org/gitaly/internal/git2go"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper/testcfg"
)
func TestSubmodule(t *testing.T) {
commitMessage := []byte("Update Submodule message")
testCases := []struct {
desc string
command git2go.SubmoduleCommand
expectedStderr string
}{
{
desc: "Update submodule",
command: git2go.SubmoduleCommand{
AuthorName: string(testhelper.TestUser.Name),
AuthorMail: string(testhelper.TestUser.Email),
Message: string(commitMessage),
CommitSHA: "41fa1bc9e0f0630ced6a8a211d60c2af425ecc2d",
Submodule: "gitlab-grack",
Branch: "master",
},
},
{
desc: "Update submodule inside folder",
command: git2go.SubmoduleCommand{
AuthorName: string(testhelper.TestUser.Name),
AuthorMail: string(testhelper.TestUser.Email),
Message: string(commitMessage),
CommitSHA: "e25eda1fece24ac7a03624ed1320f82396f35bd8",
Submodule: "test_inside_folder/another_folder/six",
Branch: "submodule_inside_folder",
},
},
{
desc: "Invalid branch",
command: git2go.SubmoduleCommand{
AuthorName: string(testhelper.TestUser.Name),
AuthorMail: string(testhelper.TestUser.Email),
Message: string(commitMessage),
CommitSHA: "e25eda1fece24ac7a03624ed1320f82396f35bd8",
Submodule: "test_inside_folder/another_folder/six",
Branch: "non/existent",
},
expectedStderr: "Invalid branch",
},
{
desc: "Invalid submodule",
command: git2go.SubmoduleCommand{
AuthorName: string(testhelper.TestUser.Name),
AuthorMail: string(testhelper.TestUser.Email),
Message: string(commitMessage),
CommitSHA: "e25eda1fece24ac7a03624ed1320f82396f35bd8",
Submodule: "non-existent-submodule",
Branch: "master",
},
expectedStderr: "Invalid submodule path",
},
{
desc: "Duplicate reference",
command: git2go.SubmoduleCommand{
AuthorName: string(testhelper.TestUser.Name),
AuthorMail: string(testhelper.TestUser.Email),
Message: string(commitMessage),
CommitSHA: "409f37c4f05865e4fb208c771485f211a22c4c2d",
Submodule: "six",
Branch: "master",
},
expectedStderr: "The submodule six is already at 409f37c4f",
},
}
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
cfg, repoProto, repoPath := testcfg.BuildWithRepo(t)
testhelper.ConfigureGitalyGit2GoBin(t, cfg)
repo := localrepo.New(git.NewExecCommandFactory(cfg), repoProto, cfg)
tc.command.Repository = repoPath
ctx, cancel := testhelper.Context()
defer cancel()
response, err := tc.command.Run(ctx, cfg)
if tc.expectedStderr != "" {
require.Error(t, err)
require.Contains(t, err.Error(), tc.expectedStderr)
return
}
require.NoError(t, err)
commit, err := repo.ReadCommit(ctx, git.Revision(response.CommitID))
require.NoError(t, err)
require.Equal(t, commit.Author.Email, testhelper.TestUser.Email)
require.Equal(t, commit.Committer.Email, testhelper.TestUser.Email)
require.Equal(t, commit.Subject, commitMessage)
entry := testhelper.MustRunCommand(
t,
nil,
"git",
"-C",
repoPath,
"ls-tree",
"-z",
fmt.Sprintf("%s^{tree}:", response.CommitID),
tc.command.Submodule,
)
parser := lstree.NewParser(bytes.NewReader(entry))
parsedEntry, err := parser.NextEntry()
require.NoError(t, err)
require.Equal(t, tc.command.Submodule, parsedEntry.Path)
require.Equal(t, tc.command.CommitSHA, parsedEntry.Oid)
})
}
}
|