Skip to content

Commit

Permalink
Merge branch 'master.dev' into 'master'
Browse files Browse the repository at this point in the history
Release 3.1.0

See merge request piclas/piclas!842
  • Loading branch information
pnizenkov committed Feb 1, 2024
2 parents 07e4fbb + e632d02 commit 249fb0d
Show file tree
Hide file tree
Showing 546 changed files with 59,792 additions and 7,580 deletions.
6 changes: 0 additions & 6 deletions .directory

This file was deleted.

114 changes: 91 additions & 23 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
# Check the number and total size of files about to be commited
#===================================================================================================================================

# Executables, command -v is safe with sh
BN_EXE=$(command -v basename)
DU_EXE=$(command -v du)
GIT_EXE=$(command -v git)
LS_EXE=$(command -v ls)
TR_EXE=$(command -v tr)

# Check if override is requested
if [ "$GIT_OVERRIDE_LIMITS" = "1" ]; then
echo 'Detected "GIT_OVERRIDE_LIMITS=1", overriding pre-commit check ...'
Expand All @@ -30,20 +37,29 @@ SIZETOTALLIMIT=1000000
SIZETOTALWARN=100000

# Number of existing files plus 100
NUMBERLIMIT=$(git ls-tree --full-tree -r --name-only HEAD | wc -l)
NUMBERLIMIT=$($GIT_EXE ls-tree --full-tree -r --name-only HEAD | wc -l)
NUMBERLIMIT=$(($NUMBERLIMIT + 100))
NUMBERWARN=100

# Local variables
ERROR=0
FILEWARN=0
FILEERR=0
FILEWARN=0
FILESUM=0
FILESUMERR=0
FILESUMWARN=0
EXEERR=0
TABERR=0

EXELINE=''
TABLINE=''
SIZEWARNLINE=''
SIZEDENYLINE=''

# Check if file is opened in a terminal
if test -t 1; then
# Check if terminal supports color
NbrOfColors=$(which tput > /dev/null && tput colors)
NbrOfColors=$(command -v tput > /dev/null && tput colors)
if test -n "$NbrOfColors" && test "$NbrOfColors" -ge 8; then
NC="$(tput sgr0)"
RED="$(tput setaf 1)"
Expand All @@ -53,13 +69,14 @@ if test -t 1; then
fi

# Get a list of all staged files
CHANGED=$(git diff --staged --name-only)
CHANGED=$($GIT_EXE diff --staged --name-only)

# Check if any changes are present
if [ -n "$CHANGED" ]; then
# Sort found files by size (-S) in reverse ordering (-r)
SORTED=$(ls -Shsr "$CHANGED" 2> /dev/null)
NUMBER=$(git diff --staged --numstat | wc -l)
CHANGED=$(echo "$CHANGED" | $TR_EXE '\n' ' ')
SORTED=$($LS_EXE --sort=size -r $CHANGED 2> /dev/null)
NUMBER=$($GIT_EXE diff --staged --numstat | wc -l)

# Check the number of files
if [ "$NUMBER" -ge "$NUMBERLIMIT" ]; then
Expand All @@ -71,51 +88,102 @@ if [ -n "$CHANGED" ]; then

# Loop over all changes
for file in $SORTED; do

# Check if path is a file that exists
# -f True if FILE exists and is a regular file.
if [ -f "$file" ]; then
# -b, --bytes equivalent to '--apparent-size --block-size=1'
LINE=$(du -h "$file")
FILESIZE=$(du -b "$file" | cut -d ' ' -f1) # this is a tab, not a white space
LINE=$($LS_EXE -alhs "$file")
FILESIZE=$($DU_EXE -b "$file" | cut -d ' ' -f1) # this is a tab, not a white space

# Sum up the total file sizes
FILESUM=$(($FILESUM + $FILESIZE))

# Check the file size limit
if [ "$FILESIZE" -gt "$SIZESINGLELIMIT" ]; then
# Error header
if [ "$FILEERR" -eq 0 ]; then
printf "${RED}The following file(s) exceed the file size limit ($SIZESINGLELIMIT bytes)${NC}\n"
ERROR=1
FILEERR=1
fi
printf "$LINE\n"
ERROR=1
FILEERR=1
SIZEDENYLINE="$LINE\n$SIZEDENYLINE"
# Check the file size warning
elif [ "$FILESIZE" -gt "$SIZESINGLEWARN" ]; then
# Error header
if [ "$FILEWARN" -eq 0 ]; then
printf "${YELLOW}The following large file(s) are about to be committed (>$SIZESINGLEWARN bytes)${NC}\n"
FILEWARN=1
fi
printf "$LINE\n"
# Warning header
FILEWARN=1
SIZEWARNLINE="$LINE\n$SIZEWARNLINE"
fi
fi

# Check total file size
if [ "$FILESUM" -gt "$SIZETOTALLIMIT" ]; then
# Error header
printf "${RED}The total file size exceeds the size limit ($SIZETOTALLIMIT bytes)${NC}\n"
ERROR=1
FILESUMERR=1
# Check the file size warning
elif [ "$FILESUM" -gt "$SIZETOTALWARN" ]; then
# Error header
printf "${YELLOW}Total file size to be committed ($FILESUM bytes)${NC}\n"
FILESUMWARN=1
fi

# Check if file is executable
if [ -x "$file" ]; then
if [ "$file" != ".githooks/pre-commit" ] && [ "$file" != "docs/documentation/buildPDF.sh" ] && [ "$file" != "docs/documentation/buildHTML.sh" ] ; then
# Error header
ERROR=1
EXEERR=1
LINE=$($LS_EXE -alhs "$file")
EXELINE="$LINE\n$EXELINE"
fi
fi

# Check for tab characters in specific file endings
name=$($BN_EXE -- "$file")
ext="${name##*.}"
name="${name%.*}"
if [ "$ext" = "txt" ] || [ "$ext" = "f90" ] || [ "$ext" = "ini" ]; then
# -P, --perl-regexp PATTERNS are Perl regular expressions
NbrOfLinesWithTabs=$(grep -P '\t' $file | wc -l)
if [ "${NbrOfLinesWithTabs}" -gt 0 ]; then
LINE=$($LS_EXE -alhs "$file")
ERROR=1
TABERR=1
TABLINE="$LINE\n$TABLINE"
fi
fi

done

if [ $FILEERR -ne 0 ]; then
printf "${RED}The following file(s) exceed the file size limit ($SIZESINGLELIMIT bytes)${NC}\n"
printf "$FILEDENYLINE"
fi

if [ $FILEWARN -ne 0 ]; then
printf "${YELLOW}The following large file(s) are about to be committed (>$SIZESINGLEWARN bytes)${NC}\n"
printf "$FILEWARNLINE"
fi

if [ $FILESUMERR -ne 0 ]; then
printf "${RED}The total file size exceeds the size limit ($SIZETOTALLIMIT bytes)${NC}\n"
fi

if [ $FILESUMWARN -ne 0 ]; then
printf "${YELLOW}Total file size to be committed ($FILESUM bytes)${NC}\n"
fi

if [ "$EXEERR" -ne 0 ]; then
printf "${RED}The following file(s) are executable, which is not allowed. Remove the execute permission via 'chmod -x filename' and try again.${NC}\n"
printf "$EXELINE"
fi

if [ "$TABERR" -ne 0 ]; then
printf "${RED}The following file(s) contain tabs, which is not allowed. Remove the tab stops and try again.${NC}\n"
printf "$TABLINE"
fi

# Abort if hook encountered any error
if [ "$ERROR" -ne 0 ]; then
echo '------------------------------------------------------------------------------------------------------------------------------------'
echo 'Commit rejected! You can override this check by passing "GIT_OVERRIDE_LIMITS=1" to git.'
echo 'Commit rejected! You can override this check by passing "GIT_OVERRIDE_LIMITS=1" to git, e.g., run "GIT_OVERRIDE_LIMITS=1 git commit".'
exit 1
fi

Expand Down
8 changes: 7 additions & 1 deletion .github/workflows/cmake-ninja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ jobs:
DESTDIR=AppDir ninja install
mkdir -p AppDir/usr/share/icons
cp ../docs/logo.png AppDir/usr/share/icons/${PROG}.png
mkdir -p AppDir/usr/share/icons/hicolor/64x64/apps/
ln -sf ../../../${PROG}.png AppDir/usr/share/icons/hicolor/64x64/apps/
cp ../.github/workflows/piclas.desktop template.desktop
mv template.desktop ${PROG}.desktop
sed -i -e "s/Name=.*/Name=${PROG}/" ${PROG}.desktop
Expand Down Expand Up @@ -252,6 +254,8 @@ jobs:
DESTDIR=AppDir ninja install
mkdir -p AppDir/usr/share/icons
cp ../docs/logo.png AppDir/usr/share/icons/${PROG}.png
mkdir -p AppDir/usr/share/icons/hicolor/64x64/apps/
ln -sf ../../../${PROG}.png AppDir/usr/share/icons/hicolor/64x64/apps/
cp ../.github/workflows/piclas.desktop template.desktop
mv template.desktop ${PROG}.desktop
sed -i -e "s/Name=.*/Name=${PROG}/" ${PROG}.desktop
Expand All @@ -278,6 +282,8 @@ jobs:
DESTDIR=AppDir ninja install
mkdir -p AppDir/usr/share/icons
cp ../docs/logo.png AppDir/usr/share/icons/${PROG}.png
mkdir -p AppDir/usr/share/icons/hicolor/64x64/apps/
ln -sf ../../../${PROG}.png AppDir/usr/share/icons/hicolor/64x64/apps/
cp ../.github/workflows/piclas.desktop template.desktop
mv template.desktop ${PROG}.desktop
sed -i -e "s/Name=.*/Name=${PROG}/" ${PROG}.desktop
Expand Down Expand Up @@ -312,7 +318,7 @@ jobs:
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: piclas-binaries-v3.0.0
name: piclas-binaries-v3.1.0
path: artifacts

- name: Upload release asset
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,7 @@ doxygen/

# unit test
unitTests/bin/

# gitlab-ci-local temp files and folders
.gitlab-ci-local/
reggie/
Loading

0 comments on commit 249fb0d

Please sign in to comment.