Last active
          December 27, 2018 23:09 
        
      - 
      
- 
        Save patrickmch/b3764cdcdffbe76dfb8d3c3bb679d394 to your computer and use it in GitHub Desktop. 
    commit-msg
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| BRANCH_PATH=$(git symbolic-ref -q HEAD) # Something like refs/heads/my-branch-name | |
| BRANCH_NAME=${BRANCH_PATH##*/} # Get text behind the last / of the branch path | |
| # Make sure we have an issue number in front before doing anything | |
| if [[ $BRANCH_NAME =~ (^[0-9]{4}) ]] ;then | |
| ISSUE_NUMBER=${BASH_REMATCH[1]} | |
| FIRST_LINE=$(head -n1 $1) | |
| # make sure there isn't already a "fixes ISSUE_NUMBER" line in message (ex. if it's an amend) | |
| ISSUE_NUM_RE="[Ff]ixes #[0-9]{4}" | |
| if ! [[ "$(cat $1)" =~ $ISSUE_NUM_RE ]] ;then | |
| cat "$1" > /tmp/out && mv /tmp/out "$1" | |
| echo -ne "\nfixes #$ISSUE_NUMBER" >> "$1" | |
| fi | |
| fi | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
ISSUE_NUM_REneeds to be a variable. Everything after#will be evaluated as a comment if that expression isn't surrounded by quotes, and newer bash versions handle quotes a bit strangely. See this SO answer.