-
Notifications
You must be signed in to change notification settings - Fork 194
Expand file tree
/
Copy pathpre-commit
More file actions
39 lines (28 loc) · 1.38 KB
/
pre-commit
File metadata and controls
39 lines (28 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env bash
set -e
LC_ALL=C
git_username_lower="$(git config github.user | tr '[:upper:]' '[:lower:]')"
if [[ -z "${git_username_lower}" ]]; then
echo -e "Error: GitHub username is not set.
Please set your GitHub username using one of the following commands:
1. To set it globally (for all repos):
\033[1mgit config --global github.user \"<USERNAME>\"\033[0m
2. To set it locally (for this repo only):
\033[1mgit config github.user \"<USERNAME>\"\033[0m
Replace <USERNAME> with your GitHub username (e.g., 'gh-username').
Once set, try committing again."
exit 1
fi
# e.g. "USERNAME/ARO-1234", "USERNAME/hotfix-v20240321.00", "USERNAME/gh-issue-123" and appended descriptions: "USERNAME/ARO-1234/description-here"
valid_branch_regex="^${git_username_lower}\/(ARO-[0-9]{4,}|hotfix-v[0-9]{8}(\.[0-9]+)*|gh-issue-[0-9]{1,})(\/[a-zA-Z0-9][a-zA-Z0-9.-]*)?$"
local_branch="$(git rev-parse --abbrev-ref HEAD)"
if [[ ! $local_branch =~ $valid_branch_regex ]]; then
current_branch=$(git branch --show-current)
echo -e "Your commit has been rejected because the branch name is invalid.
Branch names in this project must adhere to the following contract:
\033[3m$valid_branch_regex\033[0m
To rename your current branch, run:
\033[1mgit branch --move $current_branch <NEW-BRANCH-NAME>\033[0m
Replace <NEW-BRANCH-NAME> with a valid branch name and try again."
exit 1
fi