Commit 8356221e authored by Davi Marinho's avatar Davi Marinho Committed by Christoph Cullmann
Browse files

Fix triplicated documents when occurs git conflict

Fix wrong triplicated documents when occurs a git conflict. 
Now it shows correctly only one document.
parent d9a78dff
Pipeline #150355 passed with stage
in 2 minutes and 45 seconds
......@@ -430,17 +430,29 @@ QVector<QString> KateProjectWorker::filesFromGit(const QDir &dir, bool recursive
* use --recurse-submodules, there since git 2.11 (released 2016)
* our own submodules handling code leads to file duplicates
*/
const QStringList lsFilesArgs{QStringLiteral("ls-files"), QStringLiteral("-z"), QStringLiteral("--recurse-submodules"), QStringLiteral(".")};
QStringList lsFilesArgs{QStringLiteral("ls-files"), QStringLiteral("-z"), QStringLiteral("--recurse-submodules"), QStringLiteral(".")};
/**
* ls-files untracked
*/
const QStringList lsFilesUntrackedArgs{QStringLiteral("ls-files"),
QStringList lsFilesUntrackedArgs{QStringLiteral("ls-files"),
QStringLiteral("-z"),
QStringLiteral("--others"),
QStringLiteral("--exclude-standard"),
QStringLiteral(".")};
const auto [major, minor] = getGitVersion(dir.absolutePath());
if(major > 2 || (major == 2 && minor >= 31))
{
lsFilesArgs.insert(3, QStringLiteral("--deduplicate"));
lsFilesUntrackedArgs.insert(4, QStringLiteral("--deduplicate"));
} else {
qDebug() << "Your git version is too old, please update.";
}
// ls-files + ls-files untracked
return gitFiles(dir, recursive, lsFilesArgs, false) << gitFiles(dir, recursive, lsFilesUntrackedArgs, true);
}
......
......@@ -8,6 +8,7 @@
#include <QProcess>
#include <QStandardPaths>
#include <QRegularExpression>
/**
* small helper function to setup a QProcess based "git" command.
......@@ -50,3 +51,40 @@ inline bool setupGitProcess(QProcess &process, const QString &workingDirectory,
process.setProcessEnvironment(env);
return true;
}
/**
* helper function to get the git version
* @param dir
*/
inline std::pair<int, int> getGitVersion(const QString &workingDir)
{
QProcess git;
if (!setupGitProcess(git, workingDir, {QStringLiteral("--version")})) {
return {-1, -1};
}
git.start(QProcess::ReadOnly);
if (git.waitForStarted() && git.waitForFinished(-1)) {
if (git.exitStatus() != QProcess::NormalExit || git.exitCode() != 0) {
return {-1, -1};
}
QString gitVersion = QString::fromUtf8(git.readAllStandardOutput());
QString expression = QStringLiteral("git version\\s*(\\d+).(\\d+).(\\d+)+.*");
QRegularExpression gitRegex(expression);
QRegularExpressionMatch gitMatch = gitRegex.match(gitVersion);
bool okMajor;
bool okMinor;
int versionMajor = gitMatch.captured(1).toInt(&okMajor);
int versionMinor = gitMatch.captured(2).toInt(&okMinor);
if(okMajor && okMinor)
{
return {versionMajor, versionMinor};
} else {
return {-1, -1};
}
}
return {-1, -1};
}
Supports Markdown
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