From af7d73fb853909e7d4bae1ba3d726860b26b2d00 Mon Sep 17 00:00:00 2001 From: Enrique Encalada Date: Tue, 2 Mar 2021 17:06:28 +0100 Subject: [PATCH] Fixes #518 The behaviour for a git repo revision was being hardcoded to `master`, which is incorrect, while github is already creating the default branch to `main` and also because the default Tekton behaviour does not take place if the revision parameter is not specified. Tekton defaults behaviour triggers a git symbolic-link to HEAD, which we should allow to happen if the user does not specify a revision in the Build source. --- docs/build.md | 2 +- pkg/reconciler/buildrun/resources/taskrun.go | 5 ++++- pkg/reconciler/buildrun/resources/taskrun_test.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/docs/build.md b/docs/build.md index c18a440ec2..7da92e2364 100644 --- a/docs/build.md +++ b/docs/build.md @@ -83,7 +83,7 @@ The `Build` definition supports the following fields: A `Build` resource can specify a Git source, together with other parameters like: - `source.credentials.name` - For private repositories, the name is a reference to an existing secret on the same namespace containing the `ssh` data. -- `source.revision` - An specific revision to select from the source repository, this can be a commit or branch name. +- `source.revision` - An specific revision to select from the source repository, this can be a commit or branch name. If not defined, it will fallback to the git repository default branch. - `source.contextDir` - For repositories where the source code is not located at the root folder, you can specify this path here. Currently, only supported by `buildah`, `kaniko` and `buildpacks` build strategies. By default, the Build controller will validate that the Git repository exists. If the validation is not desired, users can define the `build.shipwright.io/verify.repository` annotation with `false`. For example: diff --git a/pkg/reconciler/buildrun/resources/taskrun.go b/pkg/reconciler/buildrun/resources/taskrun.go index f38ba9d2bc..0cac734612 100644 --- a/pkg/reconciler/buildrun/resources/taskrun.go +++ b/pkg/reconciler/buildrun/resources/taskrun.go @@ -180,7 +180,10 @@ func GenerateTaskRun( strategy buildv1alpha1.BuilderStrategy, ) (*v1beta1.TaskRun, error) { - revision := "master" + // Set revision to empty if the field is not specified in the Build. + // This will force Tekton Controller to do a git symbolic-link to HEAD + // giving back the default branch of the repository + revision := "" if build.Spec.Source.Revision != nil { revision = *build.Spec.Source.Revision } diff --git a/pkg/reconciler/buildrun/resources/taskrun_test.go b/pkg/reconciler/buildrun/resources/taskrun_test.go index 2bdf68d3c3..9b60f232ed 100644 --- a/pkg/reconciler/buildrun/resources/taskrun_test.go +++ b/pkg/reconciler/buildrun/resources/taskrun_test.go @@ -121,7 +121,7 @@ var _ = Describe("GenerateTaskrun", func() { namespace = "build-test" contextDir = "src" - revision = "master" + revision = "" builderImage = &buildv1alpha1.Image{ ImageURL: "heroku/buildpacks:18", }