Skip to content

Instantly share code, notes, and snippets.

@mikalai-yankouski
Last active June 12, 2023 10:04
Show Gist options
  • Save mikalai-yankouski/5c7195bea22aabb8cb1a75933adff28b to your computer and use it in GitHub Desktop.
Save mikalai-yankouski/5c7195bea22aabb8cb1a75933adff28b to your computer and use it in GitHub Desktop.
prepared message for commit
#!/bin/bash
branchPath=$(git symbolic-ref -q HEAD | grep -Eo 'LENS-[0-9]+') #Somthing like refs/heads/myBranchName
branchName=$branchPath #Get text behind the last / of the branch path
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ;then #Check that this is not an amend by checking that the first line is empty
sed -i "1s/^/$branchName \n/" $1 #Insert branch name at the start of the commit message file
fi
#mac
#!/bin/bash
branchPath=$(git symbolic-ref -q HEAD | grep -Eo 'CAGG-[0-9]+|CCMPSAPP-[0-9]+') #Somthing like refs/heads/myBranchName
branchName=$branchPath #Get text behind the last / of the branch path
firstLine=$(head -n1 $1)
if [ -z "$firstLine" ] ;then #Check that this is not an amend by checking that the first line is empty
sed -i '.bak' "1s/^/$branchName /" $1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment