Skip to content

Instantly share code, notes, and snippets.

@otomazeli
Forked from cphyc/watch-svn
Created July 6, 2022 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save otomazeli/b5a0d5229849d333d52c7df07fff05ce to your computer and use it in GitHub Desktop.
Save otomazeli/b5a0d5229849d333d52c7df07fff05ce to your computer and use it in GitHub Desktop.
SVN Monitor: monitor a repository and send a notification whenever a new commit is pushed
#!/usr/bin/env bash
#
# This tool is only working with SVN. I *strongly* advise to use git or mercurial for your everyday work.
# However, somteimes you're stuck with SVN so here's a small script to make your life easier :)
#
# This script is under the MIT license.
# 2017 - cphyc
# Preset parameters
NOTIFYCMD=notify-send
POLLFREQ=10
VERBOSE="false"
# Get the parameters of the call
while [[ $# -ge 1 ]]; do
key="$1"
case $key in
-t|--time)
POLLFREQ="$2"
shift # past argument
;;
-v|--verbose)
VERBOSE="true"
;;
-n|--notify-cmd)
NOTIFYCMD="$2"
shift # past argument
;;
-h|--help|*)
echo "\
SVN repository poller! Usage:
watch-snv [-t TIME] [-v] [-h]
-t, --time the time to leave between two polls [def: $POLLFREQ]
-v, --verbose verbose, or not verbose, that is the question [def: $VERBOSE]
-n, --notify-cmd use this command for notification [def: $NOTIFYCMD]
-h, --help print this help"
exit 0
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
function svn_is_up_to_date {
# Svn show updates: show modify files on server in column nine
nmodified=$(svn status --show-updates -q | cut -b 9 | grep '*' | wc -l)
return $nmodified
}
function get_upstream_revision {
# Select upstream revision
upstream=$(svn status --show-updates -q | grep '*' | cut -b 10-20)
trimed_upstream="$(echo -e "${upstream}" | tr -d '[:space:]')"
echo $trimed_upstream
}
function get_local_revision {
loc=$(svn status --show-updates | tail -n 1 | cut -d ':' -f 2)
trimed_loc="$(echo -e "${loc}" | tr -d '[:space:]')"
echo $trimed_loc
}
function notify {
notify-send "$(pwd) needs update" \
"Server: rev$(get_upstream_revision), local rev$(get_local_revision)"
}
old_status=-1
# Main loop
while true; do
[ "$VERBOSE" == "true" ] && echo Polling server at $(date)
svn_is_up_to_date
new_status=$?
if [ "$new_status" != "0" ]; then
[ "$old_status" != "$new_status" ] && notify
fi
sleep $POLLFREQ
old_status=$new_status
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment