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

DiffEditor: Support mode change in Git diff

Task-number: QTCREATORBUG-14963
Change-Id: I5d26ae810add657a94fb40a5d4437e2d17a1625a
Reviewed-by: default avatarJarek Kobus <jaroslaw.kobus@theqtcompany.com>
parent 9bd066cb
......@@ -541,6 +541,17 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
"similarity index 99%\n"
"rename from file a.txt\n"
"rename to file b.txt\n"
"diff --git a/file.txt b/file.txt\n"
"old mode 100644\n"
"new mode 100755\n"
"index 1234567..9876543\n"
"--- a/file.txt\n"
"+++ b/file.txt\n"
"@@ -20,3 +20,3 @@\n"
" A\n"
"-B\n"
"+C\n"
" D\n"
);
FileData fileData1;
......@@ -641,8 +652,13 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data()
fileData8.rightFileInfo = DiffFileInfo(_("file b.txt"));
fileData8.fileOperation = FileData::RenameFile;
FileData fileData9;
fileData9.leftFileInfo = DiffFileInfo(_("file.txt"), _("1234567"));
fileData9.rightFileInfo = DiffFileInfo(_("file.txt"), _("9876543"));
fileData9.chunks << chunkData7;
QList<FileData> fileDataList1;
fileDataList1 << fileData1 << fileData2 << fileData3 << fileData4 << fileData5 << fileData6 << fileData7 << fileData8;
fileDataList1 << fileData1 << fileData2 << fileData3 << fileData4 << fileData5
<< fileData6 << fileData7 << fileData8 << fileData9;
QTest::newRow("Git patch") << patch
<< fileDataList1;
......
......@@ -892,6 +892,8 @@ static FileData readGitHeaderAndChunks(const QString &headerAndChunks,
// will be followed by: index shasha..0000000, file "b" replaced by "/dev/null", @@ -m,n +0,0 @@
const QRegExp deletedFileMode(QLatin1String("^deleted file mode \\d+\\n")); // deleted file mode octal
const QRegExp modeChangeRegExp(QLatin1String("^old mode \\d+\\nnew mode \\d+\\n"));
const QRegExp indexRegExp(QLatin1String("^index (\\w+)\\.{2}(\\w+)(?: \\d+)?(\\n|$)")); // index cap1..cap2(optionally: octal)
QString leftFileName = QLatin1String("a/") + fileName;
......@@ -905,6 +907,8 @@ static FileData readGitHeaderAndChunks(const QString &headerAndChunks,
fileData.fileOperation = FileData::DeleteFile;
rightFileName = devNull;
patch.remove(0, deletedFileMode.matchedLength());
} else if (modeChangeRegExp.indexIn(patch) == 0) {
patch.remove(0, modeChangeRegExp.matchedLength());
}
if (indexRegExp.indexIn(patch) == 0) {
......
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