gitlab-ci: Use --unshallow when fetching for linters
authorBen Gamari <ben@smart-cactus.org>
Fri, 7 Jun 2019 14:55:30 +0000 (10:55 -0400)
committerBen Gamari <ben@well-typed.com>
Sat, 8 Jun 2019 17:34:18 +0000 (13:34 -0400)
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

index 35c199f..fdb4174 100644 (file)
@@ -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