Skip to content

Commit

Permalink
Fix mibexsoftware#102 add renamed binary files case
Browse files Browse the repository at this point in the history
  • Loading branch information
Laura Cameran committed Jun 19, 2020
1 parent 440555f commit 7066e3e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 7066e3e

Please sign in to comment.