.vim/bundle: Update vim bundle submodules
[dotfiles.git] / bin / git-subup
index aec9632313ac51029c5b1a6aaa28f014bdf4f158..54472e60997be91c6bac93341926963104ef428f 100755 (executable)
@@ -1,8 +1,22 @@
-#!/bin/sh
-# Checkout and update source for all registered submodules (.gitmodules)
+#!/bin/bash
+# Checkout and update source for all registered submodules (.gitmodules).
+# Optionally 'git pull' on each submodule to check for updates.
 
+# Change to root directory
 cd $(git rev-parse --show-toplevel)
-git submodule update --init --checkout --quiet
-git submodule sync --quiet
-git submodule foreach --quiet git checkout --quiet -B master origin/HEAD
-git submodule foreach git pull --prune origin
+
+# Ensure all submodules (and child submodules) are checked-out
+git submodule update --init --checkout --recursive
+
+# Update submodules' remotes based on .gitmodules
+git submodule sync
+
+# Forcibly update each submodule's "master" branch to be the current revision
+# in case HEAD is detached (e.g. due to "git submodule update --checkout")
+git submodule foreach --recursive 'git checkout --quiet -B master'
+
+if [ "$1" = "pull" ]; then
+    # Fetch & pull any new updates from submodule's origin (but *NOT* any child
+    # submodule updates -- those should come from the submodule proper)
+    git submodule foreach 'git-up origin'
+fi