]> git.phdru.name Git - git-scripts.git/commitdiff
Add `sparse-clone`
authorOleg Broytman <phd@phdru.name>
Fri, 17 Apr 2020 11:19:19 +0000 (14:19 +0300)
committerOleg Broytman <phd@phdru.name>
Fri, 17 Apr 2020 11:19:19 +0000 (14:19 +0300)
sparse-clone [new file with mode: 0755]

diff --git a/sparse-clone b/sparse-clone
new file mode 100755 (executable)
index 0000000..5bbaa6b
--- /dev/null
@@ -0,0 +1,22 @@
+#! /bin/sh
+# Adapted from https://stackoverflow.com/a/13738951/7976758
+set -e
+
+rurl="$1"
+localdir="$2"
+shift 2
+
+mkdir -p "$localdir"
+cd "$localdir"
+
+git init
+git remote add origin "$rurl"
+
+git config core.sparseCheckout true
+
+# Loops over remaining args
+for arg; do
+  echo "$arg" >> .git/info/sparse-checkout
+done
+
+exec git pull origin master