add bin/git-pull-and-run-if-origin-changed
This commit is contained in:
parent
77aba67af9
commit
1fbcd661b0
32
bin/git-pull-and-run-if-origin-changed
Executable file
32
bin/git-pull-and-run-if-origin-changed
Executable file
@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if [ -z "$1" ]; then
|
||||||
|
echo "command missing in arguments" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get the current branch name
|
||||||
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
|
while true; do
|
||||||
|
|
||||||
|
# get the latest commit hashes from origin and local
|
||||||
|
git fetch origin
|
||||||
|
LOCAL=$(git rev-parse HEAD)
|
||||||
|
REMOTE=$(git rev-parse origin/$BRANCH)
|
||||||
|
|
||||||
|
# check if the local branch differs from the remote branch
|
||||||
|
if [ "$LOCAL" != "$REMOTE" ]; then
|
||||||
|
echo "pulling changes from origin"
|
||||||
|
git pull origin $BRANCH
|
||||||
|
|
||||||
|
# run the command
|
||||||
|
echo "Running $*"
|
||||||
|
"$@"
|
||||||
|
else
|
||||||
|
echo "no changes detected on the origin branch"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "waiting for 1 minute before checking again..."
|
||||||
|
sleep 60
|
||||||
|
done
|
Loading…
Reference in New Issue
Block a user