Skip to content

Commit a22ab2a

Browse files
Don't forward fetches with sha in want (#1313)
Most upstreams don't support this, so it only ever worked when the commit was fetched before. Change: no-sha-want
1 parent 3b89f31 commit a22ab2a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

josh-proxy/src/bin/josh-proxy.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ fn fetch_needed(
110110
head_ref: Option<&str>,
111111
head_ref_resolved: Option<&str>,
112112
) -> Result<bool, FetchError> {
113+
if let Some(head_ref) = head_ref {
114+
if head_ref != "HEAD" && !head_ref.starts_with("refs/") {
115+
// If the request is for fetching a sha, don't fetch, as most upstreams
116+
// don't support that. The rev should have been fetched previously by reference.
117+
return Ok(false);
118+
}
119+
}
120+
113121
let fetch_timer_ok = {
114122
if let Some(last) = service.fetch_timers.read()?.get(remote_url) {
115123
let since = std::time::Instant::now().duration_since(*last);

tests/proxy/clone_sha.t

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454

5555
$ cd ${TESTTMP}
5656

57+
$ git ls-remote http://localhost:8002/real_repo.git | tr '\t' ' '
58+
bb282e9cdc1b972fffd08fd21eead43bc0c83cb8 HEAD
59+
36c6ab9d481503e14a88f783e87f3791aa8cef99 refs/heads/branch-1
60+
bb282e9cdc1b972fffd08fd21eead43bc0c83cb8 refs/heads/master
61+
5762
Checks the following:
5863

5964
1) Two different formats for separating origin ref in the remote URL
@@ -130,7 +135,6 @@ Check (2) and (3) but with a branch ref
130135
| | `-- upstream
131136
| | `-- real_repo.git
132137
| | |-- HEAD
133-
| | |-- bb282e9cdc1b972fffd08fd21eead43bc0c83cb8
134138
| | `-- refs
135139
| | `-- heads
136140
| | |-- branch-1
@@ -150,5 +154,5 @@ Check (2) and (3) but with a branch ref
150154
|-- namespaces
151155
`-- tags
152156

153-
35 directories, 23 files
157+
35 directories, 22 files
154158

0 commit comments

Comments
 (0)