I've looked here but my question wasn't answered. I have a script that keeps a number of files up-to-date. The repository consists of a number of bash and python scripts. One of the scripts runs on an hourly cronjob and looks like this:
#! /bin/bash
git fetch origin && git reset --hard origin/dev && git clean -f -d
python -m compileall .
# Set permissions
chmod -R 744 *
Essentially it updates all the scripts to the current content of GitHub. One of the scripts is code for a daemon. When that changes I want to restart the daemon. There's no clue in the output from the git
commands regarding which files were changed. So, how can I do that?
To complicate matters, I think the python -m compileall
makes git
think all files have changed. But I found this question that seems to work.
[EDIT] Additional bonus question added: Based on the answer given below by @behzad.nouri I have modified the code thus:
#! /bin/bash
branch=$(cat ~/bin/gitbin.branch)
git fetch origin && \
DIFFdmn=$(git --no-pager diff --name-only $branch..origin/$branch -- ./testdaemon/daemon.py) && \
DIFFlib=$(git --no-pager diff --name-only $branch..origin/$branch -- ./testdaemon/libdaemon.py) && \
git reset --hard origin/dev && git clean -f -d
python -m compileall .
# Set permissions
chmod -R 744 *
if [[ -n "$DIFFdmn" ]]; then
logger -t 02-update-scripts "daemon has changed"
./testdaemon/daemon.py restart
fi
if [[ -n "$DIFFlib" ]]; then
logger -t 02-update-scripts "daemonlib has changed"
./testdaemon/daemon.py restart
fi
where ~/bin/gitbin.branch
should contain the name of the branch to sync with. This works for the branch called dev
but fails for the master
-branch (when trying to define the DIFFdmn
variable) with the message:
fatal: bad revision 'master..origin/master'
Any suggestions are very welcome.