git » base-pkgbuilds.git » commit 5ca2544

git-it-up

author Urja (ARMLFS builder)
2024-06-23 11:31:17 UTC
committer Urja (ARMLFS builder)
2024-06-23 11:31:17 UTC
parent 14643a84f0c6d12d1f66ef61834e47a798a68801

git-it-up

git-it-up.sh +51 -0

diff --git a/git-it-up.sh b/git-it-up.sh
new file mode 100755
index 0000000..a6644c2
--- /dev/null
+++ b/git-it-up.sh
@@ -0,0 +1,51 @@
+#!/bin/bash
+set -e
+
+if [ "$(whoami)" != "builder" ]; then
+	echo "Will re-exec self ($0) as builder"
+	sleep 0.2s
+	L="$@"
+	exec su builder -c "$0 $L"
+fi
+
+gititup() {
+	cd $1
+pkgver=$(grep "pkgver=" PKGBUILD | head -1 | cut -d '=' -f 2)
+	echo $1 $pkgver
+	[ -e .githidden ] && mv .githidden .git
+	if [ ! -e .gitignore ]; then
+	cat > .gitignore << "EOF"
+/src/
+/pkg/
+EOF
+	fi
+	if [ -e .git ]; then
+		BRANCH="$(git branch --show-current)"
+		if [[ -z "$BRANCH" ]]; then
+			if git branch | grep -q main; then
+				git branch -m main arch-main
+			fi
+			git switch -c main
+		fi
+		if [[ -n "$(git status --porcelain)" ]]; then
+			git add .
+			git commit -m "$1 $pkgver"
+		fi
+	else
+		git init .
+		git add .
+		git commit -m "Initial $1 $pkgver"
+	fi
+}
+
+L="$@"
+if [[ -z "$L" ]]; then
+	L="$(find -mindepth 1 -maxdepth 1 -type d)"
+fi
+
+for d in $L; do
+	d=$(basename $d)
+	if [[ -O "$d" ]] && grep -q $d order; then
+		(gititup $d)
+	fi
+done