summaryrefslogtreecommitdiffstats
path: root/gitsrht/blueprints/repo.py
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-10-01 20:52:59 -0400
committerDrew DeVault <sir@cmpwn.com>2018-10-01 20:52:59 -0400
commit52ed520bb716d7150e46b1a0f8b18d2ee770c4e5 (patch)
treea919dd4ebaa0ce8a000e6a43103da8ed312ef0dc /gitsrht/blueprints/repo.py
parentf83ec15d3d5c3c4bd904aa39d1d8601ff0163743 (diff)
Prevent 500 on missing refs
Diffstat (limited to 'gitsrht/blueprints/repo.py')
-rw-r--r--gitsrht/blueprints/repo.py35
1 files changed, 28 insertions, 7 deletions
diff --git a/gitsrht/blueprints/repo.py b/gitsrht/blueprints/repo.py
index 31507f8..cc700b1 100644
--- a/gitsrht/blueprints/repo.py
+++ b/gitsrht/blueprints/repo.py
@@ -101,7 +101,10 @@ def tree(owner, repo, ref, path):
abort(401)
git_repo = CachedRepository(repo.path)
ref = ref or git_repo.default_branch().name[len("refs/heads/"):]
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
commit = git_repo.get(commit.target)
@@ -147,7 +150,10 @@ def raw_blob(owner, repo, ref, path):
abort(401)
git_repo = CachedRepository(repo.path)
ref = ref or git_repo.default_branch().name[len("refs/heads/"):]
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
commit = git_repo.get(commit.target)
@@ -183,7 +189,10 @@ def archive(owner, repo, ref):
abort(401)
git_repo = CachedRepository(repo.path)
ref = ref or git_repo.default_branch().name[len("refs/heads/"):]
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
commit = git_repo.get(commit.target)
@@ -262,7 +271,10 @@ def log(owner, repo, ref, path):
abort(401)
git_repo = CachedRepository(repo.path)
ref = ref or git_repo.default_branch().name[len("refs/heads/"):]
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
commit = git_repo.get(commit.target)
refs = collect_refs(git_repo)
@@ -290,7 +302,10 @@ def commit(owner, repo, ref):
if not has_access(repo, UserAccess.read):
abort(401)
git_repo = CachedRepository(repo.path)
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
ref = git_repo.get(commit.target)
try:
@@ -313,7 +328,10 @@ def patch(owner, repo, ref):
if not has_access(repo, UserAccess.read):
abort(401)
git_repo = CachedRepository(repo.path)
- commit = git_repo.revparse_single(ref)
+ try:
+ commit = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if isinstance(commit, pygit2.Tag):
ref = git_repo.get(commit.target)
subp = subprocess.run([
@@ -381,7 +399,10 @@ def ref(owner, repo, ref):
if not has_access(repo, UserAccess.read):
abort(401)
git_repo = CachedRepository(repo.path)
- tag = git_repo.revparse_single(ref)
+ try:
+ tag = git_repo.revparse_single(ref)
+ except KeyError:
+ abort(404)
if not isinstance(tag, pygit2.Tag):
abort(404)
return render_template("ref.html", view="refs",