/
zhendosina
/
obshell
Обзор
Документация
Войти
/
zhendosina
/
obshell
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
git-hooks/pre-commit
35 строк
897 B
frf12
feat: change swwa comment before format
16 май 2024, 15:32
16 май 2024, 15:32
1d6764d
Код
Авторство
О чём код?
#!/bin/sh # List of Go files that have been modified FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.go$') # No Go files were modified if [ -z "$FILES" ]; then echo "No Go files were modified" exit 0 fi # Flag whether formatting was done FORMATTED=false # Iterate and format each Go file for FILE in $FILES; do # Modify swag comment, trigger swag fmt formatting sed -i 's/@Router/ @Router /g' $FILE swag fmt $FILE # Check if the file has been formatted by swag fmt if ! git diff --quiet "$FILE"; then FORMATTED=true # Add the formatted Go file to the staging area git add "$FILE" echo "$FILE was formatted" fi done if $FORMATTED; then echo -e "\033[31m[Error] \033[0mSome files have been formatted. Please commit again" exit 1 fi # If formatting is complete, continue with the original commit exit 0