Fix for the case when several branches are edited: 'git fetch' will

display several lines then, not only one.
This commit is contained in:
Gerhard Hoffmann 2023-08-04 13:35:42 +02:00
parent c62299aa72
commit f88b0edb2a

View File

@ -165,13 +165,7 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
std::optional<QString> GitClient::gitFetch() { std::optional<QString> GitClient::gitFetch() {
if (QDir(m_customerRepository).exists()) { if (QDir(m_customerRepository).exists()) {
// TODO qCritical() << "BRANCH NAME" << m_branchName;
UpdateStatus status (UPDATE_STATUS::GIT_FETCH_UPDATES, "GIT FETCH UPDATES");
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT FETCH UPDATES", status.m_statusDescription));
Command c("git fetch"); Command c("git fetch");
if (c.execute(m_customerRepository)) { if (c.execute(m_customerRepository)) {
@ -179,36 +173,51 @@ std::optional<QString> GitClient::gitFetch() {
if (!s.isEmpty()) { if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
if (!lines.empty()) { if (!lines.empty()) {
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
QRegularExpressionMatch match = re.match(lines.last()); // lines can look like this:
if (match.hasMatch()) { // From https://git.mimbach49.de/GerhardHoffmann/customer_281
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches // 41ec581..5d25ac3 master -> origin/master
// TODO // ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
status = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS, // 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
QString("GIT SUCCESSFULLY FETCHED ") + m_customerRepository); // 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
qInfo() << status; // 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
bool found = false;
//emit m_worker->sendCmdEventToIsmas( for (int i=0; i < lines.size(); ++i) {
// m_worker->getIsmasClient().updateOfPSAContinues( if (lines.at(i).contains(m_branchName)) {
// "GIT_FETCH_UPDATES SUCCESS", status.m_statusDescription)); found = true;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
return match.captured(2); static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
} else { QRegularExpressionMatch match = re.match(lines.at(i));
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount(); if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
return match.captured(2);
} else {
emit m_worker->showErrorMessage("git fetch",
QString("(wrong cap-count (%1)").arg(re.captureCount()));
}
} else {
emit m_worker->showErrorMessage("git fetch",
"regex-match for commits");
}
} }
} else { }
qCritical() << "ERROR NO MATCH OF COMMITS FOR 'GIT FETCH'"; if (!found) {
emit m_worker->showErrorMessage("git fetch",
QString("unkown branch name ") + m_branchName);
} }
} else { } else {
qCritical() << "ERROR WRONG FORMAT FOR RESULT FOR 'GIT FETCH'" << s; emit m_worker->showErrorMessage("git fetch",
QString("wrong format for result of 'git fetch' ") + s);
} }
} else { } else {
qCritical() << "ERROR EMPTY RESULT FROM 'GIT FETCH'"; emit m_worker->showErrorMessage("git fetch",
"empty result for 'git fetch'");
} }
} }
} else { } else {
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST"; emit m_worker->showErrorMessage("git fetch",
QString("repository ") + m_customerRepository + " does not exist");
} }
return std::nullopt; return std::nullopt;
} }