From b66626a578b713e415fc9e34a2c36c9a4669e9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=86=8A=E9=91=AB=E4=BC=9F=20Xinwei=20Xiong?= <3293172751NSS@gmail.com> Date: Tue, 22 Oct 2024 11:03:55 +0800 Subject: [PATCH] Update pre-commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 熊鑫伟 Xinwei Xiong <3293172751NSS@gmail.com> --- scripts/githooks/pre-commit | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/scripts/githooks/pre-commit b/scripts/githooks/pre-commit index 7660e5d..e92e44b 100644 --- a/scripts/githooks/pre-commit +++ b/scripts/githooks/pre-commit @@ -5,7 +5,6 @@ # Licensed under the MIT License (the "License"); # you may not use this file except in compliance with the License. -# ============================================================================== # This is a pre-commit hook that ensures attempts to commit files that are # are larger than $limit to your _local_ repo fail, with a helpful error message. @@ -13,12 +12,12 @@ # GIT_FILE_SIZE_LIMIT=50000000 git commit -m "test: this commit is allowed file sizes up to 50MB" # # ============================================================================== +# LC_ALL=C local_branch="$(git rev-parse --abbrev-ref HEAD)" -valid_branch_regex="^(main|master|develop)$|(feature|feat|release|hotfix|test|bug|ci|style|)\/[a-z0-9._-]+$|^HEAD$" - +valid_branch_regex="^(main|master|develop|release(-[a-zA-Z0-9._-]+)?)$|(feature|feat|openim|hotfix|test|bug|bot|refactor|revert|ci|cicd|style|)\/[a-z0-9._-]+$|^HEAD$" YELLOW="\e[93m" GREEN="\e[32m" @@ -26,18 +25,18 @@ RED="\e[31m" ENDCOLOR="\e[0m" printMessage() { - printf "${YELLOW}kubecub : $1${ENDCOLOR}\n" + printf "${YELLOW}openim : $1${ENDCOLOR}\n" } printSuccess() { - printf "${GREEN}kubecub : $1${ENDCOLOR}\n" + printf "${GREEN}openim : $1${ENDCOLOR}\n" } printError() { - printf "${RED}kubecub : $1${ENDCOLOR}\n" + printf "${RED}openim : $1${ENDCOLOR}\n" } -printMessage "Running local kubecub pre-commit hook." +printMessage "Running local openim pre-commit hook." # flutter format . # https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694#file-githook-md @@ -47,9 +46,9 @@ limit=${GIT_FILE_SIZE_LIMIT:-2000000} # Default 2MB limitInMB=$(( $limit / 1000000 )) function file_too_large(){ - filename=$0 - filesize=$(( $1 / 2**20 )) - + filename=$0 + filesize=$(( $1 / 2**20 )) + cat < /dev/null 2>&1 then - against=HEAD + against=HEAD else - against="$empty_tree" + against="$empty_tree" fi # Set split so that for loop below can handle spaces in file names by splitting on line breaks @@ -96,8 +95,8 @@ fi if [[ ! $local_branch =~ $valid_branch_regex ]] then - printError "There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. -Your commit will be rejected. You should rename your branch to a valid name(feat/name OR bug/name) and try again." + printError "There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_regex. +Your commit will be rejected. You should rename your branch to a valid name(feat/name OR fix/name) and try again." printError "For more on this, read on: https://gist.github.com/cubxxw/126b72104ac0b0ca484c9db09c3e5694" exit 1 -fi \ No newline at end of file +fi