ref: f19481bc6ff48f9833294805b359896916a8b788
parent: 777e9c6d56ed9eaeb28196b3b6da77a34139f892
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Sep 3 22:02:02 EDT 2020
git/compat: initial import (thanks halfwit) Add a 'git/compat' tool that puts us into a shell with a 'git' compatibility stub. This git stub gives us enough of the git command line to support ported unix tools like go.
--- /dev/null
+++ b/compat
@@ -1,0 +1,146 @@
+#!/bin/rc
+
+rfork e
+
+opts=()
+args=()
+
+fn cmd_init{
+ while(~ $#* 0){
+ switch($1){
+ case --bare
+ opts=(-b)
+ case --
+ # go likes to use these
+ case -*
+ die unknown command init $*
+ case *
+ args=($args $1)
+ }
+ shift
+ }
+ ls >[1=2]
+ /$cputype/bin/git/init $opts $args
+}
+
+fn cmd_clone{
+ branch=()
+ while( ! ~ $#* 0){
+ switch($1){
+ case -b
+ branch=$2
+ shift
+ case --
+ # go likes to use these
+ case -*
+ die unknown command clone $*
+ case *
+ args=($args $1)
+ }
+ shift
+ }
+ /$cputype/bin/git/clone $opts $args
+ if(~ $#branch 1)
+ /$cputype/bin/git/branch -n -b $1 origin/$1
+}
+
+fn cmd_pull{
+ if(~ $1 -*)
+ die unknown options for pull $*
+ /$cputype/bin/git/pull
+}
+
+fn cmd_fetch{
+ while(~ $#* 0){
+ switch($1){
+ case --all
+ opts=($opts -a)
+ case -f
+ opts=($opts -u $2)
+ shift
+ case --
+ # go likes to use these
+ case -*
+ die unknown command clone $*
+ case *
+ args=($args $1)
+ }
+ shift
+ }
+ /$cputype/bin/git/pull -f $opts
+}
+
+
+fn cmd_checkout{
+ if(~ $1 -*)
+ die unknown command pull $*
+ if(~ $#* 0)
+ die git checkout branch
+ /$cputype/bin/git/branch $b
+}
+
+fn rev-parse{
+ while(~ $1 -*){
+ switch($1){
+ case --git-dir
+ echo $gitroot/.git
+ shift
+ case --abbrev-ref
+ echo `{dcmd git9/branch | sed s@^heads/@@g}
+ shift
+ case *
+ dprint option $opt
+ }
+ shift
+ }
+}
+
+fn cmd_show-ref{
+ if(~ $1 -*)
+ die unknown command pull $*
+ filter=cat
+ if(~ $#* 0)
+ filter=cat
+ if not
+ filter='-e(^|/)'^$*^'$'
+ for(b in `{cd $gitroot/.git/refs/ && walk -f})
+ echo `{cat $gitroot/.git/refs/$b} refs/$b
+}
+
+fn cmd_remote{
+ if(! ~ $1 add)
+ die unimplemented remote cmd $*
+ >>$gitroot/.git/config{
+ echo '[remote "'$2'"]'
+ echo ' url='$3
+ }
+}
+
+fn cmd_version{
+ echo git version 2.2.0
+}
+
+
+fn usage{
+ echo 'git <command> <args>' >[1=2]
+ exit usage
+}
+
+fn die {
+ >[1=2] echo $*
+ exit boom
+}
+
+if(~ $0 *compat){
+ ramfs -m /n/gitcompat
+ cp $0 /n/gitcompat/git
+ path=( /n/gitcompat $path )
+ exec rc
+}
+
+if(! test -f '/env/fn#cmd_'$1){
+ die git $1: commmand not implemented
+}
+
+gitroot=`{git/conf -r} || exit repo
+cmd_$1 $*(2-)
--- a/git.1
+++ b/git.1
@@ -38,6 +38,8 @@
]
.I file...
.PP
+.B git/compat
+.PP
.B git/conf
[
.B -r
@@ -408,6 +410,16 @@
.TP
A
Added, does not yet exist in a commit.
+
+.PP
+.B Git/compat
+spawns an rc subshell with a compatibility stub in
+.IR $path .
+This compatibility stub provides enough of the unix
+.I git
+commands to run tools like
+.I go get
+but not much more.
.SH REF SYNTAX