From 1c5b63e7f8e07cf5c490044477338cef93f40f8e Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jan 09 2018 11:22:29 +0000 Subject: Allow calling git blame on a commit instead of a branch Fixes https://pagure.io/pagure/issue/2894 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 7a9537f..b1af3b6 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -677,7 +677,10 @@ def view_blame_file(repo, filename, username=None, namespace=None): branch = repo_obj.lookup_branch(branchname) commit = branch.get_object() else: - commit = repo_obj[repo_obj.head.target] + try: + commit = repo_obj[branchname] + except ValueError: + commit = repo_obj[repo_obj.head.target] content = __get_file_in_tree( repo_obj, commit.tree, filename.split('/'), bail_on_tree=True) diff --git a/tests/test_pagure_flask_ui_repo.py b/tests/test_pagure_flask_ui_repo.py index 2de46a5..b6961ad 100644 --- a/tests/test_pagure_flask_ui_repo.py +++ b/tests/test_pagure_flask_ui_repo.py @@ -2223,7 +2223,7 @@ class PagureFlaskRepotests(tests.Modeltests): tests.add_content_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_content_git_repo( - os.path.join(self.path, 'repos','test.git'), + os.path.join(self.path, 'repos', 'test.git'), branch='feature') tests.add_readme_git_repo(os.path.join(self.path, 'repos', 'test.git')) tests.add_binary_git_repo( @@ -2247,6 +2247,23 @@ class PagureFlaskRepotests(tests.Modeltests): data = regex.findall(output.data) self.assertEqual(len(data), 2) + # View for a commit + repo_obj = pygit2.Repository( + os.path.join(self.path, 'repos', 'test.git')_) + commit = repo_obj[repo_obj.head.target] + parent = commit.parents[0].oid.hex + + output = self.app.get('/test/blame/sources?identifier=%s' % parent) + self.assertEqual(output.status_code, 200) + self.assertIn(b'', output.data) + self.assertIn( + b'', output.data) + self.assertIn( + b'', output.data) + data = regex.findall(output.data) + self.assertEqual(len(data), 2) + # View in feature branch output = self.app.get('/test/blame/sources?identifier=feature') self.assertEqual(output.status_code, 200)
 bar