shithub: git9

ref: 5577b5b51e56f5d043a9830903b2fb668f8451d1
dir: /init/

View raw version
#!/bin/rc -e
rfork ne
. /sys/lib/git/common.rc

usage='
	git/init [-b] [-u upstream] name
		-b        init bare repository
		-u        set remote "origin" to upstream
'

sub='/.git'
upstream=()
while(~ $1 -* && ! ~ $1 --){
	switch($1){
	case -b
		sub=''
	case -u
		upstream=$2
		shift
	case *
		usage
	}
	shift
}
if(~ $1 --)
	shift

if (~ $#* 0)
	dir=.
if not if(~ $#* 1)
	dir=$1
if not
	usage

if(test -e $dir$sub)
	die $dir$sub already exists

mkdir -p $dir$sub
dircp /sys/lib/git/template $dir/$sub
mkdir -p $dir/$sub/refs/heads
mkdir -p $dir/$sub/refs/remotes
>>$dir/$sub/config {
	if(! ~ $#upstream 0){
		echo '[remote "origin"]'
		echo '	url='$upstream
	}
	echo '[branch "master"]'
	echo '	remote = origin'
	echo '	merge = refs/heads/master' 
}