Created
October 10, 2014 16:50
-
-
Save csrui/350b20b3fb19ae76f3c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function update_git_repo() { | |
GIT_DIR=$1 | |
GIT_REMOTE=$2 | |
GIT_BRANCH=${3:-master} | |
if [ ! -d $GIT_DIR ]; then | |
CURRENT_SHA="" | |
git clone --depth 1 $GIT_REMOTE $GIT_DIR -b $GIT_BRANCH | |
else | |
CURRENT_REMOTE=$(cd $GIT_DIR && git config --get remote.origin.url || true) | |
if [ "$GIT_REMOTE" == "$CURRENT_REMOTE" ]; then | |
CURRENT_SHA=$(cat $GIT_DIR/.git/refs/heads/$GIT_BRANCH) | |
else | |
rm -Rf $GIT_DIR | |
exit 0 # Process manager should restart this script | |
fi | |
fi | |
cd $GIT_DIR && \ | |
git fetch && \ | |
git reset --hard origin/$GIT_BRANCH | |
NEW_SHA=$(cat $GIT_DIR/.git/refs/heads/$GIT_BRANCH) | |
} | |
update_git_repo "/tmp/myrepo" "git://example.com/my/repo.git" | |
sleep 60 # No need for a tight loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment