]> gitweb.fluxo.info Git - scripts.git/commitdiff
Adding git-subtree-update
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 12 Feb 2014 16:44:04 +0000 (14:44 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 12 Feb 2014 16:44:04 +0000 (14:44 -0200)
git-subtree-update [new file with mode: 0755]

diff --git a/git-subtree-update b/git-subtree-update
new file mode 100755 (executable)
index 0000000..f0ad28e
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/bash
+#
+# Update a subtree.
+#
+
+# Parameters
+BASENAME="`basename $0`"
+REMOTE="$1"
+FOLDER="$2"
+
+# Syntax
+if [ -z "$2" ]; then
+  echo "usage: $BASENAME <gitremote> <folder>"
+  exit 1
+fi
+
+# Check remote
+if ! git remote | grep -qe '^remote'; then
+  echo "fatal: no such remote $REMOTE"
+  exit
+fi
+
+# Fetch the remote
+git fetch $REMOTE master
+
+# Process
+if [ ! -d "$FOLDER" ]; then
+  # Add a subtree
+  git subtree add --prefix $FOLDER $REMOTE master --squash
+else
+  # Update a subtree
+  git subtree pull --prefix $FOLDER $REMOTE master --squash
+fi