From 549a796fdc5d959be294b28b81d721a48fe4ae5d Mon Sep 17 00:00:00 2001 From: Joerg Bornemann Date: Mon, 2 Jan 2017 16:28:24 +0100 Subject: Fix restoration of symbolic commits qbs-benchmarker tries to restore the original commit of the qbs repository. To determine that commit the command git describe HEAD is used. For the 1.7 branch this produces something like v1.7.0-26-g2bc9373 which then is passed to 'git checkout'. Afterwards the repo is in detached HEAD state. Use 'git symbolic-ref' to determine the correct original branch name. Fall back to the old method if that doesn't work. Change-Id: I21526db1efceebcf5102eed9da43478871880ab1 Reviewed-by: Christian Kandeler --- tests/benchmarker/benchmarker.cpp | 13 ++++++++++++- tests/benchmarker/runsupport.cpp | 5 ++++- tests/benchmarker/runsupport.h | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) (limited to 'tests/benchmarker') diff --git a/tests/benchmarker/benchmarker.cpp b/tests/benchmarker/benchmarker.cpp index 69faa780c..becf60dec 100644 --- a/tests/benchmarker/benchmarker.cpp +++ b/tests/benchmarker/benchmarker.cpp @@ -96,7 +96,18 @@ void Benchmarker::benchmark() void Benchmarker::rememberCurrentRepoState() { QByteArray commit; - runProcess(QStringList() << "git" << "describe" << "HEAD", m_qbsRepo, &commit); + int exitCode = 0; + try { + runProcess(QStringList() << "git" << "symbolic-ref" << "--short" << "HEAD", m_qbsRepo, + &commit, &exitCode); + } catch (const Exception &) { + if (exitCode == 0) { + // runProcess did not throw because of the exit code. + throw; + } + // Fallback, in case git cannot retrieve a nice symbolic name. + runProcess(QStringList() << "git" << "describe" << "HEAD", m_qbsRepo, &commit); + } m_commitToRestore = QString::fromLatin1(commit); } diff --git a/tests/benchmarker/runsupport.cpp b/tests/benchmarker/runsupport.cpp index 360cc871b..669cd3ae5 100644 --- a/tests/benchmarker/runsupport.cpp +++ b/tests/benchmarker/runsupport.cpp @@ -36,7 +36,8 @@ namespace qbsBenchmarker { -void runProcess(const QStringList &commandLine, const QString &workingDir, QByteArray *output) +void runProcess(const QStringList &commandLine, const QString &workingDir, QByteArray *output, + int *exitCode) { QStringList args = commandLine; const QString command = args.takeFirst(); @@ -51,6 +52,8 @@ void runProcess(const QStringList &commandLine, const QString &workingDir, QByte throw Exception(QString::fromLatin1("Error running '%1': %2") .arg(command, p.errorString())); } + if (exitCode) + *exitCode = p.exitCode(); if (p.exitCode() != 0) { QString errorString = QString::fromLatin1("Command '%1' finished with exit code %2.") .arg(command).arg(p.exitCode()); diff --git a/tests/benchmarker/runsupport.h b/tests/benchmarker/runsupport.h index 4bfd4289b..9c09019c8 100644 --- a/tests/benchmarker/runsupport.h +++ b/tests/benchmarker/runsupport.h @@ -39,7 +39,7 @@ QT_END_NAMESPACE namespace qbsBenchmarker { void runProcess(const QStringList &commandLine, const QString& workingDir = QString(), - QByteArray *output = 0); + QByteArray *output = nullptr, int *exitCode = nullptr); } // namespace qbsBenchmarker -- cgit v1.2.3