Skip to content

Commit 5b4445b

Browse files
committed
add check for updates to git repo
1 parent 3ba6cdb commit 5b4445b

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

plugins/check_git_origin

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/bin/bash
2+
3+
if [ $# -ne 1 ]; then
4+
echo "check if a git repo is behind upstream"
5+
echo "Usage:"
6+
echo " $0 GIT_REPO"
7+
echo ""
8+
echo " GIT_REPO: path of git repo"
9+
exit 0
10+
fi
11+
12+
GIT_REPO=$1
13+
14+
TMPDIR=`mktemp -d /tmp/git-tmp.XXXXXX` || exit 4
15+
16+
pushd "$TMPDIR" >/dev/null || exit 4
17+
18+
cp -r $GIT_REPO . || exit 4
19+
cd *
20+
git fetch 2>/dev/null
21+
COMMIT_COUNT=$( git log --oneline master..origin/master | wc -l )
22+
23+
popd >/dev/null
24+
25+
rm -rf "$TMPDIR"
26+
27+
28+
if [ "$COMMIT_COUNT" -eq 0 ]; then
29+
echo "OK - git repo $GIT_REPO is up to date"
30+
exit 0
31+
else
32+
echo "WARNING - git repo $GIT_REPO is $COMMIT_COUNT commit(s) behind upstream"
33+
exit 1
34+
fi
35+
36+

0 commit comments

Comments
 (0)