shithub: git9

ref: 9d5b7ea0c9843da1ec5fb8a1357dc9c2ec9fa86d
dir: /init/

View raw version
#!/bin/rc

rfork e

fn usage{
	echo $0 '[-b] [-u upstream] name
	-b:	init bare repository' >[1=2]
	exit usage
}

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){
	echo $dir$sub already exists >[1=2]
	exit exists
}

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