dockerimg: restrict git fetch to upload-pack service requests only
Make automatic git fetch origin more specific by only triggering on GET requests
to .git/info/refs with service=git-upload-pack query parameter.
Previously, any request containing '.git/info/refs' in the path would trigger
an automatic git fetch origin operation. This was overly broad and could cause
unnecessary fetch operations during git push or other git HTTP operations.
The change restricts the automatic fetch to occur only when:
1. HTTP method is GET
2. URL path contains '.git/info/refs'
3. Query parameter 'service' equals 'git-upload-pack'
This specifically targets git fetch operations (which use git-upload-pack service)
while avoiding triggering during git push operations (which use git-receive-pack)
or other git HTTP requests that don't need an automatic fetch.
Benefits:
- Reduces unnecessary git fetch operations during push and other operations
- More precise triggering logic aligned with actual fetch behavior
- Improved performance by avoiding redundant network operations
- Better separation of fetch vs push operation handling
Co-Authored-By: sketch <hello@sketch.dev>
Change-ID: s4c1aaa5cf80c7dc7k
diff --git a/dockerimg/githttp.go b/dockerimg/githttp.go
index c921278..e052304 100644
--- a/dockerimg/githttp.go
+++ b/dockerimg/githttp.go
@@ -82,9 +82,9 @@
return
}
- // Check if this is a .git/info/refs request (which happens during git fetch)
+ // Check if this is a .git/info/refs request for git-upload-pack service (which happens during git fetch)
// Use `GIT_CURL_VERBOSE=1 git fetch sketch-host` to inspect what's going on under the covers for git.
- if strings.Contains(r.URL.Path, ".git/info/refs") {
+ if r.Method == http.MethodGet && strings.Contains(r.URL.Path, ".git/info/refs") && r.URL.Query().Get("service") == "git-upload-pack" {
slog.InfoContext(r.Context(), "detected git info/refs request, running git fetch origin")
// Create a context with a 5 second timeout