From 1b36cb8e32bab2fac9d5a51a374522069b537342 Mon Sep 17 00:00:00 2001 From: Nikola Forró Date: Apr 20 2024 08:11:21 +0000 Subject: Fix pagure.lib.git.get_changed_files() Signed-off-by: Nikola Forró --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 1999516..9c2d710 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -1398,6 +1398,10 @@ def get_changed_files(torev, fromrev, abspath): """Return files changed between HEAD and BASE. Return as a dict with paths as keys and status letters as values. """ + if set(fromrev) == set("0") or set(fromrev) == set("^0"): + # get hash of the empty tree + cmd = ["hash-object", "-t", "tree", "/dev/null"] + fromrev = pagure.lib.git.read_git_output(cmd, abspath) cmd = ["diff", "--name-status", "-z", fromrev, torev] output = pagure.lib.git.read_git_output(cmd, abspath) items = output.split("\0") diff --git a/tests/test_pagure_lib_git.py b/tests/test_pagure_lib_git.py index 595de6d..08c932e 100644 --- a/tests/test_pagure_lib_git.py +++ b/tests/test_pagure_lib_git.py @@ -3231,6 +3231,12 @@ index 0000000..60f7480 hash0 = output[0].replace("'", "") hash1 = output[1].replace("'", "") + # Case 0: EMPTY_TREE => hash0 + output0 = pagure.lib.git.get_changed_files( + hash0, "^" + 40 * "0", gitrepo + ) + self.assertEqual(output0, {issue.uid: "A"}) + # Case 1: hash1 => hash0 output1 = pagure.lib.git.get_changed_files(hash0, hash1, gitrepo) self.assertEqual(output1, {issue.uid: "M"})