From fe9653160be3b025698be9a2a2141b2b87b8ef55 Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Fri, 7 Jun 2019 10:55:30 -0400 Subject: gitlab-ci: Use --unshallow when fetching for linters GitLab creates a shallow clone. However, this means that we may not have the base commit of an MR when linting, causing `git merge-base` to fail. Fix this by passing `--unshallow` to `git fetch`, ensuring that we have the entire history. --- .gitlab-ci.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 35c199f248..fdb4174ddb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -52,9 +52,13 @@ ghc-linters: stage: lint image: "registry.gitlab.haskell.org/ghc/ci-images/linters:$DOCKER_REV" script: - - git fetch "$CI_MERGE_REQUEST_PROJECT_URL" $CI_MERGE_REQUEST_TARGET_BRANCH_NAME + # GitLab creates a shallow clone which means that we may not have the base + # commit of the MR being tested (e.g. if the MR is quite old), causing `git + # merge-base` to fail. Passing `--unshallow` to `git fetch` ensures that + # we have the entire history. + - git fetch --unshallow "$CI_MERGE_REQUEST_PROJECT_URL" $CI_MERGE_REQUEST_TARGET_BRANCH_NAME - base="$(git merge-base FETCH_HEAD $CI_COMMIT_SHA)" - - "echo Merge base $base" + - "echo Linting changes between $base..$CI_COMMIT_SHA" # - validate-commit-msg .git $(git rev-list $base..$CI_COMMIT_SHA) - validate-whitespace .git $(git rev-list $base..$CI_COMMIT_SHA) - .gitlab/linters/check-makefiles.py $base $CI_COMMIT_SHA -- cgit v1.2.1