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:
Orgad Shaneh
2013-01-06 12:04:36 +02:00
committed by Orgad Shaneh
parent 0917a067af
commit 5abce3ab9f
2 changed files with 18 additions and 24 deletions

View File

@@ -307,10 +307,8 @@ bool BranchModel::refresh(const QString &workingDirectory, QString *errorMessage
branchArgs << QLatin1String(GitClient::noColorOption)
<< QLatin1String("-v") << QLatin1String("-a");
QString output;
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage)) {
if (!m_client->synchronousBranchCmd(workingDirectory, branchArgs, &output, errorMessage))
VcsBase::VcsBaseOutputWindow::instance()->appendError(*errorMessage);
return false;
}
beginResetModel();
@@ -472,10 +470,8 @@ bool BranchModel::branchIsMerged(const QModelIndex &idx)
QStringList args;
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);
return false;
}
QStringList lines = output.split(QLatin1Char('\n'), QString::SkipEmptyParts);
foreach (const QString &l, lines) {

View File

@@ -1363,11 +1363,11 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
QByteArray outputText;
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, branchArgs, &outputText, &errorText);
*output = commandOutputFromLocal8Bit(outputText);
if (!rc) {
*errorMessage = tr("Cannot run \"git branch\" in \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText));
return false;
}
*output = commandOutputFromLocal8Bit(outputText);
return true;
}
@@ -1669,24 +1669,22 @@ QStringList GitClient::synchronousRepositoryBranches(const QString &repositoryUR
QStringList branches;
branches << tr("<Detached HEAD>");
QString headSha;
if (resp.result == Utils::SynchronousProcessResponse::Finished) {
// split "82bfad2f51d34e98b18982211c82220b8db049b<tab>refs/heads/master"
foreach (const QString &line, resp.stdOut.split(QLatin1Char('\n'))) {
if (line.endsWith(QLatin1String("\tHEAD"))) {
QTC_CHECK(headSha.isNull());
headSha = line.left(line.indexOf(QLatin1Char('\t')));
continue;
}
// split "82bfad2f51d34e98b18982211c82220b8db049b<tab>refs/heads/master"
foreach (const QString &line, resp.stdOut.split(QLatin1Char('\n'))) {
if (line.endsWith(QLatin1String("\tHEAD"))) {
QTC_CHECK(headSha.isNull());
headSha = line.left(line.indexOf(QLatin1Char('\t')));
continue;
}
const QString pattern = QLatin1String("\trefs/heads/");
const int pos = line.lastIndexOf(pattern);
if (pos != -1) {
const QString branchName = line.mid(pos + pattern.count());
if (line.startsWith(headSha))
branches[0] = branchName;
else
branches.push_back(branchName);
}
const QString pattern = QLatin1String("\trefs/heads/");
const int pos = line.lastIndexOf(pattern);
if (pos != -1) {
const QString branchName = line.mid(pos + pattern.count());
if (line.startsWith(headSha))
branches[0] = branchName;
else
branches.push_back(branchName);
}
}
return branches;