summaryrefslogtreecommitdiff
path: root/update-submodule
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2020-11-17 19:14:53 +0100
committerErich Eckner <git@eckner.net>2020-11-17 19:14:53 +0100
commit6fbe63d499c63813940318d54197c9cb96d4f428 (patch)
tree10dc90a87dc4f898dc7700fa60057f31afbf5c6d /update-submodule
parentaa2302de2efdd849f0c05fe0b089b435db99127a (diff)
downloadarchlinuxewe.git.save-6fbe63d499c63813940318d54197c9cb96d4f428.tar.xz
revert git-removal
Diffstat (limited to 'update-submodule')
-rwxr-xr-xupdate-submodule34
1 files changed, 34 insertions, 0 deletions
diff --git a/update-submodule b/update-submodule
new file mode 100755
index 00000000..326cbe3c
--- /dev/null
+++ b/update-submodule
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+pkgSrcDir="$1"
+submoduleDir="$2"
+url="$3"
+path="${url%% *}"
+url="${url#${path} }"
+
+if [ -d "${path}" ] && [ -n "$(ls -A "${path}")" ]; then
+ git -C "${pkgSrcDir}" submodule update 2>/dev/null || true
+ exit
+fi
+
+if [ ! -f "${path}" ]; then
+ >&2 echo 'update-submodule needs a commit'
+ >&2 printf '"%s" ' "$@"
+ >&2 printf '\n'
+ exit 1
+fi
+
+commit=$(cat "${path}")
+rm "${path}"
+mkdir -p "${path}"
+if [ -d "${submoduleDir}" ]; then
+ upstream="${submoduleDir}/${path}"
+ if [ ! -d "${upstream}" ]; then
+ git clone -q "${url}" "${upstream}"
+ fi
+else
+ upstream="${pkgSrcDir}/${path}"
+fi
+git -C "${upstream}" pull -q --ff-only
+git -C "${upstream}" archive "${commit}" \
+| tar -C "${path}" -x