]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/git/compat
15eb261e488592189fdf45e74bcb7fcfdb16867f
[plan9front.git] / sys / src / cmd / git / compat
1 #!/bin/rc
2
3 rfork e
4
5 opts=()
6 args=()
7
8 fn cmd_init{
9         while(~ $#* 0){
10                 switch($1){
11                 case --bare
12                         opts=(-b)
13                 case -- 
14                         # go likes to use these
15                 case -*
16                         die unknown command init $*
17                 case *
18                         args=($args $1)
19                 }
20                 shift
21         }
22         ls >[1=2]
23         git/init $opts $args
24 }
25
26 fn cmd_clone{
27         branch=()
28         while( ! ~ $#* 0){
29                 switch($1){
30                 case -b
31                         branch=$2
32                         shift
33                 case --
34                         # go likes to use these
35                 case -*
36                         die unknown command clone $*
37                 case *
38                         args=($args $1)
39                 }
40                 shift
41         }
42         git/clone $opts $args
43         if(~ $#branch 1)
44                 git/branch -n -b $1 origin/$1
45 }
46
47 fn cmd_pull{
48         if(~ $1 -*)
49                 die unknown options for pull $*
50         git/pull
51 }
52
53 fn cmd_fetch{
54         while(~ $#* 0){
55                 switch($1){
56                 case --all
57                         opts=($opts -a)
58                 case -f
59                         opts=($opts -u $2)
60                         shift
61                 case --
62                         # go likes to use these
63                 case -*
64                         die unknown command clone $*
65                 case *
66                         args=($args $1)
67                 }
68                 shift
69         }       
70         git/pull -f $opts
71 }
72
73
74 fn cmd_checkout{
75         if(~ $1 -*)
76                 die unknown command pull $*
77         if(~ $#* 0)
78                 die git checkout branch
79         git/branch $b
80 }
81
82 fn cmd_submodule {
83         if(test -f .gitmodules)
84                 die 'submodules unsupported'
85 }
86
87 fn cmd_rev-parse{
88         while(~ $1 -*){
89                 switch($1){
90                 case --git-dir
91                         echo $gitroot/.git
92                         shift
93                 case --abbrev-ref
94                         echo `{dcmd git9/branch | sed s@^heads/@@g}
95                         shift
96                 case *
97                         dprint option $opt
98                 }
99                 shift
100         }
101 }
102
103 fn cmd_show-ref{
104         if(~ $1 -*)
105                 die unknown command pull $*
106         filter=cat
107         if(~ $#* 0)
108                 filter=cat
109         if not
110                 filter='-e(^|/)'^$*^'$'
111         for(b in `$nl{cd $gitroot/.git/refs/ && walk -f})
112                 echo `{cat $gitroot/.git/refs/$b} refs/$b 
113 }
114
115 fn cmd_remote{
116         if({! ~ $#* 3 && ! ~ $#* 4} || ! ~ $1 add)
117                 die unimplemented remote cmd $*
118         name=$2
119         url=$3
120         if(~ $3 '--')
121                 url=$4
122         >>$gitroot/.git/config{
123                 echo '[remote "'$name'"]'
124                 echo '  url='$url
125         }
126 }
127
128 fn cmd_version{
129         echo git version 2.2.0
130 }
131
132
133 fn usage{
134         echo 'git <command> <args>' >[1=2]
135         exit usage
136 }
137
138 fn die {
139         >[1=2] echo git $_cmdname: $*
140         exit $_cmdname: $*
141 }
142
143 _cmdname=$1
144 if(~ $0 *compat){
145         ramfs -m /n/gitcompat
146         touch /n/gitcompat/git
147         bind $0 /n/gitcompat/git
148         path=( /n/gitcompat $path )
149         exec rc
150 }
151
152 if(! test -f '/env/fn#cmd_'$1)
153         die git $1: commmand not implemented
154 if(! ~ $1 init && ! ~ $1 clone)
155         gitroot=`{git/conf -r} || die repo
156
157 cmd_$1 $*(2-)
158 exit ''