forked from qt-creator/qt-creator
Git: Make branch lookup more robust
It might fail because a particular branch points to an invalid commit. We don't want that to prevent display of all other branches. Change-Id: I8fe427735351fc458c99396dc1f9d77bc948468e Reviewed-by: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
0917a067af
commit
5abce3ab9f
@@ -307,10 +307,8 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
|
|||||||
branchArgs << QLatin1String(GitClient::noColorOption)
|
branchArgs << QLatin1String(GitClient::noColorOption)
|
||||||
<< QLatin1String("-v") << QLatin1String("-a");
|
<< QLatin1String("-v") << QLatin1String("-a");
|
||||||
QString output;
|
QString output;
|
||||||
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage)) {
|
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage))
|
||||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
|
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|
||||||
@@ -472,10 +470,8 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx)
|
|||||||
QStringList args;
|
QStringList args;
|
||||||
|
|
||||||
args << QLatin1String("-a") << QLatin1String("--contains") << sha(idx);
|
args << QLatin1String("-a") << QLatin1String("--contains") << sha(idx);
|
||||||
if (!m_client->synchronousBranchCmd(m_workingDirectory, args, &output, &errorMessage)) {
|
if (!m_client->synchronousBranchCmd(m_workingDirectory, args, &output, &errorMessage))
|
||||||
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
|
VcsBase::VcsBaseOutputWindow::instance()->appendError(errorMessage);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList lines = output.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
QStringList lines = output.split(QLatin1Char('\n'), QString::SkipEmptyParts);
|
||||||
foreach (const QString &l, lines) {
|
foreach (const QString &l, lines) {
|
||||||
|
|||||||
@@ -1363,11 +1363,11 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
|
|||||||
QByteArray outputText;
|
QByteArray outputText;
|
||||||
QByteArray errorText;
|
QByteArray errorText;
|
||||||
const bool rc = fullySynchronousGit(workingDirectory, branchArgs, &outputText, &errorText);
|
const bool rc = fullySynchronousGit(workingDirectory, branchArgs, &outputText, &errorText);
|
||||||
|
*output = commandOutputFromLocal8Bit(outputText);
|
||||||
if (!rc) {
|
if (!rc) {
|
||||||
*errorMessage = tr("Cannot run \"git branch\" in \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText));
|
*errorMessage = tr("Cannot run \"git branch\" in \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*output = commandOutputFromLocal8Bit(outputText);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1669,24 +1669,22 @@ QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryUR
|
|||||||
QStringList branches;
|
QStringList branches;
|
||||||
branches << tr("<Detached HEAD>");
|
branches << tr("<Detached HEAD>");
|
||||||
QString headSha;
|
QString headSha;
|
||||||
if (resp.result == Utils::SynchronousProcessResponse::Finished) {
|
// split "82bfad2f51d34e98b18982211c82220b8db049b<tab>refs/heads/master"
|
||||||
// split "82bfad2f51d34e98b18982211c82220b8db049b<tab>refs/heads/master"
|
foreach (const QString &line, resp.stdOut.split(QLatin1Char('\n'))) {
|
||||||
foreach (const QString &line, resp.stdOut.split(QLatin1Char('\n'))) {
|
if (line.endsWith(QLatin1String("\tHEAD"))) {
|
||||||
if (line.endsWith(QLatin1String("\tHEAD"))) {
|
QTC_CHECK(headSha.isNull());
|
||||||
QTC_CHECK(headSha.isNull());
|
headSha = line.left(line.indexOf(QLatin1Char('\t')));
|
||||||
headSha = line.left(line.indexOf(QLatin1Char('\t')));
|
continue;
|
||||||
continue;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const QString pattern = QLatin1String("\trefs/heads/");
|
const QString pattern = QLatin1String("\trefs/heads/");
|
||||||
const int pos = line.lastIndexOf(pattern);
|
const int pos = line.lastIndexOf(pattern);
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
const QString branchName = line.mid(pos + pattern.count());
|
const QString branchName = line.mid(pos + pattern.count());
|
||||||
if (line.startsWith(headSha))
|
if (line.startsWith(headSha))
|
||||||
branches[0] = branchName;
|
branches[0] = branchName;
|
||||||
else
|
else
|
||||||
branches.push_back(branchName);
|
branches.push_back(branchName);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return branches;
|
return branches;
|
||||||
|
|||||||
Reference in New Issue
Block a user