From ad93e536f03b760625e0897d1761be400a485bda Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 16 Aug 2023 10:33:08 +0200 Subject: [PATCH] Added gitShowReason(): get lastCommit, message and date of last commit to insert inti sendLastVersion-message to ISMAS. --- git/git_client.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ git/git_client.h | 1 + 2 files changed, 42 insertions(+) diff --git a/git/git_client.cpp b/git/git_client.cpp index 78defa4..35475f2 100644 --- a/git/git_client.cpp +++ b/git/git_client.cpp @@ -114,6 +114,47 @@ bool GitClient::gitCloneAndCheckoutBranch() { return false; } +QStringList GitClient::gitShowReason() { + QStringList lst; + if (QDir(m_customerRepository).exists()) { + // %h: commit (short form) + // %s: commit message + // %cI: commit date, strict ISO 8601 format + Command c("git show -s --format=\"c=%h m=%s d=%cI\""); + if (c.execute(m_customerRepository)) { + QString const s = c.getCommandResult().trimmed(); + int const c = s.indexOf("c="); + int const m = s.indexOf("m="); + int const d = s.indexOf("d="); + QString commit{""}, msg{""}, date{""}; + if (c != -1) { + int start = c + 2; + if (m >= start) { + int length = m - start; + commit = s.mid(start, length).trimmed(); + + start = m + 2; + if (d >= start) { + length = d - start; + msg = s.mid(start, length).trimmed(); + + start = d + 2; + date = s.mid(start); + } + } + + if (!commit.isEmpty() && !msg.isEmpty() && !date.isEmpty()) { + lst << commit << msg << date; + } + } + } + } else { + qCritical() << "CUSTOMER_REPOSITORY" << m_customerRepository + << "DOES NOT EXIST"; + } + return lst; +} + /* Zu beachten: wird eine datei neu hinzugefuegt (git add/commit) dann aber gleich wieder geloscht, so wird sie im diff nicht angezeigt. diff --git a/git/git_client.h b/git/git_client.h index 7da27c4..0faca95 100644 --- a/git/git_client.h +++ b/git/git_client.h @@ -50,6 +50,7 @@ class GitClient : public QObject { std::optional gitMerge(); QString gitLastCommit(QString fileName); + QStringList gitShowReason(); QString gitBlob(QString fileName); QString gitCommitForBlob(QString blob); bool gitIsFileTracked(QString file2name);