summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Burda <quent.burda@gmail.com>2024-05-09 21:21:54 +0200
committerLouis Burda <quent.burda@gmail.com>2024-05-09 21:21:54 +0200
commitf16259717222a423c2725e58d318c2ee19c358a4 (patch)
treec42fb97e8ba4829fe934a0c376e452180b58520f
downloadsubgit-f16259717222a423c2725e58d318c2ee19c358a4.tar.gz
subgit-f16259717222a423c2725e58d318c2ee19c358a4.zip
Add subgit and subgit-clone
-rw-r--r--Makefile10
-rwxr-xr-xsubgit21
-rwxr-xr-xsubgit-clone21
3 files changed, 52 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..84148d6
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,10 @@
+DESTDIR ?=
+PREFIX ?= /usr/local
+BINDIR ?= /bin
+
+all:
+
+install:
+ install -m755 subgit subgit-clone -t "$(DESTDIR)$(PREFIX)$(BINDIR)"
+
+.PHONY: install all
diff --git a/subgit b/subgit
new file mode 100755
index 0000000..ed9f310
--- /dev/null
+++ b/subgit
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+# Find parent .subgit directory.
+path=$PWD
+while [ 1 ]; do
+ [ -d "$path/.subgit" ] && break
+ path=$(dirname "$path")
+ if [ "$path" = "/" ]; then
+ echo "No subgit found" 1>&2
+ exit 1
+ fi
+done
+
+# Create a temporary symlink.
+trap 'unlink "$path/.git"' EXIT
+ln -sf ".subgit" "$path/.git"
+
+# Proxy the command.
+git "$@"
diff --git a/subgit-clone b/subgit-clone
new file mode 100755
index 0000000..b6e78f5
--- /dev/null
+++ b/subgit-clone
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+if [ $# -lt 2 ]; then
+ echo "Usage: subgit-clone OPT.. REMOTE PATH"
+ exit 1
+fi
+
+path=${@: -1}
+
+git clone "$@"
+
+echo "remote=$(git -C "$path" remote get-url origin)" > "$path/.subgitrc"
+echo "branch=$(git -C "$path" branch --show-current)" >> "$path/.subgitrc"
+echo "commit=$(git -C "$path" rev-parse --verify HEAD)" >> "$path/.subgitrc"
+
+mv "$path/.git" "$path/.subgit"
+
+[ ! -f "$path/.gitignore" ] && echo "/.gitignore" >> "$path/.gitignore"
+echo "/.subgit" >> "$path/.gitignore"