1

I am trying to do a simple git commit. I run

git add .
git commit -a -m "Added fixes"

and I get back

sed: -e expression #1, char 10: unknown option to `s'

The solutions I see are for Linux, but unfortunately I'm on Windows (Corporate policy). How can I fix it?

This is the prepare-commit-msg

#!/bin/bash
# Include any branches for which you wish to disable this script
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop)
fi
# Get the current branch name and check if it is excluded
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_EXCLUDED=$(printf "%s\n" "${BRANCHES_TO_SKIP[@]}" | grep -c "^$BRANCH_NAME$")
# Trim it down to get the parts we're interested in
TRIMMED=$(echo $BRANCH_NAME | sed -e 's:\([a-z]\+\/\)*\([A-Z]\+-[0-9]\+\).\+:\2:')
# If it isn't excluded, preprend the trimmed branch identifier to the given message
if [ -n "$BRANCH_NAME" ] &&  ! [[ $BRANCH_EXCLUDED -eq 1 ]]; then
sed -i.bak -e "1s/^/$TRIMMED: /" $1
fi
Alex Ironside
  • 4,658
  • 11
  • 59
  • 119

1 Answers1

3

The problem is that there is / in your branch name but the same character is used in sed script. As a temporary measure, you can replace / in sed script with something else, for example ,:

sed -i.bak -e "1s,^,$TRIMMED: ," $1

In the ideal solution one should look for / in branch name and escape it correctly inside sed script.

Arkadiusz Drabczyk
  • 11,227
  • 2
  • 25
  • 38