forge
Explore
Log in

Don't you dare go Hollow

A clone URL opened in a browser (/owner/repo.git, as cargo prints it) redirects to the repo page instead of a 404, keeping the rest of the path and the query

Browse files at this commit

6934e8dcc70d58b42a8b7eed4fd5d94ff7932525Ahmet Kaan GümüşParent: fe7f9a0
Some checks failed
Show checks
  • fix
    • a clone URL opened in a browser (/owner/repo.git, as cargo prints it) redirects to the repo page instead of a 404, keeping the rest of the path and the query
    • an old name with .git follows its rename too
Show full message
🐛 fix: a clone URL opened in a browser (/owner/repo.git, as cargo prints it) redirects to the repo page instead of a 404, keeping the rest of the path and the query; an old name with .git follows its rename too
crates/forge-e2e/tests/e2e/repo_rename_e2e.rsmodified+11 -0
@@ -263,6 +263,17 @@ async fn repo_rename_end_to_end() {
263263 old_query.header(LOCATION).as_deref(),
264264 Some("/bob/newpub?tab=x")
265265 );
266+ let clone_url = http.get("/bob/newpub.git?rev=1", None).await;
267+ assert_eq!(clone_url.status, 307, "clone URL in a browser");
268+ assert_eq!(
269+ clone_url.header(LOCATION).as_deref(),
270+ Some("/bob/newpub?rev=1")
271+ );
272+ let old_clone_url = http.get("/bob/pub.git", None).await;
273+ assert_eq!(
274+ old_clone_url.header(LOCATION).as_deref(),
275+ Some("/bob/newpub")
276+ );
266277
267278 // The old clone URL still fetches and pushes over HTTPS.
268279 ok(
crates/forge-web/src/pages/repo_ctx.rsmodified+15 -2
@@ -379,8 +379,21 @@ async fn moved_location(
379379 owner: &str,
380380 name: &str,
381381 ) -> Result<Option<String>> {
382- let Some(target) = state.store.repo_by_redirect(owner, name).await? else {
383- return Ok(None);
382+ let base = name.strip_suffix(".git");
383+ let direct = match base {
384+ Some(base) => state.store.repo_by_owner_and_name(owner, base).await?,
385+ None => None,
386+ };
387+ let target = match direct {
388+ Some(repo) => repo,
389+ None => match state
390+ .store
391+ .repo_by_redirect(owner, base.unwrap_or(name))
392+ .await?
393+ {
394+ Some(repo) => repo,
395+ None => return Ok(None),
396+ },
384397 };
385398 let (role, org_role) = match viewer {
386399 Some((user, _)) => (