Skip to content

Use git --unshallow when GIT_DEPTH is zero

Arran Walker requested to merge ajwalker/fix-depth into main

What does this MR do?

Passes the -unshallow flag on git fetch when the GIT_DEPTH is zero and the repository is currently shallow (as indicated by .git/shallow)/

Why was this MR needed?

It was not currently possible to have a job that switches between a positive GIT_DEPTH and a zero GIT_DEPTH.

We can't just add --unshallow because this results in an error if the repository is already shallow. We fix this by first checking for the existence of .git/shallow.

What's the best way to test this MR?

Create a shell executor (so that the build directory is re-used over 2 jobs in sequence).

Run the follow jobs:

image: alpine:latest

stages:
  - shallow
  - unshallow

before_script:
  - |
    if test -f ".git/shallow"; then
      echo "We're shallow"
    else
      echo "I'm off the deep end, watch as I dive in"
      echo "I'll never meet the ground"
      echo "Crash through the surface, where they can't hurt us"
      echo "We're far from the shallow now"
    fi

shallow:
  stage: shallow
  variables:
    GIT_DEPTH: 1
  script:
    - echo "done."

unshallow:
  stage: unshallow
  variables:
    GIT_DEPTH: 0
  script:
    - echo "done."

First job will be shallow, and the second job will be far from the shallow now.

What are the relevant issue numbers?

Closes gitlab#292470 (closed)

Merge request reports

Loading