diff options
author | HampusM <hampus@hampusmat.com> | 2021-05-10 15:29:59 +0200 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2021-05-10 15:29:59 +0200 |
commit | f6bbf168c6a3004cd922ebc6d4171d1dfc43707e (patch) | |
tree | 917149e4b963477c468fb3c978a44c8495b2f686 /api | |
parent | 94d26ec2a5270ca19f2e32a8381fd6e1b152c3cd (diff) |
Fixed commit parsing bug caused by empty files
Diffstat (limited to 'api')
-rw-r--r-- | api/git.js | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -165,9 +165,12 @@ function getCommit(base_dir, repo, hash) diff.forEach((line, index) => { if(/^diff\ --git a\/[^\ ]+\ b\/[^\ ]+$/.test(line) || index === diff.length - 1) { - if(start) { + if(start != undefined || start != NaN) { let file_diff = diff.slice(start, index - 1); let chunk_header_index = file_diff.findIndex((line) => /^@@\ -[0-9,]+\ \+[0-9,]+\ @@/.test(line)); + if(chunk_header_index === -1) { + chunk_header_index = file_diff.length; + } let file_info = {}; @@ -177,15 +180,17 @@ function getCommit(base_dir, repo, hash) file_info["from"] = from_to[0]; file_info["to"] = from_to[1]; - const chunk_header = /^@@\ (-[0-9,]+)\ (\+[0-9,]+)\ @@(?:\ (.*))?/.exec(file_diff[chunk_header_index]); + if(chunk_header_index != file_diff.length) { + const chunk_header = /^@@\ (-[0-9,]+)\ (\+[0-9,]+)\ @@(?:\ (.*))?/.exec(file_diff[chunk_header_index]); - file_info["from_file_range"] = chunk_header[1]; - file_info["to_file_range"] = chunk_header[2]; + file_info["from_file_range"] = chunk_header[1]; + file_info["to_file_range"] = chunk_header[2]; - file_info["diff"] = file_diff.slice(chunk_header_index + 1).join("\n"); + file_info["diff"] = file_diff.slice(chunk_header_index + 1).join("\n"); - if(chunk_header[3]) { - file_info["diff"] = chunk_header[3] + file_info["diff"]; + if(chunk_header[3]) { + file_info["diff"] = chunk_header[3] + file_info["diff"]; + } } header.forEach((line) => |