From: Don Armstrong Date: Thu, 5 Jun 2014 18:34:38 +0000 (-0700) Subject: add update_git_repos command X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e9c13bbc2bfc0b8a4950bf83efd1dcb3436a9ba1;p=bin.git add update_git_repos command --- diff --git a/update_git_repos b/update_git_repos new file mode 100755 index 0000000..8bb73ff --- /dev/null +++ b/update_git_repos @@ -0,0 +1,28 @@ +#!/bin/bash + +if [ "x$1" == "xdoit" ]; then + # fetch everything + git fetch; + # figure out if we should pull + # 1. no modified files + if [ -n "$(git status --porcelain -u no)" ]; then + # 2. Not detached head + if [ -n "$(git symbolic-ref HEAD)" ]; then + # 3. no commits which are not in origin + if [ -n "$(git rev-list \"^$(git remote|head -n 1)\" HEAD)" ]; then + # 3. machine is currently inactive for more than 1 hour + if [ "$IDLE_TIME" -gt 3600 ]; then + git pull; + fi; + fi; + fi; + fi; + + +else + IDLE_TIME=0 + if which xprintidle >/dev/null 2>&1; then + IDLE_TIME=$(($(xprintidle) / 1000 )); + fi; + IDLE_TIME="$IDLE_TIME" mr -d ~ -j5 run update_git_repos doit; +fi;