From b2f59c803b442670142a599cc7cffaa23f668f9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 19 Aug 2020 15:21:34 +0200 Subject: [PATCH] Return an error when trying to clone a project -- >8 -- nabijaczleweli@tarta:~/uwu/git$ strace -f -o ss git clone http://127.0.0.1:5014/~nabijaczleweli/projeq Cloning into 'projeq'... fatal: remote error: This is a sourcehat project, which amalgamates multiple source repositories, issue trackers, and mailing lists. You can visit http://127.0.0.1:5014/~nabijaczleweli/projeq/sources to pick a specific source. nabijaczleweli@tarta:~/uwu/git$ -- >8 -- Returning a non-ERR here and going down to a pack is possible (confer https://twitter.com/nabijaczleweli/status/1296062752516079617) but errors later down the line are either more verbose and hint at implementation errors, or leave repositories in a sticky state. Ref: ~sircmpwn/hub.sr.ht#49 --- hubsrht/blueprints/projects.py | 35 ++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/hubsrht/blueprints/projects.py b/hubsrht/blueprints/projects.py index 12e6005..08ad877 100644 --- a/hubsrht/blueprints/projects.py +++ b/hubsrht/blueprints/projects.py @@ -1,6 +1,6 @@ import re from sqlalchemy import or_ -from flask import Blueprint, render_template, request, redirect, url_for +from flask import Blueprint, Response, render_template, request, redirect, url_for, abort from flask import session from hubsrht.decorators import adminrequired from hubsrht.projects import ProjectAccess, get_project @@ -8,13 +8,31 @@ from hubsrht.services import git, hg from hubsrht.types import Feature, Event, EventType from hubsrht.types import Project, RepoType, Visibility from hubsrht.types import SourceRepo, MailingList, Tracker +from srht.config import cfg, get_origin from srht.database import db -from srht.flask import paginate_query +from srht.flask import csrf_bypass, paginate_query from srht.oauth import current_user, loginrequired from srht.validation import Validation, valid_url 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""" + +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. + +You can visit the following URL: + + {ext_origin}{url_for("sources.sources_GET", + owner=owner.canonical_name, project_name=project.name)} + +To the browse source repositories for this project. + +""" + @projects.route("///") def summary_GET(owner, project_name): owner, project = get_project(owner, project_name, ProjectAccess.read) @@ -52,6 +70,19 @@ def summary_GET(owner, project_name): summary=summary, summary_error=summary_error, events=events, EventType=EventType) +@projects.route("///info/refs") +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) + + return Response(f"""001e# service=git-upload-pack +000000400000000000000000000000000000000000000000 HEAD\0agent=hubsrht +{'{:04x}'.format(4 + 3 + 1 + len(msg))}ERR {msg}0000""", + mimetype="application/x-git-upload-pack-advertisement") + else: + abort(404) + @projects.route("///feed") def feed_GET(owner, project_name): owner, project = get_project(owner, project_name, ProjectAccess.read)