Skip to content

Commit

Permalink
Respect submodules: false in git resource
Browse files Browse the repository at this point in the history
Fixes #1727. In #1531, the submodules parameter was added, but it has no
influence on the generated git-init invocation.
  • Loading branch information
Lyra Naeseth authored and tekton-robot committed Dec 12, 2019
1 parent 7d3ea04 commit 63e0dcd
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 32 deletions.
9 changes: 7 additions & 2 deletions pkg/apis/pipeline/v1alpha1/git_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,21 @@ func (s *GitResource) Replacements() map[string]string {
"type": string(s.Type),
"url": s.URL,
"revision": s.Revision,
"depth": strconv.FormatUint(uint64(s.Depth), 10),
}
}

// GetInputTaskModifier returns the TaskModifier to be used when this resource is an input.
func (s *GitResource) GetInputTaskModifier(_ *TaskSpec, path string) (TaskModifier, error) {
args := []string{"-url", s.URL,
args := []string{
"-url", s.URL,
"-revision", s.Revision,
"-path", path,
}

args = append(args, []string{"-path", path}...)
if !s.Submodules {
args = append(args, "-submodules", "false")
}

step := Step{
Container: corev1.Container{
Expand Down
96 changes: 66 additions & 30 deletions pkg/apis/pipeline/v1alpha1/git_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,37 +140,73 @@ func Test_GitResource_Replacements(t *testing.T) {
func Test_GitResource_GetDownloadTaskModifier(t *testing.T) {
names.TestingSeed()

r := &v1alpha1.GitResource{
Name: "git-resource",
Type: v1alpha1.PipelineResourceTypeGit,
URL: "git@github.com:test/test.git",
Revision: "master",
GitImage: "override-with-git:latest",
}

ts := v1alpha1.TaskSpec{}
modifier, err := r.GetInputTaskModifier(&ts, "/test/test")
if err != nil {
t.Fatalf("Unexpected error getting GetDownloadTaskModifier: %s", err)
}

want := []v1alpha1.Step{{Container: corev1.Container{
Name: "git-source-git-resource-9l9zj",
Image: "override-with-git:latest",
Command: []string{"/ko-app/git-init"},
Args: []string{
"-url",
"git@github.com:test/test.git",
"-revision",
"master",
"-path",
"/test/test",
for _, tc := range []struct {
desc string
gitResource *v1alpha1.GitResource
want corev1.Container
}{{
desc: "With basic values",
gitResource: &v1alpha1.GitResource{
Name: "git-resource",
Type: v1alpha1.PipelineResourceTypeGit,
URL: "git@github.com:test/test.git",
Revision: "master",
GitImage: "override-with-git:latest",
Submodules: true,
},
WorkingDir: "/workspace",
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}},
}}}
want: corev1.Container{
Name: "git-source-git-resource-9l9zj",
Image: "override-with-git:latest",
Command: []string{"/ko-app/git-init"},
Args: []string{
"-url",
"git@github.com:test/test.git",
"-revision",
"master",
"-path",
"/test/test",
},
WorkingDir: "/workspace",
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}},
},
}, {
desc: "Without submodules",
gitResource: &v1alpha1.GitResource{
Name: "git-resource",
Type: v1alpha1.PipelineResourceTypeGit,
URL: "git@github.com:test/test.git",
Revision: "master",
GitImage: "override-with-git:latest",
Submodules: false,
},
want: corev1.Container{
Name: "git-source-git-resource-mz4c7",
Image: "override-with-git:latest",
Command: []string{"/ko-app/git-init"},
Args: []string{
"-url",
"git@github.com:test/test.git",
"-revision",
"master",
"-path",
"/test/test",
"-submodules",
"false",
},
WorkingDir: "/workspace",
Env: []corev1.EnvVar{{Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}},
},
}} {
t.Run(tc.desc, func(t *testing.T) {
ts := v1alpha1.TaskSpec{}
modifier, err := tc.gitResource.GetInputTaskModifier(&ts, "/test/test")
if err != nil {
t.Fatalf("Unexpected error getting GetDownloadTaskModifier: %s", err)
}

if diff := cmp.Diff(want, modifier.GetStepsToPrepend()); diff != "" {
t.Errorf("Mismatch of GitResource DownloadContainerSpec: %s", diff)
if diff := cmp.Diff([]v1alpha1.Step{{Container: tc.want}}, modifier.GetStepsToPrepend()); diff != "" {
t.Errorf("Mismatch of GitResource DownloadContainerSpec: %s", diff)
}
})
}
}

0 comments on commit 63e0dcd

Please sign in to comment.