From 1bdae56342cd189c2e979e801f3c2fbae38a67e9 Mon Sep 17 00:00:00 2001 From: Gerhard Hoffmann Date: Wed, 19 Jul 2023 16:50:54 +0200 Subject: [PATCH] Added debug messages. Fixed gitBlob(): do not check for existing customer repository. --- git/git_client.cpp | 68 +++++++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 22 deletions(-) diff --git a/git/git_client.cpp b/git/git_client.cpp index a723455..92ef124 100644 --- a/git/git_client.cpp +++ b/git/git_client.cpp @@ -29,22 +29,36 @@ GitClient::GitClient(QString const &customerNrStr, void GitClient::onIsmasUpdatesAvailable() { if (QDir(m_customerRepository).exists()) { - qInfo() << "FETCHING OF" << m_repositoryPath - << "INTO" << m_customerRepository; + + + 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) { - for (int i=0;ihandleChangedFiles(changedFileNames.value()); + } else { - qCritical() << "PULL FAILED FOR" << m_repositoryPath - << "IN " << m_customerRepository; + 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 { @@ -53,8 +67,10 @@ void GitClient::onIsmasUpdatesAvailable() { emit m_worker->finishUpdateProcess(false); } } else { - qCritical() << "NO CHANGES IN" << m_repositoryPath - << "(" << m_customerRepository << ")"; + 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 { @@ -78,7 +94,7 @@ bool GitClient::gitCloneCustomerRepository() { << "CLONE" << m_repositoryPath << "..."; if (c.execute(m_workingDirectory)) { // execute the command in wd - QString result = c.getCommandResult(); + QString const result = c.getCommandResult(); if (!result.isEmpty()) { // Cloning into 'customer_281'...\n static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)"); @@ -91,8 +107,9 @@ bool GitClient::gitCloneCustomerRepository() { } } } - qCritical() << "ERROR CLONE RESULT HAS WRONG FORMAT"; } + qCritical() << "ERROR CLONE RESULT HAS WRONG FORMAT. CLONE_RESULT=" + << result; } return false; } @@ -126,8 +143,14 @@ bool GitClient::gitCloneAndCheckoutBranch() { qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT" << m_branchName; if (gitCloneCustomerRepository()) { //if (copyGitConfigFromMaster()) { - return gitCheckoutBranch(); + if (gitCheckoutBranch()) { + return true; + } else { + m_worker->terminateUpdateProcess(); + } //} + } else { + m_worker->terminateUpdateProcess(); } return false; } @@ -181,6 +204,9 @@ std::optional GitClient::gitFetch() { 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()) { @@ -257,19 +283,17 @@ QString GitClient::gitLastCommit(QString fileName) { return ""; } -// get the blob of the file(name) passed as $1 -// note: this can be used for any file in the filesystem +// fileName has to an absolute path QString GitClient::gitBlob(QString fileName) { - if (QDir(m_customerRepository).exists()) { - QString const filePath - = QDir::cleanPath(m_customerRepository + QDir::separator() + fileName); + QFileInfo fi(fileName); + if (fi.exists()) { QString const gitCommand = QString("git hash-object %1").arg(fileName); Command c(gitCommand); - if (c.execute(m_customerRepository)) { - return c.getCommandResult(); + if (c.execute(m_workingDirectory)) { + return c.getCommandResult().trimmed(); } } - return ""; + return "N/A"; } QString GitClient::gitCommitForBlob(QString blob) {