#4584 Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
Merged 4 years ago by pingou. Opened 4 years ago by jlanda.
jlanda/pagure fix-blame-view  into  master

file modified
+26 -9
@@ -737,19 +737,36 @@ 

      repo = flask.g.repo

      repo_obj = flask.g.repo_obj

  

-     branchname = flask.request.args.get("identifier", "master")

+     branchname = flask.request.args.get("identifier")

  

-     if repo_obj.is_empty or repo_obj.head_is_unborn:

+     if repo_obj.is_empty:

          flask.abort(404, description="Empty repo cannot have a file")

  

-     if branchname in repo_obj.listall_branches():

-         branch = repo_obj.lookup_branch(branchname)

-         commit = branch.peel(pygit2.Commit)

+     if branchname is None:

+         if repo_obj.head_is_unborn:

+             flask.abort(

+                 404, description="Identifier is mandatory on unborn HEAD repos"

+             )

+ 

+         branchname = repo_obj.head.shorthand

+         commit = repo_obj[repo_obj.head.target]

+ 

      else:

-         try:

-             commit = repo_obj[branchname]

-         except ValueError:

-             commit = repo_obj[repo_obj.head.target]

+         if branchname in repo_obj.listall_branches():

+             branch = repo_obj.lookup_branch(branchname)

+             commit = branch.peel(pygit2.Commit)

+         elif branchname in pagure.lib.git.get_git_tags(repo):

+             branch = repo_obj.lookup_reference(

+                 "refs/tags/{}".format(branchname)

+             )

+             commit = branch.peel(pygit2.Commit)

+         else:

+             try:

+                 commit = repo_obj[branchname]

+             except ValueError:

+                 flask.abort(

+                     404, description="Cannot find specified identifier"

+                 )

  

      if isinstance(commit, pygit2.Tag):

          commit = commit.peel(pygit2.Commit)

file modified
+9 -3
@@ -977,7 +977,13 @@ 

  

  

  def add_content_to_git(

-     folder, branch="master", filename="sources", content="foo", message=None

+     folder,

+     branch="master",

+     filename="sources",

+     content="foo",

+     message=None,

+     author=("Alice Author", "alice@authors.tld"),

+     commiter=("Cecil Committer", "cecil@committers.tld"),

  ):

      """ Create some more commits for the specified git repo. """

      repo, newfolder, branch_ref_obj = _clone_and_top_commits(
@@ -1006,8 +1012,8 @@ 

  

      # Commits the files added

      tree = repo.index.write_tree()

-     author = pygit2.Signature("Alice Author", "alice@authors.tld")

-     committer = pygit2.Signature("Cecil Committer", "cecil@committers.tld")

+     author = pygit2.Signature(*author)

+     committer = pygit2.Signature(*commiter)

      branch_ref = "refs/heads/%s" % branch

      message = message or "Add content to file %s" % (filename)

      repo.create_commit(

@@ -2832,232 +2832,6 @@ 

          )

          self.assertIn("foo\n bar", output_text)

  

-     def test_view_blame_file(self):

-         """ Test the view_blame_file endpoint. """

-         output = self.app.get("/foo/blame/sources")

-         # No project registered in the DB

-         self.assertEqual(output.status_code, 404)

- 

-         tests.create_projects(self.session)

- 

-         output = self.app.get("/test/blame/sources")

-         # No git repo associated

-         self.assertEqual(output.status_code, 404)

- 

-         tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

- 

-         output = self.app.get("/test/blame/sources")

-         self.assertEqual(output.status_code, 404)

- 

-         # Add some content to the git repo

-         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"), branch="feature"

-         )

-         tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))

-         tests.add_binary_git_repo(

-             os.path.join(self.path, "repos", "test.git"), "test.jpg"

-         )

-         tests.add_binary_git_repo(

-             os.path.join(self.path, "repos", "test.git"), "test_binary"

-         )

- 

-         output = self.app.get("/test/blame/foofile")

-         self.assertEqual(output.status_code, 404)

-         regex = re.compile(r'>(\w+)</a></td>\n<td class="cell2">')

- 

-         # View in master branch

-         output = self.app.get("/test/blame/sources")

-         self.assertEqual(output.status_code, 200)

-         output_text = output.get_data(as_text=True)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code> bar</code></pre></td>', output_text

-         )

-         data = regex.findall(output_text)

-         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)

-         output_text = output.get_data(as_text=True)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code> bar</code></pre></td>', output_text

-         )

-         data1 = regex.findall(output_text)

-         self.assertEqual(len(data1), 2)

-         self.assertEqual(data, data1)

- 

-         # View in feature branch

-         output = self.app.get("/test/blame/sources?identifier=feature")

-         self.assertEqual(output.status_code, 200)

-         output_text = output.get_data(as_text=True)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code> bar</code></pre></td>', output_text

-         )

-         data2 = regex.findall(output_text)

-         self.assertEqual(len(data2), 3)

-         self.assertEqual(data[0], data2[0])

-         self.assertNotEqual(data2[0], data2[1])

-         self.assertEqual(data2[1], data2[2])

- 

-         # View what's supposed to be an image

-         output = self.app.get("/test/blame/test.jpg")

-         self.assertEqual(output.status_code, 400)

-         output_text = output.get_data(as_text=True)

-         self.assertIn("<title>400 Bad Request</title>", output_text)

-         self.assertIn("<p>Binary files cannot be blamed</p>", output_text)

- 

-         # View folder

-         output = self.app.get("/test/blame/folder1")

-         self.assertEqual(output.status_code, 404)

-         output_text = output.get_data(as_text=True)

-         self.assertIn(

-             "<title>Page not found :'( - Pagure</title>", output_text

-         )

-         self.assertIn("<h2>Page not found (404)</h2>", output_text)

- 

-         # View by image name -- with a non-existant file

-         output = self.app.get("/test/blame/testfoo.jpg")

-         self.assertEqual(output.status_code, 404)

-         output = self.app.get("/test/blame/folder1/testfoo.jpg")

-         self.assertEqual(output.status_code, 404)

- 

-         # View file with a non-ascii name

-         tests.add_commit_git_repo(

-             os.path.join(self.path, "repos", "test.git"),

-             ncommits=1,

-             filename="Šource",

-         )

-         output = self.app.get("/test/blame/Šource")

-         self.assertEqual(output.status_code, 200)

-         output_text = output.get_data(as_text=True)

-         self.assertEqual(

-             output.headers["Content-Type"].lower(), "text/html; charset=utf-8"

-         )

-         self.assertIn("</span>&nbsp; Šource", output_text)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code>Row 0</code></pre></td>', output_text

-         )

- 

-         # Add a fork of a fork

-         item = pagure.lib.model.Project(

-             user_id=1,  # pingou

-             name="test3",

-             description="test project #3",

-             is_fork=True,

-             parent_id=1,

-             hook_token="aaabbbppp",

-         )

-         self.session.add(item)

-         self.session.commit()

- 

-         tests.add_content_git_repo(

-             os.path.join(self.path, "repos", "forks", "pingou", "test3.git")

-         )

-         tests.add_readme_git_repo(

-             os.path.join(self.path, "repos", "forks", "pingou", "test3.git")

-         )

-         tests.add_commit_git_repo(

-             os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),

-             ncommits=10,

-         )

-         tests.add_content_to_git(

-             os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),

-             content="✨☃🍰☃✨",

-         )

- 

-         output = self.app.get("/fork/pingou/test3/blame/sources")

-         self.assertEqual(output.status_code, 200)

-         output_text = output.get_data(as_text=True)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code> barRow 0</code></pre></td>',

-             output_text,

-         )

- 

-     def test_view_blame_file_on_tag(self):

-         """ Test the view_blame_file endpoint. """

- 

-         regex = re.compile(r'>(\w+)</a></td>\n<td class="cell2">')

-         tests.create_projects(self.session)

-         tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

-         # Add some content to the git repo

-         tests.add_content_git_repo(

-             os.path.join(self.path, "repos", "test.git")

-         )

-         tests.add_readme_git_repo(os.path.join(self.path, "repos", "test.git"))

- 

-         # add a tag to the git repo

-         repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))

-         commit = repo[repo.head.target]

-         tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)

-         repo.create_tag(

-             "v1.0",

-             commit.oid.hex,

-             pygit2.GIT_OBJ_COMMIT,

-             tagger,

-             "Release v1.0",

-         )

- 

-         # View for tag v1.0

-         output = self.app.get("/test/blame/sources?identifier=v1.0")

-         self.assertEqual(output.status_code, 200)

-         output_text = output.get_data(as_text=True)

-         self.assertIn('<table class="code_table">', output_text)

-         self.assertTrue(

-             '<tr><td class="cell1"><a id="1" href="#1" '

-             'data-line-number="1"></a></td>' in output_text

-             or '<tr><td class="cell1"><a data-line-number="1" '

-             'href="#1" id="1"></a></td>' in output_text

-         )

-         self.assertIn(

-             '<td class="cell2"><pre><code> bar</code></pre></td>', output_text

-         )

-         data = regex.findall(output_text)

-         self.assertEqual(len(data), 2)

- 

      def test_view_commit(self):

          """ Test the view_commit endpoint. """

          output = self.app.get("/foo/c/bar")

@@ -0,0 +1,329 @@ 

+ # -*- coding: utf-8 -*-

+ 

+ """

+ Authors:

+   Julen Landa Alustiza <julen@landa.eus>

+   Pierre-Yves Chibon <pingou@pingoured.fr>

+ 

+ """

+ 

+ from __future__ import unicode_literals, absolute_import

+ 

+ import re

+ import sys

+ import os

+ import pygit2

+ 

+ sys.path.insert(

+     0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")

+ )

+ 

+ import tests

+ import pagure.lib.model

+ 

+ 

+ class PagureFlaskRepoViewBlameFileSimpletests(tests.Modeltests):

+     """ Tests for view_blame_file endpoint of the flask pagure app """

+ 

+     def test_view_blame_file_no_project(self):

+         """ Test the view_blame_file endpoint """

+         output = self.app.get("/foo/blame/sources")

+         # No project registered in the DB

+         self.assertEqual(output.status_code, 404)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             "<title>Page not found :'( - Pagure</title>", output_text

+         )

+         self.assertIn("<h2>Page not found (404)</h2>", output_text)

+         self.assertIn("<p>Project not found</p>", output_text)

+ 

+     def test_view_blame_file_no_git_repo(self):

+         """ Test the view_blame_file endpoint """

+         tests.create_projects(self.session)

+ 

+         output = self.app.get("/test/blame/sources")

+         # No git repo associated

+         self.assertEqual(output.status_code, 404)

+ 

+     def test_view_blame_file_no_git_content(self):

+         """ Test the view_blame_file endpoint """

+         tests.create_projects(self.session)

+         tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

+ 

+         output = self.app.get("/test/blame/sources")

+         # project and associated repo, but no file

+         self.assertEqual(output.status_code, 404)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             "<title>Page not found :'( - Pagure</title>", output_text

+         )

+         self.assertIn("<h2>Page not found (404)</h2>", output_text)

+         self.assertIn("<p>Empty repo cannot have a file</p>", output_text)

+ 

+ 

+ class PagureFlaskRepoViewBlameFiletests(tests.Modeltests):

+     """ Tests for view_blame_file endpoint of the flask pagure app """

+ 

+     def setUp(self):

+         """ Set up the environment, ran before every tests. """

+         super(PagureFlaskRepoViewBlameFiletests, self).setUp()

+         self.regex = re.compile(r'>(\w+)</a></td>\n<td class="cell2">')

+         tests.create_projects(self.session)

+         tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)

+ 

+         # Add some content to the git repo

+         tests.add_content_to_git(

+             os.path.join(self.path, "repos", "test.git"),

+             message="initial commit",

+         )

+         tests.add_content_to_git(

+             os.path.join(self.path, "repos", "test.git"), message="foo"

+         )

+         tests.add_content_to_git(

+             os.path.join(self.path, "repos", "test.git"),

+             branch="feature",

+             content="bar",

+             message="bar",

+             author=("Aritz Author", "aritz@authors.tld"),

+         )

+ 

+     def test_view_blame_file_default_branch_master(self):

+         """ Test the view_blame_file endpoint """

+         output = self.app.get("/test/blame/sources")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>foo</code></pre></td>', output_text

+         )

+         self.assertIn('<td class="cell_user">Alice Author</td>', output_text)

+         data = self.regex.findall(output_text)

+         self.assertEqual(len(data), 2)

+ 

+     def test_view_blame_file_default_branch_non_master(self):

+         """ Test the view_blame_file endpoint """

+         repo = pygit2.Repository(os.path.join(self.path, "repos", "test.git"))

+         reference = repo.lookup_reference("refs/heads/feature").resolve()

+         repo.set_head(reference.name)

+         output = self.app.get("/test/blame/sources")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>bar</code></pre></td>', output_text

+         )

+         self.assertIn('<td class="cell_user">Aritz Author</td>', output_text)

+         data = self.regex.findall(output_text)

+         self.assertEqual(len(data), 3)

+ 

+     def test_view_blame_file_on_commit(self):

+         """ Test the view_blame_file endpoint """

+         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={}".format(parent)

+         )

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>foo</code></pre></td>', output_text

+         )

+         self.assertIn('<td class="cell_user">Alice Author</td>', output_text)

+         data = self.regex.findall(output_text)

+         self.assertEqual(len(data), 1)

+ 

+     def test_view_blame_file_on_branch(self):

+         """ Test the view_blame_file endpoint """

+         output = self.app.get("/test/blame/sources?identifier=feature")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>bar</code></pre></td>', output_text

+         )

+         self.assertIn('<td class="cell_user">Aritz Author</td>', output_text)

+         data = self.regex.findall(output_text)

+         self.assertEqual(len(data), 3)

+ 

+     def test_view_blame_file_on_tag(self):

+         """ Test the view_blame_file endpoint """

+         # set a tag on the head's parent 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

+         tagger = pygit2.Signature("Alice Doe", "adoe@example.com", 12347, 0)

+         repo_obj.create_tag(

+             "v1.0", parent, pygit2.GIT_OBJ_COMMIT, tagger, "Release v1.0"

+         )

+ 

+         output = self.app.get("/test/blame/sources?identifier=v1.0")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>foo</code></pre></td>', output_text

+         )

+         self.assertIn('<td class="cell_user">Alice Author</td>', output_text)

+         data = self.regex.findall(output_text)

+         self.assertEqual(len(data), 1)

+ 

+     def test_view_blame_file_binary(self):

+         """ Test the view_blame_file endpoint """

+         # Add binary content

+         tests.add_binary_git_repo(

+             os.path.join(self.path, "repos", "test.git"), "test.jpg"

+         )

+         output = self.app.get("/test/blame/test.jpg")

+         self.assertEqual(output.status_code, 400)

+         output_text = output.get_data(as_text=True)

+         self.assertIn("<title>400 Bad Request</title>", output_text)

+         self.assertIn("<p>Binary files cannot be blamed</p>", output_text)

+ 

+     def test_view_blame_file_non_ascii_name(self):

+         """ Test the view_blame_file endpoint """

+         tests.add_commit_git_repo(

+             os.path.join(self.path, "repos", "test.git"),

+             ncommits=1,

+             filename="Šource",

+         )

+         output = self.app.get("/test/blame/Šource")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertEqual(

+             output.headers["Content-Type"].lower(), "text/html; charset=utf-8"

+         )

+         self.assertIn("</span>&nbsp; Šource", output_text)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code>Row 0</code></pre></td>', output_text

+         )

+ 

+     def test_view_blame_file_fork_of_a_fork(self):

+         """ Test the view_blame_file endpoint """

+         item = pagure.lib.model.Project(

+             user_id=1,  # pingou

+             name="test3",

+             description="test project #3",

+             is_fork=True,

+             parent_id=1,

+             hook_token="aaabbbppp",

+         )

+         self.session.add(item)

+         self.session.commit()

+ 

+         tests.add_content_git_repo(

+             os.path.join(self.path, "repos", "forks", "pingou", "test3.git")

+         )

+         tests.add_readme_git_repo(

+             os.path.join(self.path, "repos", "forks", "pingou", "test3.git")

+         )

+         tests.add_commit_git_repo(

+             os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),

+             ncommits=10,

+         )

+         tests.add_content_to_git(

+             os.path.join(self.path, "repos", "forks", "pingou", "test3.git"),

+             content="✨☃🍰☃✨",

+         )

+ 

+         output = self.app.get("/fork/pingou/test3/blame/sources")

+         self.assertEqual(output.status_code, 200)

+         output_text = output.get_data(as_text=True)

+         self.assertIn('<table class="code_table">', output_text)

+         self.assertTrue(

+             '<tr><td class="cell1"><a id="1" href="#1" '

+             'data-line-number="1"></a></td>' in output_text

+             or '<tr><td class="cell1"><a data-line-number="1" '

+             'href="#1" id="1"></a></td>' in output_text

+         )

+         self.assertIn(

+             '<td class="cell2"><pre><code> barRow 0</code></pre></td>',

+             output_text,

+         )

+ 

+     def test_view_blame_file_no_file(self):

+         """ Test the view_blame_file endpoint """

+         output = self.app.get("/test/blame/foofile")

+         self.assertEqual(output.status_code, 404)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             "<title>Page not found :'( - Pagure</title>", output_text

+         )

+         self.assertIn("<h2>Page not found (404)</h2>", output_text)

+         self.assertIn("<p>File not found</p>", output_text)

+ 

+     def test_view_blame_file_folder(self):

+         """ Test the view_blame_file endpoint """

+         tests.add_commit_git_repo(

+             os.path.join(self.path, "repos", "test.git/folder1"),

+             ncommits=1,

+             filename="sources",

+         )

+         output = self.app.get("/test/blame/folder1")

+         self.assertEqual(output.status_code, 404)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             "<title>Page not found :'( - Pagure</title>", output_text

+         )

+         self.assertIn("<h2>Page not found (404)</h2>", output_text)

+         self.assertIn("<p>File not found</p>", output_text)

+ 

+     def test_view_blame_file_unborn_head_no_identifier(self):

+         repo_obj = pygit2.Repository(

+             os.path.join(self.path, "repos", "test.git")

+         )

+         repo_obj.set_head("refs/heads/unexistent")

+ 

+         output = self.app.get("/test/blame/sources")

+         self.assertEqual(output.status_code, 404)

+         output_text = output.get_data(as_text=True)

+         self.assertIn(

+             "<title>Page not found :'( - Pagure</title>", output_text

+         )

+         self.assertIn("<h2>Page not found (404)</h2>", output_text)

+         self.assertIn(

+             "<p>Identifier is mandatory on unborn HEAD repos</p>", output_text

+         )

Fixes #4571

This allows using blame with unborn head repositories while an identifier argument is passed and uses the actual default branch when master branch exists but is not the default one.

rebased onto c4937434dd9ea86a5adf2743cc189c80267745b1

4 years ago

rebased onto 07024c4bf551cf3081a53b0351fd25475820be0f

4 years ago

rebased onto 53ff2627c2e7bbd9312357622ceecdeb9318cc83

4 years ago

The tag case is not working, but I found more problems looking on that like being able to ask for unexistent tag blames: https://pagure.io/pagure/blame/pagure/ui/repo.py?identifier=v6.6.6

We should block this too, or at least explicitly say that this is coming from head not from an unexistent tag =)

A little proof on https://stg.pagure.io/blame-test/
Navigating to blame view on branch master works properly, it points to: https://stg.pagure.io/blame-test/blame/file?identifier=master and shows the correct blame version.
Navitaging to blame view on tag v1.0 works properly, it points to https://stg.pagure.io/blame-test/blame/file?identifier=835ccd9cf7de755514b0418c45f98b345204aef2 and shows the correct blame version.

Using tag v1.0 as identifier arg (the failing test) fails: https://stg.pagure.io/blame-test/blame/file?identifier=v1.0 It's showing the blame for repo_obj.head.target, so master, not for v1.0 tag

2 new commits added

  • tests: cover more blame view cases
  • tests: allow easy change of author|committer signature on add_content_to_git()
4 years ago

rebased onto b38ce7cc229353a7df3e4c6623a65c1a32ab6c2e

4 years ago

Fixed the problems when using tags as identifiers

rebased onto 5b7068cdaddd3524d6b6cfe9c58aefa737ecba91

4 years ago

3 new commits added

  • Move to own test file and refactor view_blame_file tests
  • tests: allow easy change of author|committer signature on add_content_to_git()
  • Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
4 years ago

3 new commits added

  • Move to own test file and refactor view_blame_file tests
  • tests: allow easy change of author|committer signature on add_content_to_git()
  • Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
4 years ago

3 new commits added

  • Move to own test file and refactor view_blame_file tests
  • tests: allow easy change of author|committer signature on add_content_to_git()
  • Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
4 years ago

3 new commits added

  • Move to own test file and refactor view_blame_file tests
  • tests: allow easy change of author|committer signature on add_content_to_git()
  • Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
4 years ago

3 new commits added

  • Move to own test file and refactor view_blame_file tests
  • tests: allow easy change of author|committer signature on add_content_to_git()
  • Change default head selection behaviour to allow using blame with unborn HEAD or non master default branch repos
4 years ago

Jenkins will not be happy due to the broken arrow 0.15 thing, but otherwise this is ready to review

rebased onto 7a4125c04b17e864443fc0702d59d830a0f67904

4 years ago

Looks like I can't rebase this one :(

rebased onto c9c8572

4 years ago

Pull-Request has been merged by pingou

4 years ago