Skip to content

Commit 6c07eee

Browse files
authored
🐹 fix: husky preventing initial commit (#395)
1 parent bdde37a commit 6c07eee

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

.husky/pre-commit

+13-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,19 @@ PROTECTED_BRANCHES=(
2020
"release"
2121
)
2222

23-
# 获取当前分支名
24-
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
23+
# 初始化 CURRENT_BRANCH 变量为空字符串
24+
CURRENT_BRANCH=""
25+
26+
# 检查仓库是否有提交历史
27+
if git show-ref --heads --quiet; then
28+
# 获取当前分支名
29+
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
30+
echo "当前分支: $CURRENT_BRANCH"
31+
else
32+
echo "当前为首次提交,仓库没有提交历史"
33+
exit 0
34+
fi
35+
2536

2637
# 如果当前分支是受保护分支
2738
for branch in "${PROTECTED_BRANCHES[@]}"; do

0 commit comments

Comments
 (0)