From 42547062af82c42bd6224801b1e0c3dddfba58ee Mon Sep 17 00:00:00 2001 From: Petar Perisin Date: Thu, 4 Apr 2013 12:28:53 +0200 Subject: [PATCH] Git: dereference topic result sometimes tags are annotated, and have different hash than head - now all will be good with them too. Change-Id: Ibd66b78e6dbc7f181ba05f45339f2d97bb611602 Reviewed-by: Orgad Shaneh Reviewed-by: Tobias Hunger --- src/plugins/git/gitclient.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/plugins/git/gitclient.cpp b/src/plugins/git/gitclient.cpp index e20b6bac846..1efc0cbaca1 100644 --- a/src/plugins/git/gitclient.cpp +++ b/src/plugins/git/gitclient.cpp @@ -1186,7 +1186,8 @@ bool GitClient::synchronousHeadRefs(const QString &workingDirectory, QStringList QString *errorMessage) { QStringList args; - args << QLatin1String("show-ref") << QLatin1String("--head") << QLatin1String("--abbrev=10"); + args << QLatin1String("show-ref") << QLatin1String("--head") + << QLatin1String("--abbrev=10") << QLatin1String("--dereference"); QByteArray outputText; QByteArray errorText; const bool rc = fullySynchronousGit(workingDirectory, args, &outputText, &errorText); @@ -1258,15 +1259,21 @@ QString GitClient::synchronousTopic(const QString &workingDirectory) if (!synchronousHeadRefs(workingDirectory, &references)) return QString(); - QString tagStart = QLatin1String("refs/tags/"); - QString remoteStart = QLatin1String("refs/remotes/"); + const QString tagStart(QLatin1String("refs/tags/")); + const QString remoteStart(QLatin1String("refs/remotes/")); + const QString dereference(QLatin1String("^{}")); 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); + int derefInd = ref.indexOf(dereference); + if (ref.startsWith(tagStart)) { + return data.topic = ref.mid(tagStart.size(), + (derefInd == -1) ? -1 : derefInd - tagStart.size()); + } + if (ref.startsWith(remoteStart)) { + remoteBranch = ref.mid(remoteStart.size(), + (derefInd == -1) ? -1 : derefInd - remoteStart.size()); + } } // No tag