Show helpful error on Mercurial clones as well

Unfortunately "hg clone" seems to have issues with the redirect to the
version with the trailing slash, but it's better than the raw HTML dump
from before

-- >8 --
nabijaczleweli@tarta:~/uwu$ hg clone http://127.0.0.1:5014/~nabijaczleweli/projeq wellb
abort: HTTP Error 308: PERMANENT REDIRECT
nabijaczleweli@tarta:~/uwu$ hg clone http://127.0.0.1:5014/~nabijaczleweli/projeq/ wellb
abort: 'http://127.0.0.1:5014/~nabijaczleweli/projeq/' does not appear to be an hg repository:
---%<--- (text/plain; charset=utf-8)

You have tried to clone a project from sourcehat, but you probably meant to
clone a specific hg repository for this project instead. A single project on
sourcehat often has more than one hg repository.

You can visit the following URL:

  http://127.0.0.1:5014/~nabijaczleweli/projeq/sources

To the browse source repositories for this project.

---%<---
!
nabijaczleweli@tarta:~/uwu$
-- >8 --
This commit is contained in:
наб 2020-08-20 17:18:39 +02:00 committed by Drew DeVault
parent b2f59c803b
commit 39eafa9bbf
1 changed files with 9 additions and 4 deletions

View File

@ -18,11 +18,11 @@ projects = Blueprint("projects", __name__)
site_name = cfg("sr.ht", "site-name")
ext_origin = get_origin("hub.sr.ht", external=True)
clone_message = lambda owner, project: f"""
clone_message = lambda owner, project, scm: f"""
You have tried to clone a project from {site_name}, but you probably meant to
clone a specific git repository for this project instead. A single project on
{site_name} often has more than one git repository.
clone a specific {scm} repository for this project instead. A single project on
{site_name} often has more than one {scm} repository.
You can visit the following URL:
@ -37,6 +37,11 @@ To the browse source repositories for this project.
def summary_GET(owner, project_name):
owner, project = get_project(owner, project_name, ProjectAccess.read)
# Mercurial clone
if request.args.get("cmd") == "capabilities":
return Response(clone_message(owner, project, "hg"),
mimetype="text/plain")
summary = None
summary_error = False
if project.summary_repo_id is not None:
@ -74,7 +79,7 @@ def summary_GET(owner, project_name):
def summary_refs(owner, project_name):
if request.args.get("service") == "git-upload-pack":
owner, project = get_project(owner, project_name, ProjectAccess.read)
msg = clone_message(owner, project)
msg = clone_message(owner, project, "git")
return Response(f"""001e# service=git-upload-pack
000000400000000000000000000000000000000000000000 HEAD\0agent=hubsrht