checkin for saving current state
This commit is contained in:
96
Git/git_command.cpp
Normal file
96
Git/git_command.cpp
Normal file
@@ -0,0 +1,96 @@
|
||||
#include "git_command.h"
|
||||
|
||||
#include "command.h"
|
||||
#include "utils_internal.h"
|
||||
using namespace internal;
|
||||
|
||||
#include <QProcess>
|
||||
#include <QByteArray>
|
||||
#include <QFileInfo>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
|
||||
bool GitCommand::initEnv = false;
|
||||
static bool initEnv() {
|
||||
QString gitSSHCommand{""};
|
||||
QByteArray const v = qgetenv("GIT_SSH_COMMAND");
|
||||
if (v.isEmpty()) {
|
||||
QString sshKeyFile("/opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig");
|
||||
if (QFileInfo(sshKeyFile).exists()) {
|
||||
if (qgetenv("GIT_SSH_COMMAND").isNull()) {
|
||||
gitSSHCommand = "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig";
|
||||
if (!qputenv("GIT_SSH_COMMAND", QByteArray(gitSSHCommand.toStdString().c_str()))) {
|
||||
qCritical() << "ERROR: GIT_SSH_COMMAND not put into env. Exiting...";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
qCritical() << "ERROR ssh-key-file" << sshKeyFile << "does not exists. Exiting...";
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
gitSSHCommand = QString(v.toStdString().c_str());
|
||||
qCritical() << "WARNING GIT_SSH_COMMAND already set in enviroment:"
|
||||
<< gitSSHCommand;
|
||||
if (gitSSHCommand != "ssh -i /opt/app/tools/atbupdate/.keys/id_ed25519_ptuConfig") {
|
||||
qCritical() << "ERROR" << gitSSHCommand << "wrong. Exiting...";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// qCritical() << __func__ << ":" << __LINE__ << gitSSHCommand;
|
||||
return true;
|
||||
}
|
||||
|
||||
GitCommand::GitCommand()
|
||||
: m_workingDirectory(customerRepoDir()) {
|
||||
// qCritical() << __func__ << ":" << __LINE__ << m_workingDirectory;
|
||||
if (!GitCommand::initEnv) {
|
||||
GitCommand::initEnv = ::initEnv();
|
||||
}
|
||||
}
|
||||
|
||||
bool GitCommand::exec(QStringList const &options, int start_timeout, int finish_timeout) {
|
||||
if (GitCommand::initEnv) {
|
||||
Command cmd(QString("git"), options, m_workingDirectory,
|
||||
start_timeout, finish_timeout);
|
||||
return cmd.exec();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool GitCommand::check(int start_timeout, int finish_timeout) {
|
||||
QStringList const lst{"fsck"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
||||
bool GitCommand::checkout(int start_timeout, int finish_timeout) {
|
||||
int const zoneNr = read1stLineOfFile("/mnt/system_data/zone_nr");
|
||||
if (zoneNr != -1) {
|
||||
QStringList const lst{"checkout", QString("zg1/zone%1").arg(zoneNr)};
|
||||
// qCritical() << __func__ << __LINE__ << lst;
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool GitCommand::clone(int start_timeout, int finish_timeout) {
|
||||
m_workingDirectory = customerRepoRoot(); // /opt/app/tools/atbupdate !
|
||||
QDir const repoDir{customerRepoDir()};
|
||||
if (repoDir.exists() && repoDir.entryInfoList(QDir::NoDotAndDotDot|QDir::AllEntries).count() != 0) {
|
||||
qCritical() << "clone error:" << repoDir << "exists and is not empty";
|
||||
return false;
|
||||
}
|
||||
// git clone "gitea@ptu-config.atb-comm.de:ATB/customer_999"
|
||||
QStringList const lst{"clone", repositoryUrl() + customerRepoDirName()};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
||||
bool GitCommand::pull(int start_timeout, int finish_timeout) {
|
||||
QStringList const lst{"pull"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
||||
|
||||
bool GitCommand::status(int start_timeout, int finish_timeout) {
|
||||
QStringList const lst{"status"};
|
||||
return exec(lst, start_timeout, finish_timeout);
|
||||
}
|
Reference in New Issue
Block a user