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()) {
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
// lines can look like this:
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
// 41ec581..5d25ac3 master -> origin/master
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
bool found = false;
for (int i=0; i < lines.size(); ++i) {
if (lines.at(i).contains(m_branchName)) {
found = true;
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1 // 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)"); static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
QRegularExpressionMatch match = re.match(lines.last()); QRegularExpressionMatch match = re.match(lines.at(i));
if (match.hasMatch()) { if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
// TODO
status = UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString("GIT SUCCESSFULLY FETCHED ") + m_customerRepository);
qInfo() << status;
//emit m_worker->sendCmdEventToIsmas(
// m_worker->getIsmasClient().updateOfPSAContinues(
// "GIT_FETCH_UPDATES SUCCESS", status.m_statusDescription));
return match.captured(2); return match.captured(2);
} else { } else {
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount(); emit m_worker->showErrorMessage("git fetch",
QString("(wrong cap-count (%1)").arg(re.captureCount()));
} }
} else { } else {
qCritical() << "ERROR NO MATCH OF COMMITS FOR 'GIT FETCH'"; emit m_worker->showErrorMessage("git fetch",
"regex-match for commits");
}
}
}
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;
} }