Skip to content

Commit fc154ca

Browse files
committed
Fix prepare-commit-msg for rebases/merges
1 parent 8000743 commit fc154ca

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

.git-templates/hooks/prepare-commit-msg

+12-7
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,13 @@
77
# - type-123-description -> type: #123
88
# - 123-description -> #123
99
# - 123-GH-124-description -> #123 GH-124
10-
# - some-description ->
10+
# - some-description ->
1111

12-
LAST_EXIT_CODE=$?
1312
COMMIT_MSG_FILE="$1"
1413

15-
EXCLUDED_BRANCHES=("master" "main" "dev")
16-
CURRENT_BRANCH=$(git symbolic-ref --quiet --short HEAD)
17-
18-
# Abort during merges/rebases and on excluded branches
19-
if [ $LAST_EXIT_CODE -ne 0 ] || [[ ${EXCLUDED_BRANCHES[*]} =~ $CURRENT_BRANCH ]]; then
14+
# Abort during merges/rebases
15+
LAST_EXIT_CODE=$?
16+
if [ $LAST_EXIT_CODE -ne 0 ]; then
2017
exit 0
2118
fi
2219

@@ -25,6 +22,14 @@ if [ -n "$(head -n 1 "$COMMIT_MSG_FILE")" ]; then
2522
exit 0
2623
fi
2724

25+
# Abort on excluded branches
26+
EXCLUDED_BRANCHES=("master" "main" "dev")
27+
CURRENT_BRANCH=$(git symbolic-ref --quiet --short HEAD)
28+
if [[ ${EXCLUDED_BRANCHES[*]} =~ $CURRENT_BRANCH ]]; then
29+
exit 0
30+
fi
31+
32+
# Build array of conventional commit types
2833
CONVENTIONAL_COMMIT_TYPES=("build" "chore" "ci" "docs" "feat" "fix" "perf" "refactor" "revert" "style" "test")
2934
for type in "${CONVENTIONAL_COMMIT_TYPES[@]}"; do
3035
CONVENTIONAL_COMMIT_TYPES+=("$type!")

0 commit comments

Comments
 (0)