Added gitShowReason(): get lastCommit, message and date of last commit to insert inti

sendLastVersion-message to ISMAS.
This commit is contained in:
Gerhard Hoffmann 2023-08-16 10:33:08 +02:00
parent 259da8200e
commit ad93e536f0
2 changed files with 42 additions and 0 deletions

View File

@ -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.

View File

@ -50,6 +50,7 @@ class GitClient : public QObject {
std::optional<QStringList> gitMerge();
QString gitLastCommit(QString fileName);
QStringList gitShowReason();
QString gitBlob(QString fileName);
QString gitCommitForBlob(QString blob);
bool gitIsFileTracked(QString file2name);