Skip to content

Commit

Permalink
Fixes #518
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
qu1queee committed Mar 2, 2021
1 parent 965569b commit af7d73f
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion pkg/reconciler/buildrun/resources/taskrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciler/buildrun/resources/taskrun_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ var _ = Describe("GenerateTaskrun", func() {

namespace = "build-test"
contextDir = "src"
revision = "master"
revision = ""
builderImage = &buildv1alpha1.Image{
ImageURL: "heroku/buildpacks:18",
}
Expand Down

0 comments on commit af7d73f

Please sign in to comment.