Skip to content

Instantly share code, notes, and snippets.

@risentveber
Last active October 11, 2022 13:15
Show Gist options
  • Save risentveber/cf742433c6499bad7f59a26b3db1616c to your computer and use it in GitHub Desktop.
Save risentveber/cf742433c6499bad7f59a26b3db1616c to your computer and use it in GitHub Desktop.
#!/bin/sh
# set -- $GIT_PARAMS
BRANCH_NAME=$(git symbolic-ref --short HEAD)
BRANCH_IN_COMMIT=0
if [ -f $1 ]; then
BRANCH_IN_COMMIT=$(grep -c "\[$BRANCH_NAME\]" $1)
fi
if [ -n "$BRANCH_NAME" ] && ! [[ $BRANCH_IN_COMMIT -ge 1 ]]; then
if [ -f $1 ]; then
BRANCH_NAME="${BRANCH_NAME/\//\/}"
sed -i.bak -e "1s@^@[$BRANCH_NAME] @" $1
else
echo "[$BRANCH_NAME] " > "$1"
fi
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment