Commit 5011ba94 authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh

Git: Support merge status

Change-Id: If0338d066a2844a8bedf3e5ecf89979dc5c20385
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent ab85e734
......@@ -119,26 +119,36 @@ bool CommitData::checkLine(const QString &stateInfo, const QString &file)
return true;
}
FileStates stagedState = stateFor(stateInfo.at(0));
if (stagedState == UnknownFileState)
FileStates xState = stateFor(stateInfo.at(0));
FileStates yState = stateFor(stateInfo.at(1));
if (xState == UnknownFileState || yState == UnknownFileState)
return false;
stagedState |= StagedFile;
if (stagedState != StagedFile)
files.append(qMakePair(stagedState, file));
FileStates state = stateFor(stateInfo.at(1));
if (state == UnknownFileState)
return false;
bool isMerge = (xState == UnmergedFile || yState == UnmergedFile ||
((xState == yState) && (xState == AddedFile || xState == DeletedFile)));
if (isMerge) {
if (xState == yState) {
if (xState == UnmergedFile)
xState = ModifiedFile;
files.append(qMakePair(xState | UnmergedFile | UnmergedUs | UnmergedThem, file));
} else if (xState == UnmergedFile) {
files.append(qMakePair(yState | UnmergedFile | UnmergedThem, file));
} else {
files.append(qMakePair(xState | UnmergedFile | UnmergedUs, file));
}
} else {
xState |= StagedFile;
if (xState != StagedFile)
files.append(qMakePair(xState, file));
if (state != UntrackedFile) {
QString newFile = file;
if (stagedState & (RenamedFile | CopiedFile))
newFile = file.mid(file.indexOf(QLatin1String(" -> ")) + 4);
if (yState != UntrackedFile) {
QString newFile = file;
if (xState & (RenamedFile | CopiedFile))
newFile = file.mid(file.indexOf(QLatin1String(" -> ")) + 4);
files.append(qMakePair(state, newFile));
files.append(qMakePair(yState, newFile));
}
}
return true;
}
......@@ -199,8 +209,14 @@ QString CommitData::stateDisplayName(const FileStates &state)
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", "renamed"));
else if (state & CopiedFile)
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", "copied"));
else if (state & UnmergedFile)
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", "unmerged"));
if (state & UnmergedUs) {
if (state & UnmergedThem)
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", " by both"));
else
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", " by us"));
} else if (state & UnmergedThem) {
resultState.append(QCoreApplication::translate("Git::Internal::CommitData", " by them"));
}
return resultState;
}
......
......@@ -75,6 +75,9 @@ enum FileState {
CopiedFile = 0x20,
UnmergedFile = 0x40,
UnmergedUs = 0x100,
UnmergedThem = 0x200,
UnknownFileState = 0x800
};
Q_DECLARE_FLAGS(FileStates, FileState)
......
......@@ -1091,6 +1091,15 @@ void GitPlugin::testStatusParsing_data()
QTest::newRow("C ") << (CopiedFile | StagedFile) << FileStates(UnknownFileState);
QTest::newRow("CM") << (CopiedFile | StagedFile) << FileStates(ModifiedFile);
QTest::newRow("CD") << (CopiedFile | StagedFile) << FileStates(DeletedFile);
// Merges
QTest::newRow("DD") << (DeletedFile | UnmergedFile | UnmergedUs | UnmergedThem) << FileStates(UnknownFileState);
QTest::newRow("AA") << (AddedFile | UnmergedFile | UnmergedUs | UnmergedThem) << FileStates(UnknownFileState);
QTest::newRow("UU") << (ModifiedFile | UnmergedFile | UnmergedUs | UnmergedThem) << FileStates(UnknownFileState);
QTest::newRow("AU") << (AddedFile | UnmergedFile | UnmergedUs) << FileStates(UnknownFileState);
QTest::newRow("UD") << (DeletedFile | UnmergedFile | UnmergedThem) << FileStates(UnknownFileState);
QTest::newRow("UA") << (AddedFile | UnmergedFile | UnmergedThem) << FileStates(UnknownFileState);
QTest::newRow("DU") << (DeletedFile | UnmergedFile | UnmergedUs) << FileStates(UnknownFileState);
}
void GitPlugin::testStatusParsing()
......
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