diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index ad056aa6cec..4a185c9ebca 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1103,12 +1103,20 @@ QString GitClient::synchronousBranch(const QString &workingDirectory) { QByteArray outputTextData; QStringList arguments; - arguments << QLatin1String("symbolic-ref") << QLatin1String("--short") << QLatin1String("HEAD"); + arguments << QLatin1String("symbolic-ref") << QLatin1String("HEAD"); // if HEAD is detached, the command is expected to fail. if (!fullySynchronousGit(workingDirectory, arguments, &outputTextData)) return QString(); QString branch = commandOutputFromLocal8Bit(outputTextData); branch.remove(QLatin1Char('\n')); + + // Must strip the "refs/heads/" prefix manually since the --short switch + // of git symbolic-ref only got introduced with git 1.7.10, which is not + // available for all popular Linux distributions yet. + const QString refsHeadsPrefix = QLatin1String("refs/heads/"); + if (branch.startsWith(refsHeadsPrefix)) + branch.remove(0, refsHeadsPrefix.count()); + return branch; }