Reputation: 760
I am creating a script that will pull down the latest master branch of code, and check to see if any of the file names are SQL. After I have determined the filename, I am going to source the stored procedures. Currently I have it pulling the code and readying the output line by line, however my grep command doesn't seem to be able to find the sql filename. This is what I have
#!/bin/bash
# Pull all of the latest code for the master branch, and set the commit log to
# a variable
commit_log=$(git pull origin master --quiet)
#read the commit log line by line
echo $commit_log | while read line
do
if [ `echo "$line" | grep -E "(\.sql)$"` ]; then
echo "SQL"
fi
echo "LINE:" $line
done
I am not stuck on bash, I could also do this in perl.
Upvotes: 1
Views: 641
Reputation: 26515
After a pull the new state is stored in HEAD and the old one in HEAD@{1}.
You can find the changed files between both with git diff --name-only
.
A small perl one-liner seems to be the easiest way to check the file names:
git pull
git diff --name-only HEAD@{1} | perl -wpe 'print "SQL:" if /\.sql$/'
Upvotes: 4