| |
@@ -322,6 +322,14 @@
|
| |
if isinstance(commit, pygit2.Tag):
|
| |
commit = commit.peel(pygit2.Commit)
|
| |
branchname = commit.oid.hex
|
| |
+ elif isinstance(commit, pygit2.Blob):
|
| |
+ try:
|
| |
+ commit = commit.peel(pygit2.Commit)
|
| |
+ branchname = commit.oid.hex
|
| |
+ except Exception:
|
| |
+ flask.abort(
|
| |
+ 404, description="Invalid branch/identifier provided"
|
| |
+ )
|
| |
elif not repo_obj.is_empty and not repo_obj.head_is_unborn:
|
| |
branch = repo_obj.lookup_branch(repo_obj.head.shorthand)
|
| |
commit = branch.peel(pygit2.Commit)
|
| |
@@ -768,8 +776,13 @@
|
| |
404, description="Cannot find specified identifier"
|
| |
)
|
| |
|
| |
- if isinstance(commit, pygit2.Tag):
|
| |
- commit = commit.peel(pygit2.Commit)
|
| |
+ try:
|
| |
+ if isinstance(commit, pygit2.Tag):
|
| |
+ commit = commit.peel(pygit2.Commit)
|
| |
+ elif isinstance(commit, pygit2.Blob):
|
| |
+ commit = commit.peel(pygit2.Commit)
|
| |
+ except Exception:
|
| |
+ flask.abort(404, description="Invalid identified provided")
|
| |
|
| |
content = __get_file_in_tree(
|
| |
repo_obj, commit.tree, filename.split("/"), bail_on_tree=True
|
| |
@@ -816,10 +829,16 @@
|
| |
repo_obj = flask.g.repo_obj
|
| |
|
| |
branchname = flask.request.args.get("identifier")
|
| |
-
|
| |
if repo_obj.is_empty:
|
| |
flask.abort(404, description="Empty repo cannot have a file")
|
| |
|
| |
+ if not branchname:
|
| |
+ try:
|
| |
+ branch = repo_obj.lookup_branch(repo_obj.head.shorthand)
|
| |
+ branchname = branch.branch_name
|
| |
+ except pygit2.GitError:
|
| |
+ flask.abort(400, description="Invalid repository")
|
| |
+
|
| |
try:
|
| |
log = pagure.lib.repo.PagureRepo.log(
|
| |
flask.g.reponame,
|
| |