]> git.donarmstrong.com Git - bin.git/commitdiff
add update_git_repos command
authorDon Armstrong <don@donarmstrong.com>
Thu, 5 Jun 2014 18:34:38 +0000 (11:34 -0700)
committerDon Armstrong <don@donarmstrong.com>
Thu, 5 Jun 2014 18:34:38 +0000 (11:34 -0700)
update_git_repos [new file with mode: 0755]

diff --git a/update_git_repos b/update_git_repos
new file mode 100755 (executable)
index 0000000..8bb73ff
--- /dev/null
@@ -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;