title: CI jobs fail intermittently on GitLab-runner with error "fatal: shallow file has changed since we read it"
body: <p>Jobs on my self-hosted GitLab deployment recently started failing <em>sometimes</em> with this git error:</p>
  <p>An example of a full job log is:</p>
  <pre><code>Running with gitlab-runner 13.12.0 (v13.12.0)
    on ....50ab V...
  Preparing the &quot;shell&quot; executor
  00:00
  Using Shell executor...
  Preparing environment
  00:00
  Running on saxtons...
  Getting source from Git repository
  00:03
  $ /nix/store/s0frm5z2k43qm66q39ifl2vz96hmyxg4-pre-clone
  Fetching changes with git depth set to 50...
  Reinitialized existing Git repository in /var/lib/private/gitlab-runner/builds/V.../2/privatestorage/PrivateStorageio/.git/
  fatal: shallow file has changed since we read it
  Cleaning up file based variables
  00:00
  ERROR: Job failed: exit status 1
  </code></pre>
  <p>The pre-clone script contains this and is used to fix permissions on unwriteable directories that cause the runner's attempts to clean up the git checkout to fail:</p>
  <pre><code>chmod --recursive u+rwX .
  </code></pre>
  <p>The GitLab-runner's config.toml contains this:</p>
  <pre><code>check_interval = 0
  concurrent = 8
  
  [[runners]]
  executor = &quot;shell&quot;
  name = &quot;...50ab&quot;
  pre_clone_script = &quot;/nix/store/s0frm5z2k43qm66q39ifl2vz96hmyxg4-pre-clone&quot;
  token = &quot;V...&quot;
  url = &quot;https://.../&quot;
  
  [runners.cache]
  [runners.cache.azure]
  
  [runners.cache.gcs]
  
  [runners.cache.s3]
  
  [runners.custom_build_dir]
  
  [[runners]]
  executor = &quot;docker&quot;
  name = &quot;...5afc&quot;
  token = &quot;...&quot;
  url = &quot;https://.../&quot;
  
  [runners.cache]
  [runners.cache.azure]
  
  [runners.cache.gcs]
  
  [runners.cache.s3]
  
  [runners.custom_build_dir]
  
  [runners.docker]
  disable_cache = false
  disable_entrypoint_overwrite = false
  image = &quot;nixos/nix&quot;
  oom_kill_disable = false
  privileged = false
  shm_size = 0
  tls_verify = false
  volumes = [&quot;/cache&quot;]
  
  [[runners]]
  executor = &quot;docker&quot;
  name = &quot;...c334&quot;
  token = &quot;...&quot;
  url = &quot;https://.../&quot;
  
  [runners.cache]
  [runners.cache.azure]
  
  [runners.cache.gcs]
  
  [runners.cache.s3]
  
  [runners.custom_build_dir]
  
  [runners.docker]
  disable_cache = false
  disable_entrypoint_overwrite = false
  image = &quot;.../ubuntu-python3-awscli&quot;
  oom_kill_disable = false
  privileged = false
  shm_size = 0
  tls_verify = false
  volumes = [&quot;/cache&quot;]
  
  [session_server]
  session_timeout = 1800
  </code></pre>
  <p>GitLab-runner is deployed on NixOS 21.05 (using the NixOS package/service configuration).</p>
  <p>I've never seen this git error before.</p>
  <ul>
  <li>What does it indicate is happening?</li>
  <li>How do I configure GitLab to stop doing whatever causes this?</li>
  </ul>