Commit 31ed90b4 authored by Petar Perisin's avatar Petar Perisin
Browse files

Git: Show remote branch in topic



No extra terminal commands are executed.

Change-Id: Ia875b5dbce2784962b9fc2b7c9c1b0a696a02ec8
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
Reviewed-by: default avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
parent eebee331
...@@ -1181,6 +1181,42 @@ static inline QString msgCannotDetermineBranch(const QString &workingDirectory, ...@@ -1181,6 +1181,42 @@ static inline QString msgCannotDetermineBranch(const QString &workingDirectory,
return GitClient::tr("Cannot retrieve branch of \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), why); return GitClient::tr("Cannot retrieve branch of \"%1\": %2").arg(QDir::toNativeSeparators(workingDirectory), why);
} }
bool GitClient::synchronousHeadRefs(const QString &workingDirectory, QStringList *output,
QString *errorMessage)
{
QStringList args;
args << QLatin1String("show-ref") << QLatin1String("--head") << QLatin1String("--abbrev=10");
QByteArray outputText;
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText);
if (!rc) {
QString message = tr("Cannot run \"git show-ref --head\" in \"%1\": %2").
arg(QDir::toNativeSeparators(workingDirectory), commandOutputFromLocal8Bit(errorText));
if (errorMessage)
*errorMessage = message;
else
outputWindow()->append(message);
return false;
}
QByteArray headSha = outputText.left(10);
QByteArray newLine("\n");
int currentIndex = 15;
while (true) {
currentIndex = outputText.indexOf(headSha, currentIndex);
if (currentIndex < 0)
break;
currentIndex += 11;
output->append(QString::fromLocal8Bit(outputText.mid(currentIndex,
outputText.indexOf(newLine, currentIndex) - currentIndex)));
}
return true;
}
struct TopicData struct TopicData
{ {
QDateTime timeStamp; QDateTime timeStamp;
...@@ -1216,15 +1252,24 @@ QString GitClient::synchronousTopic(const QString &workingDirectory) ...@@ -1216,15 +1252,24 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
return data.topic = branch; return data.topic = branch;
} }
// Detached HEAD, try a tag // Detached HEAD, try a tag or remote branch
arguments.clear(); QStringList references;
arguments << QLatin1String("describe") << QLatin1String("--tags") if (!synchronousHeadRefs(workingDirectory, &references))
<< QLatin1String("--exact-match") << QLatin1String("HEAD"); return QString();
if (fullySynchronousGit(workingDirectory, arguments, &outputTextData, 0, false))
return data.topic = commandOutputFromLocal8Bit(outputTextData.trimmed()); QString tagStart = QLatin1String("refs/tags/");
QString remoteStart = QLatin1String("refs/remotes/");
QString remoteBranch;
foreach (const QString &ref, references) {
if (ref.startsWith(tagStart))
return data.topic = ref.mid(10);
if (ref.startsWith(remoteStart))
remoteBranch = ref.mid(13);
}
// No tag // No tag
return data.topic = tr("Detached HEAD"); return data.topic = remoteBranch.isEmpty() ? tr("Detached HEAD") : remoteBranch;
} }
// Retrieve head revision // Retrieve head revision
......
...@@ -188,6 +188,8 @@ public: ...@@ -188,6 +188,8 @@ public:
QString synchronousShortDescription(const QString &workingDirectory, const QString &revision); QString synchronousShortDescription(const QString &workingDirectory, const QString &revision);
QString synchronousShortDescription(const QString &workingDirectory, const QString &revision, QString synchronousShortDescription(const QString &workingDirectory, const QString &revision,
const QString &format); const QString &format);
bool synchronousHeadRefs(const QString &workingDirectory, QStringList *output,
QString *errorMessage = 0);
QString synchronousTopic(const QString &workingDirectory); QString synchronousTopic(const QString &workingDirectory);
QString synchronousTopRevision(const QString &workingDirectory, QString *errorMessage = 0); QString synchronousTopRevision(const QString &workingDirectory, QString *errorMessage = 0);
void synchronousTagsForCommit(const QString &workingDirectory, const QString &revision, void synchronousTagsForCommit(const QString &workingDirectory, const QString &revision,
......
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