From 4d8e52064bcdbfaa87c323741f7ac80b2c08c039 Mon Sep 17 00:00:00 2001 From: Christian Schilling Date: Wed, 13 Apr 2022 20:46:17 +0200 Subject: [PATCH] Handle @sha urls by creating magic ref The @rev url syntax did not work if rev was specified as a sha. This was because there was no ref for the symref HEAD to point to. Now a fake ref is created for that purpose. --- josh-proxy/src/bin/josh-proxy.rs | 24 +++++++++++++++--------- tests/proxy/clone_sha.t | 5 +++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/josh-proxy/src/bin/josh-proxy.rs b/josh-proxy/src/bin/josh-proxy.rs index b3cb59617..d707db0e4 100644 --- a/josh-proxy/src/bin/josh-proxy.rs +++ b/josh-proxy/src/bin/josh-proxy.rs @@ -295,17 +295,23 @@ async fn do_filter( )?; } - from_to.push(( - format!( - "refs/josh/upstream/{}/{}", - &josh::to_ns(&upstream_repo), - headref - ), - temp_ns.reference(&headref), - )); - let mut headref = headref; + if headref.starts_with("refs/") || headref == "HEAD" { + from_to.push(( + format!( + "refs/josh/upstream/{}/{}", + &josh::to_ns(&upstream_repo), + headref + ), + temp_ns.reference(&headref), + )); + } else { + let headsha = headref.clone(); + headref = format!("refs/heads/_{}", &headref); + from_to.push((headsha, temp_ns.reference(&headref))); + } + josh::filter_refs(&transaction, filter, &from_to, josh::filter::empty())?; if headref == "HEAD" { headref = heads_map diff --git a/tests/proxy/clone_sha.t b/tests/proxy/clone_sha.t index ba66b4060..68a3fa891 100644 --- a/tests/proxy/clone_sha.t +++ b/tests/proxy/clone_sha.t @@ -49,6 +49,11 @@ $ cd ${TESTTMP} + $ git ls-remote http://localhost:8002/real_repo.git@bb282e9cdc1b972fffd08fd21eead43bc0c83cb8:/.git + bb282e9cdc1b972fffd08fd21eead43bc0c83cb8\tHEAD (esc) + bb282e9cdc1b972fffd08fd21eead43bc0c83cb8\trefs/heads/_bb282e9cdc1b972fffd08fd21eead43bc0c83cb8 (esc) + bb282e9cdc1b972fffd08fd21eead43bc0c83cb8\trefs/heads/master (esc) + $ git clone -q http://localhost:8002/real_repo.git@bb282e9cdc1b972fffd08fd21eead43bc0c83cb8:/.git full_repo $ cd full_repo