Commit 0865e9eb authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: List branches on show



Change-Id: Ie69a58efc7068c699abf0e3d396216d9809346f4
Reviewed-by: default avatarAndré Hartmann <aha_1980@gmx.de>
Reviewed-by: default avatarPetar Perisin <petar.perisin@gmail.com>
parent 51f69c88
......@@ -1800,6 +1800,22 @@ void GitClient::synchronousTagsForCommit(const QString &workingDirectory, const
}
}
QStringList GitClient::synchronousBranchesForCommit(const QString &workingDirectory, const QString &revision)
{
QString output;
QStringList arguments;
arguments << QLatin1String(noColorOption) << QLatin1String("-a")
<< QLatin1String("--contains") << revision;
synchronousBranchCmd(workingDirectory, arguments, &output, 0);
QStringList res;
foreach (const QString &branch, output.split(QLatin1Char('\n'))) {
const QString b = branch.mid(2).trimmed();
if (!b.isEmpty())
res << b;
}
return res;
}
bool GitClient::isRemoteCommit(const QString &workingDirectory, const QString &commit)
{
QStringList arguments;
......@@ -1958,11 +1974,11 @@ bool GitClient::synchronousBranchCmd(const QString &workingDirectory, QStringLis
QByteArray errorText;
const bool rc = fullySynchronousGit(workingDirectory, branchArgs, &outputText, &errorText);
*output = commandOutputFromLocal8Bit(outputText);
if (!rc) {
*errorMessage = msgCannotRun(QLatin1String("git branch"), workingDirectory, commandOutputFromLocal8Bit(errorText));
return false;
if (!rc && errorMessage) {
*errorMessage = msgCannotRun(QLatin1String("git branch"), workingDirectory,
commandOutputFromLocal8Bit(errorText));
}
return true;
return rc;
}
bool GitClient::synchronousTagCmd(const QString &workingDirectory, QStringList tagArgs, QString *output, QString *errorMessage)
......
......@@ -236,6 +236,8 @@ public:
QString synchronousTopRevision(const QString &workingDirectory, QString *errorMessage = 0);
void synchronousTagsForCommit(const QString &workingDirectory, const QString &revision,
QString &precedes, QString &follows);
QStringList synchronousBranchesForCommit(const QString &workingDirectory,
const QString &revision);
bool isRemoteCommit(const QString &workingDirectory, const QString &commit);
bool cloneRepository(const QString &directory, const QByteArray &url);
......
......@@ -190,11 +190,25 @@ void GitEditor::setPlainTextFiltered(const QString &text)
QString precedes, follows;
if (modText.startsWith(QLatin1String("commit "))) { // show
int lastHeaderLine = modText.indexOf(QLatin1String("\n\n")) + 1;
plugin->gitClient()->synchronousTagsForCommit(workingDirectory, modText.mid(7, 8), precedes, follows);
const QString commit = modText.mid(7, 8);
plugin->gitClient()->synchronousTagsForCommit(workingDirectory, commit, precedes, follows);
if (!precedes.isEmpty())
modText.insert(lastHeaderLine, QLatin1String("Precedes: ") + precedes + QLatin1Char('\n'));
if (!follows.isEmpty())
modText.insert(lastHeaderLine, QLatin1String("Follows: ") + follows + QLatin1Char('\n'));
QString moreBranches;
QStringList branches = plugin->gitClient()->synchronousBranchesForCommit(
workingDirectory, commit);
const int branchCount = branches.count();
// If there are more than 20 branches, list first 10 followed by a hint
if (branchCount > 20) {
const int leave = 10;
moreBranches = tr(" and %1 more").arg(branchCount - leave);
branches.erase(branches.begin() + leave, branches.end());
}
modText.insert(lastHeaderLine, QLatin1String("Branches: ")
+ branches.join(QLatin1String(", ")) + moreBranches
+ QLatin1Char('\n'));
}
break;
}
......
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