summaryrefslogtreecommitdiff
path: root/sys/src/cmd/git/compat
blob: f61ff71e9271799696a264837be0c8ab33d61fcd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#!/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]
	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
	}
	git/clone $opts $args
	if(~ $#branch 1)
		git/branch -n -b $1 origin/$1
}

fn cmd_pull{
	if(~ $1 -*)
		die unknown options for pull $*
	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
	}	
	git/pull -f $opts
}


fn cmd_checkout{
	if(~ $1 -*)
		die unknown command pull $*
	if(~ $#* 0)
		die git checkout branch
	git/branch $b
}

fn cmd_submodule {
	if(test -f .gitmodules)
		die 'submodules unsupported'
}

fn cmd_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 *
			die unknown 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 `$nl{cd $gitroot/.git/refs/ && walk -f})
		echo `{cat $gitroot/.git/refs/$b} refs/$b 
}

fn cmd_rev-parse{
	switch($1){
	case --git-dir
		echo `{git/conf -r}^/.git
	case *
		die 'unknown rev-parse '$*
	}
}

fn cmd_remote{
	if({! ~ $#* 3 && ! ~ $#* 4} || ! ~ $1 add)
		die unimplemented remote cmd $*
	name=$2
	url=$3
	if(~ $3 '--')
		url=$4
	>>$gitroot/.git/config{
		echo '[remote "'$name'"]'
		echo '	url='$url
	}
}

fn cmd_log{
	count=()
	format=''
	while(~ $1 -*){
		switch($1){
		case --format
			format=$2
			shift
		case '--format='*
			format=`{echo $1 | sed 's/--format=//g'}
		case -n
			count=-n$2
			shift
		case -n*
			count=$1
		case *
			dprint option $opt
		}
		shift
	}
	@{cd $gitroot && git/fs}
	switch($format){
	case ''
		git/log $count
	case '%H:%ct'
		for(c in `{git/log -s $count| awk '{print $1}'})
			echo $c:`{mtime $gitroot/.git/fs/object/$c/msg}
	case '%h %cd'
		for(c in `{git/log -s $count| awk '{print $1}'})
			echo $c `{date `{mtime $gitroot/.git/fs/object/$c/msg}}
	}

}

fn cmd_show{
	cmd_log -n1 $*
}

fn cmd_ls-remote{
	if(~ $1 -q)
		shift
	remote=`$nl{git/conf 'remote "'$1'".url'}
	if(~ $#remote 0)
		remote=$1
	git/get -l $remote | awk '/^remote/{print $3"\t"$2}'
}

fn cmd_version{
	echo git version 2.2.0
}

fn cmd_status{
	echo
}

fn usage{
	echo 'git <command> <args>' >[1=2]
	exit usage
}

fn die {
	>[1=2] echo git $_cmdname: $*
	exit $_cmdname: $*
}

_cmdname=$1
if(~ $0 *compat){
	ramfs -m /n/gitcompat
	touch /n/gitcompat/git
	bind $0 /n/gitcompat/git
	path=( /n/gitcompat $path )
	exec rc
}

if(~ $#gitcompatdebug 1)
	echo running  $* >>/tmp/gitlog

if(~ $1 -c)
	shift 2
if(~ $1 -c*)
	shift 1
if(! test -f '/env/fn#cmd_'$1)
	die git $1: commmand not implemented
if(! ~ $1 init && ! ~ $1 clone)
	gitroot=`{git/conf -r} || die repo

if(~ $#gitcompatdebug 1)
	cmd_$1 $*(2-) | tee >>/tmp/gitlog
if not
	cmd_$1 $*(2-)
exit ''