aboutsummaryrefslogtreecommitdiff
path: root/git-subtree-update
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2014-09-18 16:36:24 -0300
committerSilvio Rhatto <user@example.org>2014-09-18 16:36:24 -0300
commit58ed624130253579365967fdc968bfc1d37279fb (patch)
tree561306cf85a85ba7712f46161ef13750be5af094 /git-subtree-update
downloadgit-subtree-58ed624130253579365967fdc968bfc1d37279fb.tar.gz
git-subtree-58ed624130253579365967fdc968bfc1d37279fb.tar.bz2
Initial import
Diffstat (limited to 'git-subtree-update')
-rwxr-xr-xgit-subtree-update33
1 files changed, 33 insertions, 0 deletions
diff --git a/git-subtree-update b/git-subtree-update
new file mode 100755
index 0000000..af45ed6
--- /dev/null
+++ b/git-subtree-update
@@ -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