diff --git a/app.py b/app.py
index e7438a4..9e2696a 100644
--- a/app.py
+++ b/app.py
# for base.html
app.jinja_env.globals['request'] = request
+@app.context_processor
+def inject_current_ref():
+ return {'current_ref': request.args.get('ref', 'HEAD')}
+
repo_path = os.getenv('GIT_REPO_PATH')
def datetime_filter(value, format='%Y-%m-%d %H:%M:%S'):
@app.route("/<repo_name>")
def repo_detail(repo_name):
- return render_template("repo.html", repo_name=repo_name)
+ refs = get_refs(f"{repo_path}/{repo_name}")
+ return render_template("repo.html", repo_name=repo_name, refs=refs)
@app.route("/<repo_name>/commits")
def repo_commits(repo_name):
ref = request.args.get('ref', 'HEAD')
+ refs = get_refs(f"{repo_path}/{repo_name}")
page = int(request.args.get('page', 0))
# maybe pages are not the wisest way to do this?
per_page = 50
commits = get_commits(f"{repo_path}/{repo_name}", ref=ref, max_count=per_page, skip=skip)
has_next = len(commits) == per_page
has_prev = page > 0
- return render_template("commits.html", repo_name=repo_name, commits=commits, page=page, has_next=has_next, has_prev=has_prev, ref=ref)
+ return render_template("commits.html", repo_name=repo_name, commits=commits, page=page, has_next=has_next, has_prev=has_prev, ref=ref, refs=refs)
@app.route("/<repo_name>/commits/<commit_id>")
def commit_detail(repo_name, commit_id):
@app.route("/<repo_name>/tree/<path:path>")
def repo_tree_path(repo_name, path):
ref = request.args.get('ref', 'HEAD')
+ refs = get_refs(f"{repo_path}/{repo_name}")
tree_items = get_tree_items(f"{repo_path}/{repo_name}", ref, path)
- return render_template("tree.html", repo_name=repo_name, ref=ref, path=path, tree_items=tree_items)
+ return render_template("tree.html", repo_name=repo_name, ref=ref, path=path, tree_items=tree_items, refs=refs)
@app.route("/<repo_name>/blob/<path:path>")
def repo_blob_path(repo_name, path):
ref = request.args.get('ref', 'HEAD')
+ refs = get_refs(f"{repo_path}/{repo_name}")
blob = get_blob(f"{repo_path}/{repo_name}", ref, path)
- return render_template("blob.html", repo_name=repo_name, ref=ref, path=path, blob=blob)
+ return render_template("blob.html", repo_name=repo_name, ref=ref, path=path, blob=blob, refs=refs)
@app.route("/<repo_name>/blame/<path:path>")
def repo_blame_path(repo_name, path):
ref = request.args.get('ref', 'HEAD')
+ refs = get_refs(f"{repo_path}/{repo_name}")
blame = get_blame(f"{repo_path}/{repo_name}", ref, path)
- return render_template("blame.html", repo_name=repo_name, ref=ref, path=path, blame=blame)
+ return render_template("blame.html", repo_name=repo_name, ref=ref, path=path, blame=blame, refs=refs)
@app.route("/<repo_name>/diff")
def repo_diff(repo_name):
+ refs = get_refs(f"{repo_path}/{repo_name}")
id1 = request.args.get('id1')
id2 = request.args.get('id2')
diff = get_diff(f"{repo_path}/{repo_name}", id1=id1, id2=id2)
- return render_template("diff.html", diff=diff)
+ return render_template("diff.html", diff=diff, refs=refs)
if __name__ == "__main__":
app.run(debug=True)
\ No newline at end of file
diff --git a/static/styles.css b/static/styles.css
index 349a245..e484fc1 100644
--- a/static/styles.css
+++ b/static/styles.css
table {
border-collapse: collapse;
width: 100%;
+}
+
+.base-nav {
+ display:flex;
+ align-items:center;
+ gap: 1em;
+ margin-bottom:1em;
}
\ No newline at end of file
diff --git a/templates/base.html b/templates/base.html
index f9a642d..7f0e21c 100644
--- a/templates/base.html
+++ b/templates/base.html
<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}">
</head>
<body>
- <nav>
+ <nav class="base-nav">
<a href="/">Home</a>
{% set repo_name = request.view_args.get('repo_name') %}
{% if repo_name %}
- <a href="{{ url_for('repo_commits', repo_name=repo_name) }}">Commits</a>
+ <a href="{{ url_for('repo_commits', repo_name=repo_name) }}?ref={{ current_ref }}">Commits</a>
<a href="{{ url_for('repo_refs', repo_name=repo_name) }}">Refs</a>
- <a href="{{ url_for('repo_tree_path', repo_name=repo_name) }}">Tree</a>
- <a href="{{ url_for('repo_diff', repo_name=repo_name) }}">Diff</a>
+ <a href="{{ url_for('repo_tree_path', repo_name=repo_name) }}?ref={{ current_ref }}">Tree</a>
+ <a href="{{ url_for('repo_diff', repo_name=repo_name) }}?ref={{ current_ref }}">Diff</a>
+ {% endif %}
+ {% if refs %}
+ <select onchange="changeRef(this.value)" style="margin-left:auto">
+ {% for ref in refs %}
+ <option value="{{ ref.shorthand }}" {% if ref.shorthand == current_ref %}selected{% endif %}>{{ ref.name }}</option>
+ {% endfor %}
+ </select>
{% endif %}
</nav>
+ <script>
+ function changeRef(newRef) {
+ const url = new URL(window.location);
+ url.searchParams.set('ref', newRef);
+ window.location = url;
+ }
+ </script>
{% block content %}{% endblock %}
</body>
</html>
\ No newline at end of file