Commit 3217345b authored by Administrator's avatar Administrator
Browse files

Add test of the file type

We don't want to have files with dos CRLF line endings in the repository,
so we test if any of the changed files has this file type.
parent 884ac67b
stages:
- checkRepository
- checkFormat
RebaseCheck:
stage: checkRepository
......@@ -60,3 +61,21 @@ LinearHistCheck:
- echo "${count} merge commits must be removed or the other new commits have to be replayed in a new branch"
- exit 1
- fi
FileFormatCheck:
stage: checkFormat
image: alpine
tags:
- docker
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_PROJECT_PATH == "CbmSoft/cbmroot_parameter" && $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "master"
script:
# Get the upstream repository manually. I did not find any other way to have it for
# comparison
- apk update && apk add git bash file
- ci_scripts/connect_upstream_repo.sh $CI_MERGE_REQUEST_PROJECT_URL
- git fetch upstream
- ci_scripts/check-file-format.sh upstream
#!/bin/bash
if [[ $# -eq 1 ]]; then
UPSTREAM=$1
else
if [ -z $UPSTREAM ]; then
UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq)
if [ -z $UPSTREAM ]; then
echo "Error: Name of upstream repository not provided and not found by automatic means"
echo 'Please provide if by checking your remotes with "git remote -v" and exporting UPSTREAM'
echo "or passing as an argument"
exit -1
fi
fi
fi
BASE_COMMIT=$UPSTREAM/master
CHANGED_FILES=$(git diff --name-only $BASE_COMMIT)
for file in $CHANGED_FILES; do
result=$(file $file | grep CRLF)
if [[ "$result" != "" ]]; then
echo ""
echo "File $file has wrong file format"
echo "$result"
echo ""
okay=false
fi
done
if [[ "$okay" = "false" ]]; then
echo ""
echo "Not all files have the correct file format"
echo "Test failed"
exit 1
else
exit 0
fi
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment