I am trying to create a function in bash script to automate the messages when doing git commit -S -am 'Message'
, depending on the file created, deleted or modified.
But I don't know how to do it and I just created a function, where it saves me a bit of work but I still have to manually add the messages of each commit.
This is my code:
function gitpush () {
if [ -d .git ]; then
git add .
if [ -z "$2" ]; then
echo "No commit message"
else
git commit -S -am "$2"
fi
if [ -z "$1" ]; then
echo "No repository selected"
else
git push $1 master
fi
else
echo false
fi
}
gitpush origin "Message"
I know that with the command git status --porcelain
you can get the list of affected files. And doing some research I created this little command.
git status --porcelain | \
sed -e 's/\sD/Remove/g;s/\sM/Update/g;s/\s??/Create/g' | \
awk -F: '{
print "git commit -S -am " $1 $2
}'
But it didn't work for me :(