Commit b8df1a9b authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

DiffEditor: Support patch with empty new/deleted file

Change-Id: Ic0341239309be3eae1ab2faf296bc6a698acebb0
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@digia.com>
parent 204de740
......@@ -468,6 +468,12 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
"+++ /dev/null\n"
"@@ -1 +0,0 @@\n"
"-foo\n"
"diff --git a/empty b/empty\n"
"new file mode 100644\n"
"index 0000000..e69de29\n"
"diff --git a/empty b/empty\n"
"deleted file mode 100644\n"
"index e69de29..0000000\n"
);
FileData fileData1;
......@@ -551,8 +557,16 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
chunkData4.rows = rows4;
fileData4.chunks.append(chunkData4);
FileData fileData5;
fileData5.leftFileInfo = DiffFileInfo(QLatin1String("empty"), QLatin1String("0000000"));
fileData5.rightFileInfo = DiffFileInfo(QLatin1String("empty"), QLatin1String("e69de29"));
FileData fileData6;
fileData6.leftFileInfo = DiffFileInfo(QLatin1String("empty"), QLatin1String("e69de29"));
fileData6.rightFileInfo = DiffFileInfo(QLatin1String("empty"), QLatin1String("0000000"));
QList<FileData> fileDataList;
fileDataList << fileData1 << fileData2 << fileData3 << fileData4;
fileDataList << fileData1 << fileData2 << fileData3 << fileData4 << fileData5 << fileData6;
QTest::newRow("Git patch") << patch
<< fileDataList;
......
......@@ -847,8 +847,10 @@ static FileData readGitHeaderAndChunks(const QString &headerAndChunks,
+ rightFileName
+ QLatin1String(" differ$)"));
// followed either by leftFileRegExp or by binaryRegExp
if (leftFileRegExp.indexIn(patch, 0) == 0) {
// empty or followed either by leftFileRegExp or by binaryRegExp
if (patch.isEmpty() && (fileData.leftFileInfo.devNull || fileData.rightFileInfo.devNull)) {
readOk = true;
} else if (leftFileRegExp.indexIn(patch, 0) == 0) {
patch = patch.mid(leftFileRegExp.capturedTexts().at(1).count());
// followed by rightFileRegExp
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment