From 769626581f777a54bb7792242d5a987f6e46ca26 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Fri, 11 Aug 2023 11:12:59 +0200 Subject: [PATCH] Use head -n 1 in gitLastCommit(). --- git/git_client.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/git/git_client.cpp b/git/git_client.cpp index d2c3616..78defa4 100644 --- a/git/git_client.cpp +++ b/git/git_client.cpp @@ -268,13 +268,15 @@ QString GitClient::gitLastCommit(QString fileName) { if (QDir(m_customerRepository).exists()) { QString const filePath = QDir::cleanPath(m_customerRepository + QDir::separator() + fileName); - QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName); - Command c("bash"); - if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) { - QString const r = c.getCommandResult(); - int const idx = r.indexOf("commit "); - if (idx != -1) { - return r.mid(idx + 8).trimmed(); + if (QFile(filePath).exists()) { + QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName); + Command c("bash"); + if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) { + QString const r = c.getCommandResult(); + int const idx = r.indexOf("commit "); + if (idx != -1) { + return r.mid(idx + 8).trimmed(); + } } } }