From ed25f0afef0a21e187bb5bec61605e0e71e3d689 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Jul 18 2018 20:36:45 +0000 Subject: Fix splitting the diff per file Basically, when rendering diffs, we split them by file so we can render the changes made to each file separately. However, if one of the file happens to contain a diff itself (for example if that file is a patch), then we don't want to split that, it'll make a mess. So rather than splitting on "diff --git a/" we ensure we're spliting on new lines starting with this by splitting on "\ndiff --git a/". Fixes https://pagure.io/pagure/issue/3426 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 4500c01..5df021c 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -86,9 +86,11 @@ def commit_to_patch( if diff_view: if separated: - for el in diff.patch.split('diff --git a/'): - if el: - patch.append('diff --git a/' + el) + for el in diff.patch.split('\ndiff --git a/'): + if el and not el.startswith('diff --git a/'): + patch.append('\ndiff --git a/' + el) + elif el: + patch.append(el) else: patch.append(diff.patch) else: