mirror of
https://github.com/golang/go.git
synced 2025-05-29 03:11:26 +00:00
cmd/go/internal/vcweb: set GIT_PROTOCOL in the git CGI handler
This works around a bug in 'git http-backend' that was fixed in
Git 2.34.0,¹ and will hopefully allow the tests in
cmd/go/internal/modfetch/codehost to pass reliably using older
Git releases (I tested with 2.30.2).
¹ff6a37c99e
Fixes #56881.
Change-Id: Icd2e4d252d5f712685d146f34e11922dd0c41ff0
Reviewed-on: https://go-review.googlesource.com/c/go/+/549795
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
23fee06a14
commit
6aa482681c
@ -280,9 +280,6 @@ func TestLatest(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !reflect.DeepEqual(info, tt.info) {
|
if !reflect.DeepEqual(info, tt.info) {
|
||||||
if !reflect.DeepEqual(info.Tags, tt.info.Tags) {
|
|
||||||
testenv.SkipFlaky(t, 56881)
|
|
||||||
}
|
|
||||||
t.Errorf("Latest: incorrect info\nhave %+v (origin %+v)\nwant %+v (origin %+v)", info, info.Origin, tt.info, tt.info.Origin)
|
t.Errorf("Latest: incorrect info\nhave %+v (origin %+v)\nwant %+v (origin %+v)", info, info.Origin, tt.info, tt.info.Origin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -661,9 +658,6 @@ func TestStat(t *testing.T) {
|
|||||||
}
|
}
|
||||||
info.Origin = nil // TestLatest and ../../../testdata/script/reuse_git.txt test Origin well enough
|
info.Origin = nil // TestLatest and ../../../testdata/script/reuse_git.txt test Origin well enough
|
||||||
if !reflect.DeepEqual(info, tt.info) {
|
if !reflect.DeepEqual(info, tt.info) {
|
||||||
if !reflect.DeepEqual(info.Tags, tt.info.Tags) {
|
|
||||||
testenv.SkipFlaky(t, 56881)
|
|
||||||
}
|
|
||||||
t.Errorf("Stat: incorrect info\nhave %+v\nwant %+v", *info, *tt.info)
|
t.Errorf("Stat: incorrect info\nhave %+v\nwant %+v", *info, *tt.info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,16 +37,35 @@ func (h *gitHandler) Handler(dir string, env []string, logger *log.Logger) (http
|
|||||||
return nil, ServerNotInstalledError{name: "git"}
|
return nil, ServerNotInstalledError{name: "git"}
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := &cgi.Handler{
|
baseEnv := append(slices.Clip(env),
|
||||||
Path: h.gitPath,
|
"GIT_PROJECT_ROOT="+dir,
|
||||||
Logger: logger,
|
"GIT_HTTP_EXPORT_ALL=1",
|
||||||
Args: []string{"http-backend"},
|
)
|
||||||
Dir: dir,
|
|
||||||
Env: append(slices.Clip(env),
|
handler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
|
||||||
"GIT_PROJECT_ROOT="+dir,
|
// The Git client sends the requested Git protocol version as a
|
||||||
"GIT_HTTP_EXPORT_ALL=1",
|
// "Git-Protocol" HTTP request header, which the CGI host then converts
|
||||||
),
|
// to an environment variable (HTTP_GIT_PROTOCOL).
|
||||||
}
|
//
|
||||||
|
// However, versions of Git older that 2.34.0 don't recognize the
|
||||||
|
// HTTP_GIT_PROTOCOL variable, and instead need that value to be set in the
|
||||||
|
// GIT_PROTOCOL variable. We do so here so that vcweb can work reliably
|
||||||
|
// with older Git releases. (As of the time of writing, the Go project's
|
||||||
|
// builders were on Git version 2.30.2.)
|
||||||
|
env := slices.Clip(baseEnv)
|
||||||
|
if p := req.Header.Get("Git-Protocol"); p != "" {
|
||||||
|
env = append(env, "GIT_PROTOCOL="+p)
|
||||||
|
}
|
||||||
|
|
||||||
|
h := &cgi.Handler{
|
||||||
|
Path: h.gitPath,
|
||||||
|
Logger: logger,
|
||||||
|
Args: []string{"http-backend"},
|
||||||
|
Dir: dir,
|
||||||
|
Env: env,
|
||||||
|
}
|
||||||
|
h.ServeHTTP(w, req)
|
||||||
|
})
|
||||||
|
|
||||||
return handler, nil
|
return handler, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user