Added debug messages.

Fixed gitBlob(): do not check for existing customer repository.
This commit is contained in:
Gerhard Hoffmann 2023-07-19 16:50:54 +02:00
parent 6caaae6d50
commit 1bdae56342

View File

@ -29,22 +29,36 @@ GitClient::GitClient(QString const &customerNrStr,
void GitClient::onIsmasUpdatesAvailable() { void GitClient::onIsmasUpdatesAvailable() {
if (QDir(m_customerRepository).exists()) { 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<QString> changes = gitFetch(); std::optional<QString> changes = gitFetch();
if (changes) { if (changes) {
std::optional<QStringList> changedFileNames = gitDiff(changes.value()); std::optional<QStringList> changedFileNames = gitDiff(changes.value());
if (changedFileNames) { if (changedFileNames) {
for (int i=0;i<changedFileNames.value().size();++i) {
QString fname = changedFileNames.value().at(i); qInfo() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_SUCCESS,
QString lastCommit = gitLastCommit(fname); QString("FETCHED NEW FILES ") +
qDebug() << "CCCC" << changedFileNames.value().at(i) << lastCommit; changedFileNames.value().join(",") +
} QString(" INTO ") + m_customerRepository);
if (gitPull()) { 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()); emit m_worker->handleChangedFiles(changedFileNames.value());
} else { } else {
qCritical() << "PULL FAILED FOR" << m_repositoryPath qCritical() << UpdateStatus(UPDATE_STATUS::GIT_PULL_UPDATES_FAILURE,
<< "IN " << m_customerRepository; QString("PULLING NEW FILES ") +
changedFileNames.value().join(",") +
QString(" INTO ") + m_customerRepository + " FAILED");
emit m_worker->terminateUpdateProcess(); emit m_worker->terminateUpdateProcess();
} }
} else { } else {
@ -53,8 +67,10 @@ void GitClient::onIsmasUpdatesAvailable() {
emit m_worker->finishUpdateProcess(false); emit m_worker->finishUpdateProcess(false);
} }
} else { } else {
qCritical() << "NO CHANGES IN" << m_repositoryPath qCritical() << UpdateStatus(UPDATE_STATUS::GIT_FETCH_UPDATES_REQUEST_FAILURE,
<< "(" << m_customerRepository << ")"; QString("NO CHANGES IN ") + m_repositoryPath +
QString(" (%1)").arg(m_customerRepository));
emit m_worker->finishUpdateProcess(false); emit m_worker->finishUpdateProcess(false);
} }
} else { } else {
@ -78,7 +94,7 @@ bool GitClient::gitCloneCustomerRepository() {
<< "CLONE" << m_repositoryPath << "..."; << "CLONE" << m_repositoryPath << "...";
if (c.execute(m_workingDirectory)) { // execute the command in wd if (c.execute(m_workingDirectory)) { // execute the command in wd
QString result = c.getCommandResult(); QString const result = c.getCommandResult();
if (!result.isEmpty()) { if (!result.isEmpty()) {
// Cloning into 'customer_281'...\n // Cloning into 'customer_281'...\n
static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)"); 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; return false;
} }
@ -126,8 +143,14 @@ bool GitClient::gitCloneAndCheckoutBranch() {
qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT" << m_branchName; qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT" << m_branchName;
if (gitCloneCustomerRepository()) { if (gitCloneCustomerRepository()) {
//if (copyGitConfigFromMaster()) { //if (copyGitConfigFromMaster()) {
return gitCheckoutBranch(); if (gitCheckoutBranch()) {
return true;
} else {
m_worker->terminateUpdateProcess();
}
//} //}
} else {
m_worker->terminateUpdateProcess();
} }
return false; return false;
} }
@ -181,6 +204,9 @@ std::optional<QString> GitClient::gitFetch() {
Command c("git fetch"); Command c("git fetch");
if (c.execute(m_customerRepository)) { if (c.execute(m_customerRepository)) {
QString const s = c.getCommandResult().trimmed(); QString const s = c.getCommandResult().trimmed();
qCritical() << "GIT RESULT" << s;
if (!s.isEmpty()) { if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n'); QStringList lines = Update::split(s, '\n');
if (!lines.empty()) { if (!lines.empty()) {
@ -257,19 +283,17 @@ QString GitClient::gitLastCommit(QString fileName) {
return ""; return "";
} }
// get the blob of the file(name) passed as $1 // fileName has to an absolute path
// note: this can be used for any file in the filesystem
QString GitClient::gitBlob(QString fileName) { QString GitClient::gitBlob(QString fileName) {
if (QDir(m_customerRepository).exists()) { QFileInfo fi(fileName);
QString const filePath if (fi.exists()) {
= QDir::cleanPath(m_customerRepository + QDir::separator() + fileName);
QString const gitCommand = QString("git hash-object %1").arg(fileName); QString const gitCommand = QString("git hash-object %1").arg(fileName);
Command c(gitCommand); Command c(gitCommand);
if (c.execute(m_customerRepository)) { if (c.execute(m_workingDirectory)) {
return c.getCommandResult(); return c.getCommandResult().trimmed();
} }
} }
return ""; return "N/A";
} }
QString GitClient::gitCommitForBlob(QString blob) { QString GitClient::gitCommitForBlob(QString blob) {