#!/bin/rc . /sys/lib/git/common.rc gitup -m opts=() args=() fn fakerepo { mkdir -p /tmp/fakerepo.$pid/.git bind -c $1 /tmp/fakerepo.$pid/.git cd /tmp/fakerepo.$pid } fn dcmd { if(~ $#gitdebug 1) echo $* >[1=2] $* } fn cmd_init{ while(~ $1 -*){ switch($1){ case --bare opts=(-b) case -* die unknown command init $* case * args=($args $1) } shift } ls >[1=2] dcmd git/init $opts $args } fn cmd_clone{ branch=() while(~ $1 -*){ switch($1){ case -b branch=$2 shift case -* die unknown command clone $* case * args=($args $1) } shift } dcmd git/init $opts $args if(~ $#branch 1) dcmd git/branch -n -b $1 origin/$1 } fn cmd_pull{ if(~ $1 -*) die unknown command pull $* fakerepo `{pwd} dcmd git/pull } fn cmd_fetch{ while(~ $1 -*){ switch($1){ case --all opts=($opts -a) case -f opts=($opts -u $2) shift case -* die unknown command clone $* case * args=($args $1) } shift } fakerepo `{pwd} dcmd git/pull -f $opts } fn cmd_checkout{ if(~ $1 -*) die unknown command pull $* if(~ $#* 0) die git checkout branch dcmd git/branch $b } fn cmd_log{ dcmd log $* exit unimpl } fn rev-parse{ while(~ $1 -*){ switch($1){ case --git-dir echo .git shift case --abbrev-ref echo `{dcmd git/branch | sed s@^heads/@@g} shift case * dprint option $opt } shift } } fn cmd_show-ref{ if(~ $1 -*) die unknown command pull $* for(b in `{cd .dcmd git/refs/ && walk -f}) echo`{cat .dcmd git/refs/$b} refs/$b } fn cmd_remote{ if(! ~ $1 add) die unimplemented remote cmd $* fakerepo `{pwd} >>.git/config{ echo '[remote "'$2'"]' echo ' url='$3 } } fn cmd_submodule{ dcmd submodule $* exit unimpl } fn cmd_version{ echo git version 2.2.0 } fn cmd_config{ dcmd config $* } fn usage{ echo 'git ' >[1=2] exit usage } echo '=== cmd:' $* >[1=2] echo '=== pwd:' `{pwd} >[1=2] cmd_$1 $*(2-)