hooks: fix newline injection on MacOS
Because MacOS `sed` just needs newlines to be escaped differently. Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
8fe5e5f73c
commit
337a4d7d1c
|
@ -1,10 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
set -eo pipefail
|
||||
|
||||
if [[ -z $(git diff --cached --name-only -r | grep status-go-version.json) ]]; then
|
||||
exit 0 # No status-go-version.json changes found.
|
||||
fi
|
||||
|
||||
# MacOS sed is garbage and interprets newlines differently.
|
||||
[[ "$(uname)" -eq "Darwin" ]] && NL=$'\\\n' || NL="\n"
|
||||
|
||||
MERGE_BASE=$(git merge-base -a develop "$(git rev-parse --abbrev-ref HEAD)" develop)
|
||||
GO_COMMIT_MERGE_BASE=$(git show "${MERGE_BASE}":status-go-version.json | awk -F'"' '/commit-sha1/{print $4}')
|
||||
GO_COMMIT_CURRENT=$(awk -F'"' '/commit-sha1/{print $4}' status-go-version.json)
|
||||
|
@ -16,7 +19,7 @@ COMMIT_MSG_FILE=$1
|
|||
# Check if the commit message already contains the link (rebase) and update otherwise insert into line2
|
||||
if ! grep -qF "${GITHUB_LINK_PREFIX}" "${COMMIT_MSG_FILE}" >/dev/null; then
|
||||
sed -in'' -e "2i\\
|
||||
\n${GITHUB_LINK}" "${COMMIT_MSG_FILE}"
|
||||
${NL}${GITHUB_LINK}" "${COMMIT_MSG_FILE}"
|
||||
else
|
||||
sed -in'' -e "s;^${GITHUB_LINK_PREFIX}.*$;${GITHUB_LINK};" "${COMMIT_MSG_FILE}"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue