0

I have this in my bash file

#!/usr/bin/env bash
LC_ALL=C

local_branch="STORY-409-new-bash-file"

valid_branch_regex="(feature\/|bugfix\/|release\/|hotfix\/)?(PIB\-|STORY\-)(\d+)\-(.+)"
valid_branch_sample="[type]/[ticket-number]-description-with-hyphenated-string, i.e feature/STORY-584-do-something-here"

message="There is something wrong with your branch name. Branch names in this project must adhere to this contract: $valid_branch_sample. Your commit will be rejected. You should rename your branch to a valid name and try again."

if [[ ! $local_branch =~ $valid_branch_regex ]]

then
    echo "$message"
    exit 1
fi

exit 0

and it keeps exiting with 1 meaning the regex doesn't match but I'm thinking the regex matches and it should exit with 0. What is wrong with the regex

eloka
  • 95
  • 7
  • 2
    Bash regex is ERE without supporting `\d` expression. Use `[0-9]` insread. Then the regex will look like: `valid_branch_regex="(feature/|bugfix/|release/|hotfix/)?(PIB-|STORY-)([0-9]+)-(.+)"`. Note that you don't need to escape `/` and `-`. – tshiono Sep 07 '22 at 04:21
  • 1
    Thank you so much it worked. I've been battling with this for hours @tshiono – eloka Sep 07 '22 at 04:28

0 Answers0