summaryrefslogtreecommitdiffstats
path: root/newbin/fetchgit
diff options
context:
space:
mode:
Diffstat (limited to 'newbin/fetchgit')
-rwxr-xr-xnewbin/fetchgit25
1 files changed, 25 insertions, 0 deletions
diff --git a/newbin/fetchgit b/newbin/fetchgit
new file mode 100755
index 000000000..b9fe90854
--- /dev/null
+++ b/newbin/fetchgit
@@ -0,0 +1,25 @@
+#! /bin/sh
+# usage: fetchgit REVISION URL WORKTREE
+set -euf
+
+git_rev=$1
+git_url=$2
+worktree=$3
+
+if [ ! -d "$worktree" ]; then
+ mkdir -p "$worktree"
+fi
+
+cd "$worktree"
+
+git init -q
+
+if ! current_url=$(git config remote.src.url); then
+ git remote add src "$git_url"
+elif [ "$current_url" != "$git_url" ]; then
+ git remote set-url src "$git_url"
+fi
+
+git fetch src
+
+git checkout "$git_rev"