From dd26430e414ec120d1aa6dd528724db16a347a89 Mon Sep 17 00:00:00 2001
From: Ben Sima <ben@bsima.me>
Date: Fri, 2 Sep 2022 09:59:02 -0400
Subject: add gitlab clone

---
 glclone | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100755 glclone

(limited to 'glclone')

diff --git a/glclone b/glclone
new file mode 100755
index 0000000..a81a229
--- /dev/null
+++ b/glclone
@@ -0,0 +1,35 @@
+#!/usr/bin/env bash
+set -e
+usage () {
+  printf "usage: $(basename $0) <owner>[/]<repo>\n" >&2
+  exit 1
+}
+already_exists () {
+  printf "%s\n" "$2"
+  exit 2
+}
+root=${GITLAB_ROOT:-"$HOME/src"}
+owner="$1"
+repo="$2"
+[ -z "$owner" ] && usage
+if [ -z "$repo" ]; then
+  IFS='/' read -ra parsed <<< "$owner"
+  owner="${parsed[0]}"
+  repo="${parsed[1]}"
+  if [ -z "$owner" ] || [ -z "$repo" ]; then
+    usage
+  fi
+fi
+dest="$root/$owner"
+dir="$dest/$repo"
+[ -d "$dir" ] && already_exists "$owner/$repo" "$dir"
+mkdir -p "$dest"
+cd "$dest"
+git clone "git@gitlab.com:$owner/$repo"
+git config \
+    --file="$dir/.git/config" \
+    --add remote.origin.fetch '+refs/pull/*/head:refs/pull/origin/*'
+git config \
+    --file="$dir/.git/config" \
+    --add remote.origin.fetch '+refs/pull/*/merge:refs/merge/origin/*'
+printf "%s\n" "$dest/$repo"
-- 
cgit v1.2.3