#4595 lib/git: fix .diff generation with empty commits
Merged 4 years ago by pingou. Opened 4 years ago by jlanda.
jlanda/pagure fix-empty-commit-diff  into  master

file modified
+4 -1
@@ -89,6 +89,9 @@ 

              # First commit in the repo

              diff = commit.tree.diff_to_tree(swap=True)

  

+         if diff.patch is None:

+             continue

+ 

          if find_similar and diff:

              diff.find_similar()

  
@@ -138,7 +141,7 @@ 

      if separated:

          return patch

      else:

-         return "".join(patch)

+         return "".join(filter(None, patch))

  

  

  def generate_gitolite_acls(project=None, group=None):

@@ -3277,6 +3277,20 @@ 

  

          self.second_commit = repo.revparse_single("HEAD")

  

+         # Add empty commit

+         repo.create_commit(

+             "refs/heads/master",  # the name of the reference to update

+             author,

+             committer,

+             "Empty commit",

+             # binary string representing the tree object ID

+             tree,

+             # list of binary strings representing parents of the new commit

+             [self.second_commit.oid.hex],

+         )

+ 

+         self.third_commit = repo.revparse_single("HEAD")

+ 

      def test_commit_to_patch_first_commit(self):

          """ Test the commit_to_patch function of pagure.lib.git. """

          repo = pygit2.init_repository(self.gitrepo)
@@ -3622,6 +3636,24 @@ 

  

          self.assertEqual(output, exp)

  

+     def test_commit_to_patch_empty_commit(self):

+         """ Test the commit_to_path function of pagure.lib.git. """

+         repo = pygit2.init_repository(self.gitrepo)

+ 

+         patch = pagure.lib.git.commit_to_patch(repo, self.third_commit)

+         exp = ""

+         self.assertEqual(patch, exp)

+ 

+     def test_commit_to_patch_empty_commit_diff(self):

+         """ Test the commit_to_patch function of pagure.lib.git. """

+         repo = pygit2.init_repository(self.gitrepo)

+ 

+         patch = pagure.lib.git.commit_to_patch(

+             repo, self.third_commit, diff_view=True

+         )

+         exp = ""

+         self.assertEqual(patch, exp)

+ 

  

  if __name__ == "__main__":

      unittest.main(verbosity=2)

no initial comment

I'll work on tests later this week

pretty please pagure-ci rebuild

4 years ago

Pretty flake8/black aren't happy :)

I always forgot them on the first try :D

pretty please pagure-ci rebuild

4 years ago

rebased onto 45992f7a9c96b0c28626eacb0aef0538308483b5

4 years ago

Hm this feels odd, shouldn't it be just an empty string?

rebased onto e064650e53848f189cd1d3c1ef496fd6a71cabf3

4 years ago

Indeed, git generates empty .patch files for empty commits

pretty please pagure-ci rebuild

4 years ago

rebased onto 05156b0

4 years ago

rebased onto 05156b0

4 years ago

Pull-Request has been merged by pingou

4 years ago