patx/gitman
tighten readme rendering rules on repo.tpl
Commit 3526dbf · patx · 2026-05-22T13:38:02-04:00
Comments
No comments yet.
Diff
diff --git a/templates/repo.tpl b/templates/repo.tpl
index fb5ff61..9c27056 100644
--- a/templates/repo.tpl
+++ b/templates/repo.tpl
@@ -14,21 +14,26 @@
</div>
</section>
-<section class="panel">
- % if readme_html is not None:
+% if readme_html is not None:
+ <section class="panel">
% if readme_truncated:
<p class="notice">README preview truncated. Use the source or raw view for the full file.</p>
% end
<div class="readme markdown-body">{{!readme_html}}</div>
- % elif readme is not None:
+ </section>
+% elif readme is not None:
+ <section class="panel">
% if readme_truncated:
<p class="notice">README preview truncated. Use the source or raw view for the full file.</p>
% end
<pre class="readme">{{readme}}</pre>
- % else:
+ </section>
+% elif can_maintain or commit_count == 0:
+ <section class="panel">
<div class="empty">
% if commit_count == 0:
<p>This repository is empty.</p>
+ % if can_maintain:
<h3>Start with a fresh checkout</h3>
<pre>git clone {{clone_url}}
cd {{repo["name"]}}
@@ -41,6 +46,7 @@ git push -u origin main</pre>
git remote add origin {{clone_url}}
git push -u origin HEAD:main</pre>
<p class="muted">Push will ask for the repository owner's or a contributor's username and password.</p>
+ % end
% else:
<p>This repository has no README.</p>
<pre>echo "# {{repo["name"]}}" > README.md
@@ -49,5 +55,5 @@ git commit -m "Add README"
git push</pre>
% end
</div>
- % end
-</section>
+ </section>
+% end
diff --git a/tests/test_app.py b/tests/test_app.py
index 3134843..7371c4b 100644
--- a/tests/test_app.py
+++ b/tests/test_app.py
@@ -686,6 +686,46 @@ def test_login_and_git_auth_failures_are_rate_limited(isolated_app, monkeypatch)
assert response.header("Connection") is None
+def test_no_readme_instructions_are_maintainer_only(isolated_app):
+ owner = create_user("alice")
+ create_user("bob")
+ create_user("carol")
+ isolated_app.create_repository(owner, "demo", "")
+
+ anonymous_empty_response = WsgiClient(isolated_app.app).get("/alice/demo")
+ assert anonymous_empty_response.status_code == 200
+ assert "This repository is empty." in anonymous_empty_response.text
+ assert "Start with a fresh checkout" not in anonymous_empty_response.text
+ assert 'git commit -m "Initial commit"' not in anonymous_empty_response.text
+
+ commit_file(isolated_app.repo_path("alice", "demo"), "app.py", "print('demo')\n", message="add app")
+
+ anonymous_response = WsgiClient(isolated_app.app).get("/alice/demo")
+ assert anonymous_response.status_code == 200
+ assert "This repository has no README." not in anonymous_response.text
+ assert "git add README.md" not in anonymous_response.text
+
+ non_maintainer_client = WsgiClient(isolated_app.app)
+ login_client(non_maintainer_client, "carol")
+ non_maintainer_response = non_maintainer_client.get("/alice/demo")
+ assert "This repository has no README." not in non_maintainer_response.text
+ assert "git add README.md" not in non_maintainer_response.text
+
+ owner_client = WsgiClient(isolated_app.app)
+ login_client(owner_client, "alice")
+ owner_response = owner_client.get("/alice/demo")
+ assert "This repository has no README." in owner_response.text
+ assert "git add README.md" in owner_response.text
+
+ repo = isolated_app.get_repo("alice", "demo")
+ isolated_app.add_repo_contributor(repo, owner, "bob")
+ contributor_client = WsgiClient(isolated_app.app)
+ login_client(contributor_client, "bob")
+ contributor_response = contributor_client.get("/alice/demo")
+ assert "This repository has no README." in contributor_response.text
+ assert "git add README.md" in contributor_response.text
+
+
def test_readme_preview_is_truncated_but_source_files_render_fully(isolated_app, monkeypatch):
monkeypatch.setattr(gitman, "MAX_RENDER_BYTES", 32)
owner = create_user("alice")