]> git.lizzy.rs Git - plan9front.git/blob - sys/src/cmd/git/compat
git/compat: add support for ls-remote [-d]
[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_ls-remote{
129         if(~ $1 -q)
130                 shift
131         remote=`$nl{git/conf 'remote "'$1'".url'}
132         if(~ $#remote 0)
133                 remote=$1
134         git/fetch -l $remote | awk '/^remote/{print $3"\t"$2}'
135 }
136
137 fn cmd_version{
138         echo git version 2.2.0
139 }
140
141
142 fn usage{
143         echo 'git <command> <args>' >[1=2]
144         exit usage
145 }
146
147 fn die {
148         >[1=2] echo git $_cmdname: $*
149         exit $_cmdname: $*
150 }
151
152 _cmdname=$1
153 if(~ $0 *compat){
154         ramfs -m /n/gitcompat
155         touch /n/gitcompat/git
156         bind $0 /n/gitcompat/git
157         path=( /n/gitcompat $path )
158         exec rc
159 }
160
161 if(! test -f '/env/fn#cmd_'$1)
162         die git $1: commmand not implemented
163 if(! ~ $1 init && ! ~ $1 clone)
164         gitroot=`{git/conf -r} || die repo
165
166 echo $* >/tmp/gitlog
167 cmd_$1 $*(2-)
168 exit ''