summaryrefslogtreecommitdiff
path: root/src/plugins/diffeditor/diffeditorplugin.cpp
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2017-11-29 21:36:30 +0100
committerJarek Kobus <jaroslaw.kobus@qt.io>2019-11-19 11:19:43 +0000
commit17668329181be771669c10baa0e322e0192fecdb (patch)
treeca70331ef982dc38de26da13201b6f8c090dd3c9 /src/plugins/diffeditor/diffeditorplugin.cpp
parent27586827238ca9079860e77a7b23ae20d163143e (diff)
downloadqt-creator-17668329181be771669c10baa0e322e0192fecdb.tar.gz
DiffEditor: Stage and unstage selected lines for Git
Fixes: QTCREATORBUG-19071 Change-Id: I560ba208e68e477ea865e499847d819cfdfeb6f3 Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: André Hartmann <aha_1980@gmx.de>
Diffstat (limited to 'src/plugins/diffeditor/diffeditorplugin.cpp')
-rw-r--r--src/plugins/diffeditor/diffeditorplugin.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/plugins/diffeditor/diffeditorplugin.cpp b/src/plugins/diffeditor/diffeditorplugin.cpp
index 0c52b55a9e..652c6e9d14 100644
--- a/src/plugins/diffeditor/diffeditorplugin.cpp
+++ b/src/plugins/diffeditor/diffeditorplugin.cpp
@@ -610,6 +610,7 @@ void DiffEditorPlugin::diffExternalFiles()
Q_DECLARE_METATYPE(DiffEditor::ChunkData)
Q_DECLARE_METATYPE(DiffEditor::FileData)
+Q_DECLARE_METATYPE(DiffEditor::ChunkSelection)
static inline QString _(const char *string) { return QString::fromLatin1(string); }
@@ -1430,6 +1431,140 @@ void DiffEditor::Internal::DiffEditorPlugin::testReadPatch()
}
}
+void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch_data()
+{
+ QTest::addColumn<ChunkData>("chunk");
+ QTest::addColumn<QStringList>("rightLines");
+ QTest::addColumn<ChunkSelection>("selection");
+
+ auto createChunk = []() {
+ ChunkData chunk;
+ chunk.contextInfo = "void DiffEditor::ctor()";
+ chunk.contextChunk = false;
+ chunk.leftStartingLineNumber = 49;
+ chunk.rightStartingLineNumber = 49;
+ return chunk;
+ };
+ auto appendRow = [](ChunkData *chunk, const QString &left, const QString &right) {
+ RowData row;
+ row.equal = (left == right);
+ row.leftLine.text = left;
+ row.leftLine.textLineType = left.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
+ row.rightLine.text = right;
+ row.rightLine.textLineType = right.isEmpty() ? TextLineData::Separator : TextLineData::TextLine;
+ chunk->rows.append(row);
+ };
+ ChunkData chunk;
+ QStringList rightLines;
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "", "B"); // 51 +
+ appendRow(&chunk, "C", "C"); // 52
+ rightLines = QStringList {
+ "A",
+ "B",
+ "C"
+ };
+ QTest::newRow("one added") << chunk << rightLines << ChunkSelection();
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "B", ""); // 51 -
+ appendRow(&chunk, "C", "C"); // 52
+ rightLines = QStringList {
+ "A",
+ "",
+ "C"
+ };
+ QTest::newRow("one removed") << chunk << rightLines << ChunkSelection();
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "", "B"); // 51
+ appendRow(&chunk, "", "C"); // 52 +
+ appendRow(&chunk, "", "D"); // 53 +
+ appendRow(&chunk, "", "E"); // 54
+ appendRow(&chunk, "F", "F"); // 55
+ rightLines = QStringList {
+ "A",
+ "C",
+ "D",
+ "F",
+ };
+ QTest::newRow("stage selected added") << chunk << rightLines << ChunkSelection(2, 2);
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "", "B"); // 51 +
+ appendRow(&chunk, "C", "D"); // 52
+ appendRow(&chunk, "E", "E"); // 53
+ rightLines = QStringList {
+ "A",
+ "B",
+ "C",
+ "E",
+ };
+ QTest::newRow("stage selected added keep changed") << chunk << rightLines << ChunkSelection(1, 1);
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "B", ""); // 51
+ appendRow(&chunk, "C", ""); // 52 -
+ appendRow(&chunk, "D", ""); // 53 -
+ appendRow(&chunk, "E", ""); // 54
+ appendRow(&chunk, "F", "F"); // 55
+ rightLines = QStringList {
+ "A",
+ "B",
+ "",
+ "",
+ "E",
+ "F",
+ };
+ QTest::newRow("stage selected removed") << chunk << rightLines << ChunkSelection(2, 2);
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "B", ""); // 51
+ appendRow(&chunk, "C", ""); // 52 -
+ appendRow(&chunk, "", "D"); // 53 +
+ appendRow(&chunk, "", "E"); // 54
+ appendRow(&chunk, "F", "F"); // 55
+ rightLines = QStringList {
+ "A",
+ "B",
+ "",
+ "D",
+ "F",
+ };
+ QTest::newRow("stage selected added/removed") << chunk << rightLines << ChunkSelection(2, 2);
+
+ chunk = createChunk();
+ appendRow(&chunk, "A", "A"); // 50
+ appendRow(&chunk, "B", "C"); // 51 -/+
+ appendRow(&chunk, "D", "D"); // 52
+ rightLines = QStringList {
+ "A",
+ "C",
+ "D",
+ };
+ QTest::newRow("stage modified row") << chunk << rightLines << ChunkSelection(1, 1);
+}
+
+void DiffEditor::Internal::DiffEditorPlugin::testFilterPatch()
+{
+ QFETCH(ChunkData, chunk);
+ QFETCH(QStringList, rightLines);
+ QFETCH(ChunkSelection, selection);
+
+ ChunkData result = DiffEditorDocument::filterChunk(chunk, selection, false);
+ QCOMPARE(result.rows.size(), rightLines.size());
+ for (int i = 0; i < rightLines.size(); ++i) {
+ QCOMPARE(result.rows.at(i).rightLine.text, rightLines.at(i));
+ }
+}
+
#endif // WITH_TESTS
#include "diffeditorplugin.moc"