Skip to content

Commit

Permalink
Fix prepare-git-msg hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Emma Doyle committed Feb 19, 2023
1 parent 68a8f41 commit 387c744
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
description: Prefixes the commit message with the branch name
entry: hooks/prepare-git-commit-msg.sh
language: script
stages: [prepare-commit-msg]
stages:
- prepare-commit-msg
always_run: true
9 changes: 4 additions & 5 deletions hooks/prepare-git-commit-msg.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#! /usr/bin/env bash
# https://git-scm.com/docs/githooks#_prepare_commit_msg

FILE="$1"

BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_NAME="${BRANCH_NAME##*/}"
BRANCH_IN_COMMIT=$(grep -c "$BRANCH_NAME:" "$1")

if [ -n "$BRANCH_NAME" ] && [ "$BRANCH_EXCLUDED" -ne 1 ] && [ "$BRANCH_IN_COMMIT" -lt 1 ]; then
sed -i.bak -e "1s/^/$BRANCH_NAME: /" "$1"
fi
sed -i -e "1s/^/$BRANCH_NAME: /" "$FILE"

0 comments on commit 387c744

Please sign in to comment.