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 commit6934e8dcc70d58b42a8b7eed4fd5d94ff7932525Parent: fe7f9a0Some checks failed
Show checks
ci/buildFailedDetails
- 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
2 changed files +26 -2
crates/forge-e2e/tests/e2e/repo_rename_e2e.rsmodified+11 -0
| @@ -263,6 +263,17 @@ async fn repo_rename_end_to_end() { | |||
| 263 | old_query.header(LOCATION).as_deref(), | 263 | old_query.header(LOCATION).as_deref(), |
| 264 | Some("/bob/newpub?tab=x") | 264 | Some("/bob/newpub?tab=x") |
| 265 | ); | 265 | ); |
| 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 | + ); | ||
| 266 | 277 | ||
| 267 | // The old clone URL still fetches and pushes over HTTPS. | 278 | // The old clone URL still fetches and pushes over HTTPS. |
| 268 | ok( | 279 | ok( |
crates/forge-web/src/pages/repo_ctx.rsmodified+15 -2
| @@ -379,8 +379,21 @@ async fn moved_location( | |||
| 379 | owner: &str, | 379 | owner: &str, |
| 380 | name: &str, | 380 | name: &str, |
| 381 | ) -> Result<Option<String>> { | 381 | ) -> Result<Option<String>> { |
| 382 | - let Some(target) = state.store.repo_by_redirect(owner, name).await? else { | 382 | + let base = name.strip_suffix(".git"); |
| 383 | - return Ok(None); | 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 | + }, | ||
| 384 | }; | 397 | }; |
| 385 | let (role, org_role) = match viewer { | 398 | let (role, org_role) = match viewer { |
| 386 | Some((user, _)) => ( | 399 | Some((user, _)) => ( |