From 0fb8671248abfe9b84901091c3a78180751407c0 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 19 2019 09:19:51 +0000 Subject: Do not notify about invalid identifier if none is specified If no identifier is specified, there is no point saying it was not found in the list of branches or in the git repo. Fixes https://pagure.io/pagure/issue/4203 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index bc95201..3f659dc 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -962,11 +962,12 @@ def view_tree(repo, identifier=None, username=None, namespace=None): if not repo_obj.head_is_unborn: branchname = repo_obj.head.shorthand commit = repo_obj[repo_obj.head.target] - flask.flash( - "'%s' not found in the git repository, going back to: " - "%s" % (identifier, branchname), - "error", - ) + if identifier: + flask.flash( + "'%s' not found in the git repository, going back " + "to: %s" % (identifier, branchname), + "error", + ) # 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 1e89014..ab86f71 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -3175,6 +3175,30 @@ index 0000000..fb7093d self.assertFalse( 'No content found in this repository' in output_text) + # View tree, no identifier: + output = self.app.get('/test/tree/') + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn('Tree - test - Pagure', output_text) + self.assertIn('README.rst', output_text) + self.assertNotIn( + 'No content found in this repository', output_text) + self.assertNotIn( + "'None' not found in the git repository, going back to: " + "master", output_text) + + # View tree, invalid identifier: + output = self.app.get('/test/tree/invalid') + self.assertEqual(output.status_code, 200) + output_text = output.get_data(as_text=True) + self.assertIn('Tree - test - Pagure', output_text) + self.assertIn('README.rst', output_text) + self.assertNotIn( + 'No content found in this repository', output_text) + self.assertIn( + "'invalid' not found in the git repository, going back " + "to: master", output_text) + # View tree by branch output = self.app.get('/test/tree/master') self.assertEqual(output.status_code, 200)