Runner does NOT reset submodules
Summary
Runner does NOT clean and reset changes in a submodules
Steps to reproduce
I have 2 repos:
## Bar repo
bar
└── main.py
# Foo repo
foo
├── bar # submodule
├── .gitlab-ci.yml
└── .gitmodules
Case 01:
First time setup:
research:
image: ubuntu:16.04
script:
- ls -ahl bar/
- echo "File's created while running Pipeline" > bar/pipeline.tml
I forgot GIT_SUBMODULE_STRATEGY: "recursive"
. After set it, I got bellow error:
Updating/initializing submodules recursively...
Synchronizing submodule url for 'bar'
fatal: destination path '/builds/root/foo/bar' already exists and is not an empty directory.
fatal: clone of 'http://gitlab-ci-token:xxxxxxxxxxxxxxxxxxxx@35.197.146.142.xip.io/root/bar.git' into submodule path '/builds/root/foo/bar' failed
This error come from submodules is NOT cleaned before new job:
$ ls -ahl bar/
total 20K
drwxrwxrwx 2 root root 4.0K Dec 3 11:30 .
drwxrwxrwx 4 root root 4.0K Dec 3 11:37 ..
-rw-rw-rw- 1 root root 28 Dec 3 11:30 .git
-rw-rw-rw- 1 root root 29 Dec 3 11:35 main.py
-rw-r--r-- 1 root root 38 Dec 3 11:35 pipeline.tml
Proposal
Run this command if GIT_SUBMODULE_STRATEGY: "recursive"
$ git submodule foreach --recursive git clean -ffdx
Case 02:
research:
image: ubuntu:16.04
variables:
GIT_SUBMODULE_STRATEGY: "recursive"
script:
- echo "Before modify: $(cat bar/main.py)"
- echo "I'm modify file in submodule" > bar/main.py"
- echo "After modify: $(cat bar/main.py)"
In the second run
Actual behavior
$ echo "Before modify $(cat bar/main.py)"
Before modify I'm modify file in submodule
$ echo "I'm modify file in submodule" > bar/main.py
$ echo "After modify $(cat bar/main.py)"
After modify I'm modify file in submodule
Expected behavior
Before modify print original content.
Proposal
This unexpected behavior come from submodules is NOT reset before new job.
So, runner MUST reset submodules by command:
$ git submodule foreach --recursive git reset --hard HEAD
Environment & version
Version: 10.2.0
Git revision: 0a75cdd1
Git branch: 10-2-stable
GO version: go1.8.3
Built: Wed, 22 Nov 2017 09:19:04 +0000
OS/Arch: linux/amd64
Edited by 🤖 GitLab Bot 🤖