Removed communication with ISMAS from git client.
This commit is contained in:
parent
a94606ca89
commit
371cc1a187
@ -1,6 +1,7 @@
|
|||||||
#include "git_client.h"
|
#include "git_client.h"
|
||||||
#include "update.h"
|
#include "update.h"
|
||||||
#include "worker.h"
|
#include "worker.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
@ -22,67 +23,6 @@ GitClient::GitClient(QString const &customerNrStr,
|
|||||||
if (!m_worker) {
|
if (!m_worker) {
|
||||||
qCritical() << "ERROR CASTING PARENT TO WORKER FAILED";
|
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<QString> changes = gitFetch();
|
|
||||||
|
|
||||||
if (changes) {
|
|
||||||
std::optional<QStringList> 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() {
|
bool GitClient::gitCloneCustomerRepository() {
|
||||||
@ -128,10 +68,31 @@ bool GitClient::copyGitConfigFromMaster() { // only allowed when called in
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GitClient::gitCheckoutBranch() {
|
QStringList GitClient::gitBranchNames() {
|
||||||
|
// git config --global pager.branch false
|
||||||
|
QStringList bNames;
|
||||||
if (QDir(m_customerRepository).exists()) {
|
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 ");
|
QString gitCommand("git checkout ");
|
||||||
gitCommand += m_branchName;
|
gitCommand += m_branchName;
|
||||||
|
|
||||||
Command c(gitCommand);
|
Command c(gitCommand);
|
||||||
return c.execute(m_customerRepository); // execute command in customerRepo
|
return c.execute(m_customerRepository); // execute command in customerRepo
|
||||||
}
|
}
|
||||||
@ -146,11 +107,13 @@ bool GitClient::gitCloneAndCheckoutBranch() {
|
|||||||
if (gitCheckoutBranch()) {
|
if (gitCheckoutBranch()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
m_worker->terminateUpdateProcess();
|
// TODO
|
||||||
|
// m_worker->terminateUpdateProcess();
|
||||||
}
|
}
|
||||||
//}
|
//}
|
||||||
} else {
|
} else {
|
||||||
m_worker->terminateUpdateProcess();
|
// TODO
|
||||||
|
//m_worker->terminateUpdateProcess();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -201,12 +164,18 @@ 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
|
||||||
|
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)) {
|
||||||
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()) {
|
||||||
@ -215,6 +184,15 @@ std::optional<QString> GitClient::gitFetch() {
|
|||||||
QRegularExpressionMatch match = re.match(lines.last());
|
QRegularExpressionMatch match = re.match(lines.last());
|
||||||
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();
|
qCritical() << "ERROR WRONG CAPTURE COUNT FOR 'GIT FETCH'" << re.captureCount();
|
||||||
|
@ -2,9 +2,11 @@
|
|||||||
#define GIT_CLIENT_H_INCLUDED
|
#define GIT_CLIENT_H_INCLUDED
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QStringList>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
#include "process/command.h"
|
#include "process/command.h"
|
||||||
|
#include "ismas/ismas_client.h"
|
||||||
|
|
||||||
class Worker;
|
class Worker;
|
||||||
class GitClient : public QObject {
|
class GitClient : public QObject {
|
||||||
@ -14,7 +16,7 @@ class GitClient : public QObject {
|
|||||||
QString const m_repositoryPath;
|
QString const m_repositoryPath;
|
||||||
QString const m_customerNr;
|
QString const m_customerNr;
|
||||||
QString const m_workingDirectory;
|
QString const m_workingDirectory;
|
||||||
QString const m_branchName;
|
QString m_branchName;
|
||||||
QString const m_customerRepository;
|
QString const m_customerRepository;
|
||||||
|
|
||||||
bool copyGitConfigFromMaster();
|
bool copyGitConfigFromMaster();
|
||||||
@ -28,6 +30,7 @@ class GitClient : public QObject {
|
|||||||
|
|
||||||
bool gitCloneCustomerRepository();
|
bool gitCloneCustomerRepository();
|
||||||
bool gitCheckoutBranch();
|
bool gitCheckoutBranch();
|
||||||
|
QStringList gitBranchNames();
|
||||||
|
|
||||||
QString const workingDirectory() const { return m_workingDirectory; }
|
QString const workingDirectory() const { return m_workingDirectory; }
|
||||||
QString workingDirectory() { return m_workingDirectory; }
|
QString workingDirectory() { return m_workingDirectory; }
|
||||||
@ -50,13 +53,6 @@ class GitClient : public QObject {
|
|||||||
QString gitBlob(QString fileName);
|
QString gitBlob(QString fileName);
|
||||||
QString gitCommitForBlob(QString blob);
|
QString gitCommitForBlob(QString blob);
|
||||||
bool gitIsFileTracked(QString file2name);
|
bool gitIsFileTracked(QString file2name);
|
||||||
|
|
||||||
signals:
|
|
||||||
void ismasUpdatesAvailable();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void onIsmasUpdatesAvailable();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GIT_CLIENT_H_INCLUDED
|
#endif // GIT_CLIENT_H_INCLUDED
|
||||||
|
Loading…
Reference in New Issue
Block a user