Git: Support alternative topics on detached HEAD

Use tag if applicable, otherwise use HEAD hash

Change-Id: I5c7298446e5a325a27d6d9b5effc02d32155b583
Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
Orgad Shaneh
2012-11-29 22:24:24 +02:00
committed by Orgad Shaneh
parent 5ec925f7e7
commit 25981d918e

View File

@@ -1115,7 +1115,7 @@ struct TopicData
QString topic;
};
// Retrieve head branch
// Retrieve topic (branch, tag or HEAD hash)
QString GitClient::synchronousTopic(const QString &workingDirectory)
{
static QHash<QString, TopicData> topicCache;
@@ -1144,7 +1144,15 @@ QString GitClient::synchronousTopic(const QString &workingDirectory)
return data.topic = branch;
}
return QString();
// Detached HEAD, try a tag
arguments.clear();
arguments << QLatin1String("describe") << QLatin1String("--tags")
<< QLatin1String("--exact-match") << QLatin1String("HEAD");
if (fullySynchronousGit(workingDirectory, arguments, &outputTextData))
return data.topic = commandOutputFromLocal8Bit(outputTextData.trimmed());
// No tag, return HEAD hash
return data.topic = synchronousTopRevision(workingDirectory).left(7);
}
// Retrieve head revision