Skip to content

Commit

Permalink
no early return
Browse files Browse the repository at this point in the history
  • Loading branch information
LarsEckart committed Apr 24, 2024
1 parent a4983ca commit 0534e1a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
25 changes: 12 additions & 13 deletions githooks/prepare-commit-msg
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@
FILE=$1
MESSAGE=$(cat $FILE)
TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?\w+[-_][0-9]+' | grep -Eo '\w+[-][0-9]+' | tr "[:lower:]" "[:upper:]")
if [[ $TICKET == "" ]];then
echo 'Branch name without ticket information, keeping git message as is.'
exit 0;
fi
if [[ $MESSAGE == "Merge"* ]];then
echo 'Merge commit, keeping git message as is.'
exit 0;
fi
if [[ "$MESSAGE" == "$TICKET"* ]];then
echo 'ticket information already present, keeping git message as is.'
exit 0;
fi


echo "$TICKET $MESSAGE" > $FILE
if [[ $TICKET == "" ]]; then
echo 'Branch name without ticket information, keeping git message as is.'
else
if [[ $MESSAGE == "Merge"* ]]; then
echo 'Merge commit, keeping git message as is.'
elif [[ "$MESSAGE" == "$TICKET"* ]]; then
echo 'Ticket information already present, keeping git message as is.'
else
# Prepend the ticket information only if conditions are met
echo "$TICKET $MESSAGE" > $FILE
fi
fi
25 changes: 13 additions & 12 deletions githooks/prepare-commit-msg-james
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@ MESSAGE=$(cat $FILE)
TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?\w+[-_][0-9]+' | grep -Eo '\w+[-][0-9]+' | tr "[:lower:]" "[:upper:]")

# Define the Co-Author information
CO_AUTHOR="\n\nCo-Authored-By: James Skarzinskas <james@jskarzin.org>"
CO_AUTHOR="\n\n\nCo-Authored-By: James Skarzinskas <james@jskarzin.org>"

if [[ $TICKET == "" ]]; then
echo 'Branch name without ticket information, keeping git message as is.'
exit 0;
fi
if [[ $MESSAGE == "Merge"* ]]; then
echo 'Merge commit, keeping git message as is.'
exit 0;
fi
if [[ "$MESSAGE" == "$TICKET"* ]]; then
echo 'Ticket information already present, keeping git message as is.'
exit 0;
else
if [[ $MESSAGE == "Merge"* ]]; then
echo 'Merge commit, keeping git message as is.'
elif [[ "$MESSAGE" == "$TICKET"* ]]; then
echo 'Ticket information already present, keeping git message as is.'
else
# Prepend the ticket information only if conditions are met
echo "$TICKET $MESSAGE" > $FILE
fi
fi

# Append ticket information and co-author information
echo "$TICKET $MESSAGE" > $FILE
# Append Co-Author information unconditionally
echo "$CO_AUTHOR" >> $FILE

echo 'Co-author information added.'

0 comments on commit 0534e1a

Please sign in to comment.