~edwargix/git.sr.ht

a8d5b46e8f06bf97bb217a461ec2ce6edc31be08 — Drew DeVault 6 years ago 00c7ddc
Handle empty repositories
2 files changed, 31 insertions(+), 8 deletions(-)

M gitsrht/blueprints/repo.py
A gitsrht/templates/empty-repo.html
M gitsrht/blueprints/repo.py => gitsrht/blueprints/repo.py +10 -8
@@ 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/")]

A gitsrht/templates/empty-repo.html => gitsrht/templates/empty-repo.html +21 -0
@@ 0,0 1,21 @@
{% extends "repo.html" %}
{% block content %}
<div class="container">
  <div class="row" style="margin-bottom: 1rem">
    <div class="col-md-4">
      <h3>clone</h3>
      <dl>
        <dt>read-only</dt>
        <dd><a href="{{clone_urls[0]}}">{{clone_urls[0]}}</a></dd>
        <dt>read/write</dt>
        <dd>{{clone_urls[1]}}</dd>
      </dl>
    </div>
    <div class="col-md-8">
      <p>
        Nothing here yet!
      </p>
    </div>
  </div>
</div>
{% endblock %}