Skip to content

Can't checkout a submodule branch anymore

Summary

After upgrading our gitlab runners from 13.10.0 to 13.11.0 we can't checkout a branch in a submodule anymore.

Steps to reproduce

One project named "mymodule" with two branches (main and dev)

One project named "test" with two branches (main and dev) and the project named "mymodule" as a submodule

Main branch :

[submodule "mymodule"]
    path = mymodule
    url = ../mymodule.git

Dev branch :

[submodule "mymodule"]
    path = mymodule
    url = ../mymodule.git
    branch = dev

Main branch

variables:
  GIT_SUBMODULE_STRATEGY: recursive

stages:
  - test

test:
  stage: test
  script:
    - cd mymodule
    - git pull

Dev branch

variables:
  GIT_SUBMODULE_STRATEGY: recursive

stages:
  - test

test:
  stage: test
  script:
    - cd mymodule
    - git checkout dev
    - git pull

Actual behavior

The git pull in the main branch can update the submodule OK.

The git checkout dev doesn't work anymore :

$ git checkout dev
error: pathspec 'dev' did not match any file(s) known to git

Expected behavior

The same as before in 13.10.0

$ git checkout dev
Previous HEAD position was 31d631c Add new file
Branch 'dev' set up to track remote branch 'dev' from 'origin'.

Relevant logs and/or screenshots

Running with gitlab-runner 13.11.0 (58ba2b95)
  on ************************ ZNjBtxc3
Preparing the "kubernetes" executor 00:00
Using Kubernetes namespace: *********************
Using Kubernetes executor with image ********************************* ...
Using attach strategy to execute scripts...
Preparing environment 00:06
Waiting for pod ********************* to be running, status is Pending
Waiting for pod ********************* to be running, status is Pending
	ContainersNotReady: "containers with unready status: [build helper]"
	ContainersNotReady: "containers with unready status: [build helper]"
Running on runner-znjbtxc3-project-1471-concurrent-0fwjvh via *********************...
Getting source from Git repository 00:02
Fetching changes with git depth set to 50...
Initialized empty Git repository in /builds/ZNjBtxc3/0/test/tes/.git/
Created fresh repository.
Checking out b15da79f as dev...
Updating/initializing submodules recursively with git depth set to 50...
Submodule 'mymodule' (https://gitlab-ci-token:[MASKED]@*************/test/mymodule.git) registered for path 'mymodule'
Cloning into '/builds/ZNjBtxc3/0/test/test/mymodule'...
From https://************/test/mymodule
 * branch            31d631ca35bad5f5b9647500f3a7604b70501542 -> FETCH_HEAD
Submodule path 'mymodule': checked out '31d631ca35bad5f5b9647500f3a7604b70501542'
Entering 'mymodule'
Entering 'mymodule'
Executing "step_script" stage of the job script 00:01
$ cd mymodule
$ git checkout dev
error: pathspec 'dev' did not match any file(s) known to git
Cleaning up file based variables 00:00
ERROR: Job failed: command terminated with exit code 1

Environment description

Gitlab runner with the Kubernetes Executor.

config.toml contents
Add your configuration here

Used GitLab Runner version

Possible fixes

Edited by Johan S