From 371cc1a187028f1f9475f490bf29eac7157af275 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 2 Aug 2023 15:17:10 +0200 Subject: [PATCH] Removed communication with ISMAS from git client. --- git/git_client.cpp | 112 ++++++++++++++++++--------------------------- git/git_client.h | 12 ++--- 2 files changed, 49 insertions(+), 75 deletions(-) diff --git a/git/git_client.cpp b/git/git_client.cpp index 92ef124..3c0303e 100644 --- a/git/git_client.cpp +++ b/git/git_client.cpp @@ -1,6 +1,7 @@ #include "git_client.h" #include "update.h" #include "worker.h" +#include "utils.h" #include #include @@ -22,67 +23,6 @@ GitClient::GitClient(QString const &customerNrStr, if (!m_worker) { qCritical() << "ERROR CASTING PARENT TO WORKER FAILED"; } - - connect(this, SIGNAL(ismasUpdatesAvailable()), - this, SLOT(onIsmasUpdatesAvailable()), Qt::QueuedConnection); -} - -void GitClient::onIsmasUpdatesAvailable() { - if (QDir(m_customerRepository).exists()) { - - - qInfo() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST, - QString("FETCHING OF ") + m_repositoryPath + - QString(" INTO ") + m_customerRepository); - - std::optional changes = gitFetch(); - - if (changes) { - std::optional changedFileNames = gitDiff(changes.value()); - if (changedFileNames) { - - qInfo() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS, - QString("FETCHED NEW FILES ") + - changedFileNames.value().join(",") + - QString(" INTO ") + m_customerRepository); - if (gitPull()) { - qInfo() << UpdateStatus(UPDATE_STATUS::GIT_PULL_UPDATES_SUCCESS, - QString("PULL NEW FILES ") + - changedFileNames.value().join(",") + - QString(" INTO ") + m_customerRepository); - - emit m_worker->handleChangedFiles(changedFileNames.value()); - - } else { - qCritical() << UpdateStatus(UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE, - QString("PULLING NEW FILES ") + - changedFileNames.value().join(",") + - QString(" INTO ") + m_customerRepository + " FAILED"); - - emit m_worker->terminateUpdateProcess(); - } - } else { - qCritical() << "NO CHANGES IN" << m_repositoryPath - << "(" << m_customerRepository << ")"; - emit m_worker->finishUpdateProcess(false); - } - } else { - qCritical() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE, - QString("NO CHANGES IN ") + m_repositoryPath + - QString(" (%1)").arg(m_customerRepository)); - - emit m_worker->finishUpdateProcess(false); - } - } else { - if (gitCloneAndCheckoutBranch()) { - qInfo() << "CLONED" << m_repositoryPath - << "AND CHECKED OUT INTO" << m_customerRepository; - } else { - qCritical() << "ERROR CLONING " << m_repositoryPath - << "AND/OR CHECKING OUT INTO" << m_customerRepository; - emit m_worker->terminateUpdateProcess(); - } - } } bool GitClient::gitCloneCustomerRepository() { @@ -128,10 +68,31 @@ bool GitClient::copyGitConfigFromMaster() { // only allowed when called in return false; } -bool GitClient::gitCheckoutBranch() { +QStringList GitClient::gitBranchNames() { + // git config --global pager.branch false + QStringList bNames; if (QDir(m_customerRepository).exists()) { + QString gitCommand("git branch -a"); + Command c(gitCommand); + if (c.execute(m_customerRepository)) { + QString const result = c.getCommandResult(); + return result.split('\n'); + } + } + return bNames; +} + +bool GitClient::gitCheckoutBranch() { + // TODO: nachsehen, ob der Branch ueberhaupt existiert + + if (QDir(m_customerRepository).exists()) { + int zoneNr = Utils::read1stLineOfFile("/etc/zone_nr"); + m_branchName = (zoneNr != 0) + ? QString("zg1/zone%1").arg(zoneNr) : "master"; + QString gitCommand("git checkout "); gitCommand += m_branchName; + Command c(gitCommand); return c.execute(m_customerRepository); // execute command in customerRepo } @@ -146,11 +107,13 @@ bool GitClient::gitCloneAndCheckoutBranch() { if (gitCheckoutBranch()) { return true; } else { - m_worker->terminateUpdateProcess(); + // TODO + // m_worker->terminateUpdateProcess(); } //} } else { - m_worker->terminateUpdateProcess(); + // TODO + //m_worker->terminateUpdateProcess(); } return false; } @@ -201,12 +164,18 @@ std::optional GitClient::gitDiff(QString const &commits) { */ std::optional GitClient::gitFetch() { if (QDir(m_customerRepository).exists()) { + + // TODO + 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"); if (c.execute(m_customerRepository)) { QString const s = c.getCommandResult().trimmed(); - - qCritical() << "GIT RESULT" << s; - if (!s.isEmpty()) { QStringList lines = Update::split(s, '\n'); if (!lines.empty()) { @@ -215,6 +184,15 @@ std::optional GitClient::gitFetch() { QRegularExpressionMatch match = re.match(lines.last()); if (match.hasMatch()) { 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); } else { qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount(); diff --git a/git/git_client.h b/git/git_client.h index cb1f3a5..7da27c4 100644 --- a/git/git_client.h +++ b/git/git_client.h @@ -2,9 +2,11 @@ #define GIT_CLIENT_H_INCLUDED #include +#include #include #include "process/command.h" +#include "ismas/ismas_client.h" class Worker; class GitClient : public QObject { @@ -14,7 +16,7 @@ class GitClient : public QObject { QString const m_repositoryPath; QString const m_customerNr; QString const m_workingDirectory; - QString const m_branchName; + QString m_branchName; QString const m_customerRepository; bool copyGitConfigFromMaster(); @@ -28,6 +30,7 @@ class GitClient : public QObject { bool gitCloneCustomerRepository(); bool gitCheckoutBranch(); + QStringList gitBranchNames(); QString const workingDirectory() const { return m_workingDirectory; } QString workingDirectory() { return m_workingDirectory; } @@ -50,13 +53,6 @@ class GitClient : public QObject { QString gitBlob(QString fileName); QString gitCommitForBlob(QString blob); bool gitIsFileTracked(QString file2name); - -signals: - void ismasUpdatesAvailable(); - -public slots: - void onIsmasUpdatesAvailable(); - }; #endif // GIT_CLIENT_H_INCLUDED