diff --git a/src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala b/src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala index 9e82f07..c412d1c 100644 --- a/src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala +++ b/src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala @@ -53,14 +53,23 @@ object GitDiffParser extends RegexParsers { def allDiffs: Parser[List[Diff]] = rep1(diff) - def diff: Parser[Diff] = binaryDiff | gitDiff + def diff: Parser[Diff] = binaryRenameDiff | binaryDiff | gitDiff def readUpToNextDiffOrEnd = """(?s).+?(?=((?:diff --git)|$))\n?""".r + def binaryRenameDiff: Parser[BinaryDiff] = gitDiffHeader ~ extendedDiffHeader ~ binaryFilesDiffer ^^ { + _ => BinaryDiff() + } + def binaryDiff: Parser[BinaryDiff] = gitDiffHeader ~ extendedDiffHeader ~ "GIT binary patch" ~ readUpToNextDiffOrEnd ^^ { _ => BinaryDiff() } + //Strings " and " and " differ" are included in filePath + def binaryFilesDiffer: Parser[FileChange] = "Binary files " ~> (("a/" ~> filePath) ~ (" b/" ~> filePath)) <~ nl ^^ { + case oldF ~ newF => FileChange(oldF, newF) + } + def gitDiff: Parser[GitDiff] = gitDiffHeader ~ extendedDiffHeader ~ hunks ^^ { case fc ~ h ~ hs => GitDiff(fc, h, hs) }