Advertisement
janek9971

prepare-commit-msg

Mar 10th, 2023 (edited)
504
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.61 KB | None | 0 0
  1. #!/bin/bash
  2. local_branch="$(git rev-parse --abbrev-ref HEAD)"
  3.  
  4. #branchPath=$(git symbolic-ref -q HEAD) #Something like refs/heads/myBranchName
  5. taskId=${local_branch##*/}      #Get text behind the last / of the branch path
  6.  
  7. firstLine=$(head -n1 $1)
  8.  
  9. if [ -z "$firstLine"  ] ;then #Check that this is not an amend by checking that the first line is empty
  10.     sed -i "1s/^/#$taskId opis\\n/" $1 #Insert branch name at the start of the commit message file
  11. else    
  12.     if [ ! -z "$taskId" ]
  13.     then
  14.            sed -i "1s/^/#$taskId\\n/" $1 #Insert branch name at the start of the commit message file
  15.     fi
  16. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement