git » kde5-pkgbuilds.git » main » tree

[main] / git-it-up.sh

#!/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