@@ -121,6 +121,10 @@ func serviceRpc(hr HandlerReq) {
121121
122122 args := []string {rpc , "--stateless-rpc" , dir }
123123 cmd := exec .Command (config .GitBinPath , args ... )
124+ version := r .Header .Get ("Git-Protocol" )
125+ if len (version ) != 0 {
126+ cmd .Env = append (os .Environ (), fmt .Sprintf ("GIT_PROTOCOL=%s" , version ))
127+ }
124128 cmd .Dir = dir
125129 in , err := cmd .StdinPipe ()
126130 if err != nil {
@@ -155,16 +159,18 @@ func getInfoRefs(hr HandlerReq) {
155159 w , r , dir := hr .w , hr .r , hr .Dir
156160 service_name := getServiceType (r )
157161 access := hasAccess (r , dir , service_name , false )
158-
162+ version := r . Header . Get ( "Git-Protocol" )
159163 if access {
160164 args := []string {service_name , "--stateless-rpc" , "--advertise-refs" , "." }
161- refs := gitCommand (dir , args ... )
165+ refs := gitCommand (dir , version , args ... )
162166
163167 hdrNocache (w )
164168 w .Header ().Set ("Content-Type" , fmt .Sprintf ("application/x-git-%s-advertisement" , service_name ))
165169 w .WriteHeader (http .StatusOK )
166- w .Write (packetWrite ("# service=git-" + service_name + "\n " ))
167- w .Write (packetFlush ())
170+ if len (version ) == 0 {
171+ w .Write (packetWrite ("# service=git-" + service_name + "\n " ))
172+ w .Write (packetFlush ())
173+ }
168174 w .Write (refs )
169175 } else {
170176 updateServerInfo (dir )
@@ -281,17 +287,20 @@ func getConfigSetting(service_name string, dir string) bool {
281287
282288func getGitConfig (config_name string , dir string ) string {
283289 args := []string {"config" , config_name }
284- out := string (gitCommand (dir , args ... ))
290+ out := string (gitCommand (dir , "" , args ... ))
285291 return out [0 : len (out )- 1 ]
286292}
287293
288294func updateServerInfo (dir string ) []byte {
289295 args := []string {"update-server-info" }
290- return gitCommand (dir , args ... )
296+ return gitCommand (dir , "" , args ... )
291297}
292298
293- func gitCommand (dir string , args ... string ) []byte {
299+ func gitCommand (dir string , version string , args ... string ) []byte {
294300 command := exec .Command (config .GitBinPath , args ... )
301+ if len (version ) > 0 {
302+ command .Env = append (os .Environ (), fmt .Sprintf ("GIT_PROTOCOL=%s" , version ))
303+ }
295304 command .Dir = dir
296305 out , err := command .Output ()
297306
0 commit comments