Simplified interface.

When doing a clone of the repository, do not execute any other commands.
This commit is contained in:
Gerhard Hoffmann 2023-07-17 16:49:44 +02:00
parent 5eb33f3e31
commit 37c5c7c4f6

View File

@ -7,20 +7,18 @@
#include <QDir>
GitClient::GitClient(QString const &repositoryPath,
QString const &customerId,
GitClient::GitClient(QString const &customerNrStr,
QString const &customerRepository,
QString const &workingDirectory,
QString const &branchName,
QObject *parent)
: QObject(parent)
, m_worker(qobject_cast<Worker *>(parent))
, m_repositoryPath(repositoryPath)
, m_customerId(customerId)
, m_repositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(customerNrStr))
, m_customerNr(customerNrStr)
, m_workingDirectory(workingDirectory)
, m_branchName(branchName)
, m_customerRepository(QDir::cleanPath(m_workingDirectory
+ QDir::separator()
+ m_customerId)) {
, m_customerRepository(customerRepository) {
if (!m_worker) {
qCritical() << "ERROR CASTING PARENT TO WORKER FAILED";
}
@ -63,18 +61,6 @@ void GitClient::onIsmasUpdatesAvailable() {
if (gitCloneAndCheckoutBranch()) {
qInfo() << "CLONED" << m_repositoryPath
<< "AND CHECKED OUT INTO" << m_customerRepository;
if (m_worker) {
qDebug() << "WORKER EXECUTE OPKG COMMANDS";
QStringList opkgCommands;
// To make sure that opkg upgrade does not break your system
// because of an unstable connection
// Add a line "option cache cachedir" to /etc/opkg/opkg.conf to
// avoid the --cache option on command line.
opkgCommands << "opkg update";
//opkgCommands << "opkg --cache cachedir --download-only upgrade";
//opkgCommands << "opkg --cache cachedir upgrade";
emit m_worker->executeOpkgCommands(opkgCommands);
}
} else {
qCritical() << "ERROR CLONING " << m_repositoryPath
<< "AND/OR CHECKING OUT INTO" << m_customerRepository;
@ -99,7 +85,7 @@ bool GitClient::gitCloneCustomerRepository() {
QRegularExpressionMatch match = re.match(result);
if (match.hasMatch()) {
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
if (match.captured(2).trimmed() == m_customerId) {
if (match.captured(2).trimmed() == m_customerNr) {
qInfo() << "CLONING" << m_repositoryPath << "OK";
return true;
}
@ -112,7 +98,7 @@ bool GitClient::gitCloneCustomerRepository() {
}
bool GitClient::copyGitConfigFromMaster() { // only allowed when called in
// master branch
// master branch (???)
if (QDir(m_customerRepository).exists()) {
QString const cp = QString("cp .gitconfig .git/config");
Command c("bash");
@ -139,9 +125,9 @@ bool GitClient::gitCheckoutBranch() {
bool GitClient::gitCloneAndCheckoutBranch() {
qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT" << m_branchName;
if (gitCloneCustomerRepository()) {
if (copyGitConfigFromMaster()) {
//if (copyGitConfigFromMaster()) {
return gitCheckoutBranch();
}
//}
}
return false;
}
@ -191,11 +177,9 @@ std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
*/
std::optional<QString> GitClient::gitFetch() {
QString const &customerRepository
= QDir::cleanPath(m_workingDirectory + QDir::separator() + m_customerId);
if (QDir(customerRepository).exists()) {
if (QDir(m_customerRepository).exists()) {
Command c("git fetch");
if (c.execute(customerRepository)) {
if (c.execute(m_customerRepository)) {
QString const s = c.getCommandResult().trimmed();
if (!s.isEmpty()) {
QStringList lines = Update::split(s, '\n');
@ -220,7 +204,7 @@ std::optional<QString> GitClient::gitFetch() {
}
}
} else {
qCritical() << "ERROR" << customerRepository << "DOES NOT EXIST";
qCritical() << "ERROR" << m_customerRepository << "DOES NOT EXIST";
}
return std::nullopt;
}