diff --git a/pkg/apis/resource/v1alpha1/git/git_resource_test.go b/pkg/apis/resource/v1alpha1/git/git_resource_test.go index a36ce703ed2..2c2fb289f4f 100644 --- a/pkg/apis/resource/v1alpha1/git/git_resource_test.go +++ b/pkg/apis/resource/v1alpha1/git/git_resource_test.go @@ -675,6 +675,44 @@ func TestGitResource_GetDownloadTaskModifier(t *testing.T) { {Name: "NO_PROXY", Value: "no-proxy.git.com"}, }, }, + }, { + desc: "Without Refspec and without revision", + gitResource: &git.Resource{ + Name: "git-resource", + Type: resourcev1alpha1.PipelineResourceTypeGit, + URL: "git@github.com:test/test.git", + Revision: "", + Refspec: "", + GitImage: "override-with-git:latest", + Submodules: false, + Depth: 1, + SSLVerify: true, + HTTPProxy: "http-proxy.git.com", + HTTPSProxy: "https-proxy.git.com", + NOProxy: "no-proxy.git.com", + }, + want: corev1.Container{ + Name: "git-source-git-resource-twkr2", + Image: "override-with-git:latest", + Command: []string{"/ko-app/git-init"}, + Args: []string{ + "-url", + "git@github.com:test/test.git", + "-revision", + "", + "-path", + "/test/test", + "-submodules=false", + }, + WorkingDir: "/workspace", + Env: []corev1.EnvVar{ + {Name: "TEKTON_RESOURCE_NAME", Value: "git-resource"}, + {Name: "HOME", Value: pipeline.HomeDir}, + {Name: "HTTP_PROXY", Value: "http-proxy.git.com"}, + {Name: "HTTPS_PROXY", Value: "https-proxy.git.com"}, + {Name: "NO_PROXY", Value: "no-proxy.git.com"}, + }, + }, }} { t.Run(tc.desc, func(t *testing.T) { ts := v1beta1.TaskSpec{} diff --git a/pkg/git/git.go b/pkg/git/git.go index 7b5cc047f4d..9b30612d13c 100644 --- a/pkg/git/git.go +++ b/pkg/git/git.go @@ -65,7 +65,7 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error { } if spec.Revision == "" { - spec.Revision = "master" + spec.Revision = "HEAD" } if spec.Path != "" { if _, err := run(logger, "", "init", spec.Path); err != nil { @@ -85,7 +85,13 @@ func Fetch(logger *zap.SugaredLogger, spec FetchSpec) error { logger.Warnf("Failed to set http.sslVerify in git config: %s", err) return err } - + if spec.Revision == "" { + spec.Revision = "HEAD" + if _, err := run(logger, "", "symbolic-ref", spec.Revision, "refs/remotes/origin/HEAD"); err != nil { + return err + } + } + fetchArgs := []string{"fetch"} if spec.Submodules { fetchArgs = append(fetchArgs, "--recurse-submodules=yes")