shithub: git9

ref: 24c6bf14ccc9292cd735b7427422a2e6b309c07b
dir: /push/

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

usage='
	git/push [-a] [-u upstream] [-b branch] [-r branch]
		-a       push all branches
		-b       push branch "branch" (default: current branch)
		-r       delete branch "branch" from upstream
		-u       push to remote "upstream" (default: origin)
'

gitup

remote=()
sendall=''
remove=()
force=()
upstream='origin'
branch=-b`{awk '$1=="branch"{print $2}' < /mnt/git/ctl}
while(~ $1 -*){
	switch($1){
	case -u
		shift
		upstream=$1
	case -a
		branch=-b`$nl{cd .git/refs/heads && walk -f}
	case -b
		shift
		branch=(-b$1 $branch)
	case -r
		shift
		remove=(-r$1 $remove);
	case -f
		force=-f
	case *
		usage
	}
	shift
}

if(! ~ $#* 0)
	usage
if(~ $#remote 0)
	remote=`{git/conf 'remote "'$upstream'".url'}
if(~ $#remote 0)
	remote=$upstream
if(~ $#remote 0)
	die 'no idea where to push'
if(~ $#branch 0)
	die 'no branches'
updates=`$nl{git/send $force $branch $remove $remote || die $status}
echo $updates
for(ln in $updates){
	u=`{echo $ln}
	refpath=`{echo $u(2) | sed 's@^refs/heads/@.git/refs/remotes/'$upstream'/@g'}
	switch($u(1)){
	case update;
		echo $u(4) > $refpath
		echo $u(2)^':' $u(3) '=>' $u(4)
	case delete;
		echo $u(2)^': removed'
		rm -f $refpath
	case uptodate;
		echo $u(2)^': up to date'
	}
}