From a8d5b46e8f06bf97bb217a461ec2ce6edc31be08 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 21 Sep 2018 11:41:30 -0400 Subject: [PATCH] Handle empty repositories --- gitsrht/blueprints/repo.py | 18 ++++++++++-------- gitsrht/templates/empty-repo.html | 21 +++++++++++++++++++++ 2 files changed, 31 insertions(+), 8 deletions(-) create mode 100644 gitsrht/templates/empty-repo.html diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py index a015fa9..8ee193e 100644 --- a/gitsrht/blueprints/repo.py +++ b/gitsrht/blueprints/repo.py @@ -35,11 +35,20 @@ def summary(owner, repo): if not has_access(repo, UserAccess.read): abort(401) git_repo = CachedRepository(repo.path) + base = (cfg("git.sr.ht", "origin") + .replace("http://", "") + .replace("https://", "")) + clone_urls = [ + url.format(base, owner.canonical_name, repo.name) + for url in ["https://{}/{}/{}", "git@{}:{}/{}"] + ] + if git_repo.is_empty: + return render_template("empty-repo.html", owner=owner, repo=repo, + clone_urls=clone_urls) master = git_repo.branches.get("master") if not master: master = list(git_repo.branches.local)[0] master = git_repo.branches.get(master) - # TODO: Test on empty repos tip = git_repo.get(master.target) commits = list() for commit in git_repo.walk(tip.id, pygit2.GIT_SORT_TIME): @@ -47,13 +56,6 @@ def summary(owner, repo): if len(commits) >= 3: break readme = get_readme(git_repo, tip) - base = (cfg("git.sr.ht", "origin") - .replace("http://", "") - .replace("https://", "")) - clone_urls = [ - url.format(base, owner.canonical_name, repo.name) - for url in ["https://{}/{}/{}", "git@{}:{}/{}"] - ] tags = [(ref, git_repo.get(git_repo.references[ref].target)) for ref in git_repo.listall_references() if ref.startswith("refs/tags/")] diff --git a/gitsrht/templates/empty-repo.html b/gitsrht/templates/empty-repo.html new file mode 100644 index 0000000..330b99c --- /dev/null +++ b/gitsrht/templates/empty-repo.html @@ -0,0 +1,21 @@ +{% extends "repo.html" %} +{% block content %} +
+
+
+

clone

+
+
read-only
+
{{clone_urls[0]}}
+
read/write
+
{{clone_urls[1]}}
+
+
+
+

+ Nothing here yet! +

+
+
+
+{% endblock %} -- 2.38.4