Accept clone addresses with or without .git, and fix delete's wording
Browse filesSSH required `owner/name.git` and HTTPS refused it, so `git clone git@host:owner/name` and `git clone https://host/owner/name.git` both failed. Both now take either form. delete said it was permanent, but it moves the repository to the trash. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Author
- Um9i vulgarmessiah@gmail.com
- Date
- 22 Nov 2026, 22:01
- Commit
- c73daf900578
- Parent
- 6e8596b
4 files changed +19−5
| @@ -53,7 +53,9 @@ async fn transfer( | ||
| protocol: Option<String>, | ||
| request: Option<Request>, | ||
| ) -> Response { | ||
| let Some(dir) = repo_dir(&owner, &name).filter(|dir| dir.is_public()) else { | ||
| // `https://host/owner/name.git` works as well as the address the pages show. | ||
| let name = name.strip_suffix(".git").unwrap_or(&name); | ||
| let Some(dir) = repo_dir(&owner, name).filter(|dir| dir.is_public()) else { | ||
| return StatusCode::NOT_FOUND.into_response(); | ||
| }; | ||
| // Taken before the body is read, so memory for bodies stays bounded by the slots; the | ||
| @@ -877,6 +877,9 @@ fn public_web_clone_and_visibility_changes() { | ||
| let copy = work.join(format!("copy-v{version}")); | ||
| assert_eq!(git(©, &["rev-parse", "HEAD"]), git(&work, &["rev-parse", "HEAD"])); | ||
| } | ||
| // The address with `.git`, as people often type it, clones too. | ||
| let out = common::git_cmd(&work).args(["clone", "-q", &format!("{url}.git"), "copy-dotgit"]).output().unwrap(); | ||
| assert!(out.status.success(), "{}", String::from_utf8_lossy(&out.stderr)); | ||
| let copy = work.join("copy-v2"); | ||
| assert!(!host.git(©, &["push", "origin", "HEAD:forbidden"]).status.success()); | ||
| assert!(host.admin(&["visibility", "ada", "sharing", "private"]).status.success()); | ||
| @@ -589,7 +589,9 @@ fn serve(owner: &str, command: &str) -> Result<u8, String> { | ||
| ["delete", name, rest @ ..] => { | ||
| let name = check_name(name)?; | ||
| if rest != ["--yes"] { | ||
| return Err(format!("deleting {owner}/{name}.git is permanent; run: delete {name} --yes")); | ||
| return Err(format!( | ||
| "this moves {owner}/{name}.git to the trash, where only the server's operator can restore it; run: delete {name} --yes" | ||
| )); | ||
| } | ||
| let entry = delete(owner, name)?; | ||
| log_operator(&format!( | ||
| @@ -604,12 +606,13 @@ fn serve(owner: &str, command: &str) -> Result<u8, String> { | ||
| Ok(0) | ||
| } | ||
| /// Parse `owner/name.git` (optionally with leading or trailing slash). | ||
| /// Parse `owner/name.git` or `owner/name` (optionally with leading or trailing slash), as | ||
| /// git clients send either and HTTPS clone addresses carry no `.git`. | ||
| fn parse_request(path: &str) -> Option<(&str, &str)> { | ||
| let path = path.strip_prefix('/').unwrap_or(path); | ||
| let path = path.strip_suffix('/').unwrap_or(path); | ||
| let (owner, rest) = path.split_once('/')?; | ||
| let name = rest.strip_suffix(".git")?; | ||
| let name = rest.strip_suffix(".git").unwrap_or(rest); | ||
| (valid_name(owner) && valid_name(name)).then_some((owner, name)) | ||
| } | ||
| @@ -812,7 +815,9 @@ fn run() -> Result<u8, String> { | ||
| } | ||
| Action::Delete { owner, name, yes } => { | ||
| if !yes { | ||
| return Err(format!("deleting {owner}/{name}.git is permanent; pass --yes to confirm")); | ||
| return Err(format!( | ||
| "this moves {owner}/{name}.git to the trash for {TRASH_DAYS} days; pass --yes to confirm" | ||
| )); | ||
| } | ||
| let entry = delete(&owner, &name)?; | ||
| println!("moved {owner}/{name}.git to {owner}/{TRASH}/{entry}; restore with: gitv restore {owner} {entry}"); | ||
| @@ -100,6 +100,10 @@ fn push_creates_the_repository_and_clone_reads_it() { | ||
| let out = host.git(&clone, &["clone", "-q", "ada@x:ada/project.git", "copy"]); | ||
| assert!(out.status.success(), "{}", stderr(&out)); | ||
| assert_eq!(fs::read_to_string(clone.join("copy/hello.txt")).unwrap(), "hello\n"); | ||
| // The address without `.git` names the same repository. | ||
| let out = host.git(&clone, &["clone", "-q", "ada@x:ada/project", "bare-name"]); | ||
| assert!(out.status.success(), "{}", stderr(&out)); | ||
| assert!(clone.join("bare-name/hello.txt").is_file()); | ||
| // A second push updates the same repository. | ||
| fs::write(dir.join("hello.txt"), "hello again\n").unwrap(); | ||