diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp index 90cdb054220..fc607535af5 100644 --- a/src/plugins/diffeditor/diffeditorplugin.cpp +++ b/src/plugins/diffeditor/diffeditorplugin.cpp @@ -1341,6 +1341,26 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch_data() QTest::newRow("Mode change") << patch << fileDataList9; + ////////////// + patch = R"(diff --git a/old.sh b/new.sh +old mode 100644 +new mode 100755 +similarity index 100% +rename from old.sh +rename to new.sh +)" + ; + + fileData1 = FileData(); + fileData1.leftFileInfo = DiffFileInfo("old.sh"); + fileData1.rightFileInfo = DiffFileInfo("new.sh"); + fileData1.fileOperation = FileData::RenameFile; + + QList fileDataList10; + fileDataList10 << fileData1; + + QTest::newRow("Mode change + rename") << patch << fileDataList10; + ////////////// // Subversion New diff --git a/src/plugins/diffeditor/diffutils.cpp b/src/plugins/diffeditor/diffutils.cpp index 9db8a09bc4c..27ee1d3b484 100644 --- a/src/plugins/diffeditor/diffutils.cpp +++ b/src/plugins/diffeditor/diffutils.cpp @@ -997,12 +997,15 @@ static QList readDiffPatch(StringView patch, bool *ok, QFutureInterfac // The git diff patch format (CopyFile, RenameFile) // 0. [some text lines to skip, e.g. show description]\n // 1. diff --git a/[leftFileName] b/[rightFileName]\n -// 2. [dis]similarity index [0-100]%\n +// 2a. old mode [oldFileModeNumber]\n +// new mode [newFileModeNumber]\n +// 2b. +// 3. [dis]similarity index [0-100]%\n // [copy / rename] from [leftFileName]\n // [copy / rename] to [rightFileName] -// 3a. -// 3b. index [leftIndexSha]..[rightIndexSha] -// 4. --- [leftFileNameOrDevNull]\n +// 4a. +// 4b. index [leftIndexSha]..[rightIndexSha] +// 5. --- [leftFileNameOrDevNull]\n // +++ [rightFileNameOrDevNull]\n // @@ -1164,10 +1167,21 @@ static bool detectFileData(StringView patch, FileData *fileData, StringView *rem } else { // copy / rename - + StringView afterModeOrSimilarity; StringView afterSimilarity; - // (dis)similarity index [0-100]% - readLine(afterDiffGit, &afterSimilarity, &hasNewLine); + const StringView secondLine = readLine(afterDiffGit, &afterModeOrSimilarity, &hasNewLine); + if (secondLine.startsWith(QLatin1String("old mode "))) { + if (!hasNewLine) + return false; + readLine(afterModeOrSimilarity, &afterModeOrSimilarity, &hasNewLine); // new mode + if (!hasNewLine) + return false; + // (dis)similarity index [0-100]% + readLine(afterModeOrSimilarity, &afterSimilarity, &hasNewLine); + } else { + afterSimilarity = afterModeOrSimilarity; + } + if (!hasNewLine) return false; // we need to have at least one more line