I’m implementing a gitlab job that uses astyle to fix code formatting and then git diff to check if modifications have been made (and fail the job if so). Here’s what it looks like
# Code formatting using astyle
astyle:
variables:
SRC_FOLDER: "astyle"
stage: format
rules:
- changes:
- ${SRC_FOLDER}/**/*
script:
- pwd; ls -la
- cd ${SRC_FOLDER}
- astyle --options=code-format.cfg --recursive "src/*.c,*.cpp,*.h"
- if ! (git diff --color --exit-code); then echo "Code formatting check failed"; exit 1; fi
The pipeline is executed on a alpine linux Docker image with git installed but when “git diff” is executed, I get the error “warning: Not a git repository”. I’ve added the “pwd; ls -la” commands to check but when they are executed they show me the right path and the .git folder so I don’t know what the problem is. I’ve tried to look for this problem but all the answers I’ve found were people that forgot to cd into the repository. I also know I’m in the right directory because “cd ${SRC_FOLDER}” does not give an error and it can only be the case if I’m in the right directory
I’m in a custom gitlab instance so the configuration might be the problem but I don’t know what to look for in this case