From 452b779fa41c0a794116daa899161bf5754196f1 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sun, 27 Aug 2023 00:03:35 +0100 Subject: [PATCH] feat(git-hooks): allow issue IDs on multiple lines --- templates/git-hooks/prepare-commit-msg.twig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/templates/git-hooks/prepare-commit-msg.twig b/templates/git-hooks/prepare-commit-msg.twig index b7eeb2d..564cfab 100755 --- a/templates/git-hooks/prepare-commit-msg.twig +++ b/templates/git-hooks/prepare-commit-msg.twig @@ -9,7 +9,7 @@ # the commit message. # # This also works with multiple issue IDs in the same string, e.g. -# "OD-123 OD-456". +# "OD-123 OD-456", or IDs on multiple lines. set -euo pipefail @@ -17,9 +17,9 @@ PROJECT_DIR=$(git rev-parse --show-toplevel) # Get the root directory of the rep ISSUE_FILE="$PROJECT_DIR/.issue-id" if [ -f "${ISSUE_FILE}" ]; then - ISSUE_ID=$(cat "${ISSUE_FILE}" | sed 's/ /, /g') + ISSUE_IDS=$(cat "${ISSUE_FILE}" | tr '\n' ',' | tr ' ' ',' | sed 's/,$//' | sed 's/,/, /g') - if [ -n "${ISSUE_ID}" ]; then - sed -i.bak "s/# Refs:/Refs: $ISSUE_ID/" "$1" + if [ -n "${ISSUE_IDS}" ]; then + sed -i.bak "s/# Refs:/Refs: $ISSUE_IDS/" "$1" fi fi