--- title: "ADR 0020: GitLab reads use the event SHA, not the branch" --- * Status: accepted * Code: [`pkg/provider/gitlab/gitlab.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/gitlab/gitlab.go) (`sourceRevision`, `GetTektonDir`, `GetFileInsideRepo`, `GetCommitInfo`), [`pkg/provider/gitlab/parse_payload.go`](https://github.com/tektoncd/pipelines-as-code/blob/main/pkg/provider/gitlab/parse_payload.go) ## Context A branch can move between the webhook and the moment PAC reads the repository. Reading by branch name would then select PipelineRun definitions, or a commit, different from the one that triggered the event. ## Decision * `sourceRevision` returns `event.SHA` when it is set and not the all-zero SHA, otherwise `event.HeadBranch`. `GetTektonDir` and `GetFileInsideRepo` use it. `provenance == "default_branch"` and an explicit `targetRevision` take precedence. * For a branch creation event, `GetCommitInfo` resolves `event.SHA` and fails if the returned commit ID does not match it (case-insensitively). Only an event with no SHA and a head branch, i.e. an incoming webhook, resolves the mutable branch ref. * For a branch creation without commits, the payload parser takes `After` as the branch tip, because it is the immutable value GitLab provides. ## Consequences * Later pushes to the branch do not change what a running event reads. * A branch creation fails loudly if the SHA cannot be resolved to itself, instead of silently running on a newer HEAD.