From 7aa38d3c6178b551025dbd07a14d7cc10667e48c Mon Sep 17 00:00:00 2001 From: aboudjem Date: Mon, 19 Feb 2024 00:10:30 +0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=85Add=20Git=20hooks=20for=20branch=20nam?= =?UTF-8?q?e=20validation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .husky/_/post-checkout | 16 ++++++++++++++++ .husky/_/pre-commit | 16 ++++++++++++++++ .husky/_/pre-push | 14 ++++++++++++++ 3 files changed, 46 insertions(+) create mode 100755 .husky/_/post-checkout create mode 100755 .husky/_/pre-commit create mode 100755 .husky/_/pre-push diff --git a/.husky/_/post-checkout b/.husky/_/post-checkout new file mode 100755 index 00000000..3f1cbe34 --- /dev/null +++ b/.husky/_/post-checkout @@ -0,0 +1,16 @@ +#!/bin/sh + +branch_name=$(git branch --show-current) +pattern="^(feat/|fix/|release/|chore/)" +ignore_branches="^(main|dev)$" + +if [[ $branch_name =~ $ignore_branches ]]; then + exit 0 # Ignore the check if the branch is main or dev +fi + +if ! [[ $branch_name =~ $pattern ]]; then + echo -e "\033[31mERROR: Your branch name '$branch_name' does not meet the required pattern (feat/, fix/, release/, chore/).\033[0m" + echo "Please rename your branch before pushing. For example:" + echo "git branch -m " + exit 1 +fi diff --git a/.husky/_/pre-commit b/.husky/_/pre-commit new file mode 100755 index 00000000..b6afa991 --- /dev/null +++ b/.husky/_/pre-commit @@ -0,0 +1,16 @@ +#!/bin/sh + +branch_name=$(git branch --show-current) +pattern="^(feat/|fix/|release/|chore/)" +ignore_branches="^(main|dev)$" + +if [[ $branch_name =~ $ignore_branches ]]; then + exit 0 # Ignore the check if the branch is main or dev +fi + +if ! [[ $branch_name =~ $pattern ]]; then + echo -e "\033[31mERROR: Your branch name '$branch_name' does not meet the required pattern (feat/, fix/, release/, chore/).\033[0m" + echo "Please rename your branch before pushing. For example:" + echo "git branch -m " + exit 1 +fi \ No newline at end of file diff --git a/.husky/_/pre-push b/.husky/_/pre-push new file mode 100755 index 00000000..c53bf9c7 --- /dev/null +++ b/.husky/_/pre-push @@ -0,0 +1,14 @@ +#!/bin/sh +. "$(dirname "$0")/_/husky.sh" + +branch_name=$(git branch --show-current) +pattern="^(feat/|fix/|release/|chore/)" + +if ! [[ $branch_name =~ $pattern ]]; then + echo "ERROR: Your branch name does not meet the required pattern (feat/, fix/, release/, chore/)." + echo "To rename your branch, use the following command, replacing 'new-branch-name' with the correct format:" + echo "git branch -m new-branch-name" + exit 1 +fi + +yarn lint:fix