diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 2b5af31..0b25230 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -310,6 +310,11 @@ def view_commits(repo, branchname=None, username=None, namespace=None): except (ValueError, TypeError): pass + if 'refs/tags/%s' % branchname in list(repo_obj.references): + ref = repo_obj.lookup_reference( + 'refs/tags/%s' % branchname) + commit = ref.get_object() + # If we're arriving here from the release page, we may have a Tag # where we expected a commit, in this case, get the actual commit if isinstance(commit, pygit2.Tag): diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 1b345ab..2cb20a1 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2013,6 +2013,34 @@ class PagureFlaskRepotests(tests.Modeltests): 'test project #3 ', output_text) self.assertIn('Forked from', output_text) + def test_view_commits_from_tag(self): + """ Test the view_commits endpoint given a tag. """ + + tests.create_projects(self.session) + tests.create_projects_git(os.path.join(self.path, 'repos'), bare=True) + + # Add a README to the git repo - First commit + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + first_commit = repo.revparse_single('HEAD') + tagger = pygit2.Signature('Alice Doe', 'adoe@example.com', 12347, 0) + repo.create_tag( + "0.0.1", first_commit.oid.hex, pygit2.GIT_OBJ_COMMIT, tagger, + "Release 0.0.1") + + tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) + repo = pygit2.Repository(os.path.join(self.path, 'repos', 'test.git')) + latest_commit = repo.revparse_single('HEAD') + + output = self.app.get('/test/commits/0.0.1') + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn(first_commit.oid.hex, output_text) + self.assertNotIn(latest_commit.oid.hex, output_text) + self.assertIn('