commit f16259717222a423c2725e58d318c2ee19c358a4 Author: Louis Burda <quent.burda@gmail.com> Date: Thu, 9 May 2024 21:21:54 +0200 Add subgit and subgit-clone Diffstat:
A | Makefile | | | 10 | ++++++++++ |
A | subgit | | | 21 | +++++++++++++++++++++ |
A | subgit-clone | | | 21 | +++++++++++++++++++++ |
3 files changed, 52 insertions(+), 0 deletions(-)
diff --git a/Makefile 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 @@ -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 @@ -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"