2023-07-10 15:57:17 +02:00
|
|
|
#include "git_client.h"
|
|
|
|
#include "update.h"
|
2023-07-14 13:16:01 +02:00
|
|
|
#include "worker.h"
|
2023-08-02 15:17:10 +02:00
|
|
|
#include "utils.h"
|
2023-07-10 15:57:17 +02:00
|
|
|
|
|
|
|
#include <QRegularExpression>
|
|
|
|
#include <QDebug>
|
|
|
|
#include <QDir>
|
|
|
|
|
|
|
|
|
2023-07-17 16:49:44 +02:00
|
|
|
GitClient::GitClient(QString const &customerNrStr,
|
|
|
|
QString const &customerRepository,
|
2023-07-14 13:16:01 +02:00
|
|
|
QString const &workingDirectory,
|
|
|
|
QString const &branchName,
|
|
|
|
QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, m_worker(qobject_cast<Worker *>(parent))
|
2023-07-17 16:49:44 +02:00
|
|
|
, m_repositoryPath(QString("https://git.mimbach49.de/GerhardHoffmann/%1.git").arg(customerNrStr))
|
|
|
|
, m_customerNr(customerNrStr)
|
2023-07-14 13:16:01 +02:00
|
|
|
, m_workingDirectory(workingDirectory)
|
|
|
|
, m_branchName(branchName)
|
2023-07-17 16:49:44 +02:00
|
|
|
, m_customerRepository(customerRepository) {
|
2023-07-14 13:16:01 +02:00
|
|
|
if (!m_worker) {
|
|
|
|
qCritical() << "ERROR CASTING PARENT TO WORKER FAILED";
|
|
|
|
}
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
bool GitClient::gitCloneCustomerRepository() {
|
2023-10-18 11:36:13 +02:00
|
|
|
/* Blobless clone
|
|
|
|
==============
|
|
|
|
|
|
|
|
When using the --filter=blob:none option, the initial git clone will
|
|
|
|
download all reachable commits and trees, and only download the blobs
|
|
|
|
for commits when you do a git checkout. This includes the first checkout
|
|
|
|
inside the git clone operation.
|
|
|
|
|
|
|
|
The important thing to notice is that we have a copy of every blob at
|
|
|
|
HEAD but the blobs in the history are not present. If your repository
|
|
|
|
has a deep history full of large blobs, then this option can
|
|
|
|
significantly reduce your git clone times. The commit and tree data is
|
|
|
|
still present, so any subsequent git checkout only needs to download
|
|
|
|
the missing blobs. The Git client knows how to batch these requests to
|
|
|
|
ask the server only for the missing blobs.
|
|
|
|
|
|
|
|
Further, when running git fetch in a blobless clone, the server only
|
|
|
|
sends the new commits and trees. The new blobs are downloaded only
|
|
|
|
after a git checkout. Note that git pull runs git fetch and then git
|
|
|
|
merge, so it will download the necessary blobs during the git merge
|
|
|
|
command.
|
|
|
|
|
|
|
|
When using a blobless clone, you will trigger a blob download whenever
|
|
|
|
you need the contents of a file, but you will not need one if you only
|
|
|
|
need the OID (object-id) of a file. This means that git log can detect
|
|
|
|
which commits changed a given path without needing to download extra
|
|
|
|
data.
|
|
|
|
|
|
|
|
This means that blobless clones can perform commands like git
|
|
|
|
merge-base, git log, or even git log -- <path> with the same performance
|
|
|
|
as a full clone.
|
|
|
|
|
|
|
|
Commands like git diff or git blame <path> require the contents of the
|
|
|
|
paths to compute diffs, so these will trigger blob downloads the first
|
|
|
|
time they are run. However, the good news is that after that you will
|
|
|
|
have those blobs in your repository and do not need to download them a
|
|
|
|
second time. Most developers only need to run git blame on a small
|
|
|
|
number of files, so this tradeoff of a slightly slower git blame command
|
|
|
|
is worth the faster clone and fetch times.
|
|
|
|
|
|
|
|
Note: git v2.18 does not support treeless clones: --filter=tree:0.
|
|
|
|
*/
|
|
|
|
QString gitCommand("git clone --filter=blob:none ");
|
2023-07-14 13:16:01 +02:00
|
|
|
gitCommand += m_repositoryPath;
|
2023-07-10 15:57:17 +02:00
|
|
|
Command c(gitCommand);
|
2023-07-14 13:16:01 +02:00
|
|
|
|
|
|
|
qInfo() << "IN CURRENT WD" << m_workingDirectory
|
2023-10-18 11:36:13 +02:00
|
|
|
<< "CLONE VIA COMMAND" << gitCommand;
|
2023-07-14 13:16:01 +02:00
|
|
|
|
|
|
|
if (c.execute(m_workingDirectory)) { // execute the command in wd
|
2023-07-19 16:50:54 +02:00
|
|
|
QString const result = c.getCommandResult();
|
2023-07-10 15:57:17 +02:00
|
|
|
if (!result.isEmpty()) {
|
|
|
|
// Cloning into 'customer_281'...\n
|
|
|
|
static QRegularExpression re("(^\\s*Cloning\\s+into\\s+[']\\s*)(.*)(\\s*['].*$)");
|
|
|
|
QRegularExpressionMatch match = re.match(result);
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
2023-10-18 16:19:37 +02:00
|
|
|
QString const &customerNr = match.captured(2).trimmed();
|
|
|
|
if (customerNr == m_customerNr) {
|
2023-07-14 13:16:01 +02:00
|
|
|
qInfo() << "CLONING" << m_repositoryPath << "OK";
|
|
|
|
return true;
|
|
|
|
}
|
2023-10-18 16:19:37 +02:00
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString("ERROR CLONE RESULT HAS WRONG CUSTOMER-NR. rcc=%1 customer=%2 CLONE_RESULT=%3")
|
|
|
|
.arg(re.captureCount())
|
|
|
|
.arg(customerNr)
|
|
|
|
.arg(result));
|
|
|
|
return false;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
2023-10-18 11:36:13 +02:00
|
|
|
Utils::printCriticalErrorMsg(
|
|
|
|
QString("ERROR CLONE RESULT HAS WRONG FORMAT. rcc=%1 CLONE_RESULT=%2")
|
|
|
|
.arg(re.captureCount())
|
|
|
|
.arg(result));
|
|
|
|
return false;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
2023-10-18 11:36:13 +02:00
|
|
|
Utils::printCriticalErrorMsg("ERROR CLONE RESULT IS EMPTY");
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
return false;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
bool GitClient::copyGitConfigFromMaster() { // only allowed when called in
|
2023-07-17 16:49:44 +02:00
|
|
|
// master branch (???)
|
2023-07-14 13:16:01 +02:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
QString const cp = QString("cp .gitconfig .git/config");
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_customerRepository, QStringList() << "-c" << cp)) {
|
|
|
|
qInfo() << "cp .gitconfig .git/config OK";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
qCritical() << "ERROR cp .gitconfig .git/config";
|
|
|
|
}
|
|
|
|
return false;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
|
2023-08-02 15:17:10 +02:00
|
|
|
QStringList GitClient::gitBranchNames() {
|
|
|
|
// git config --global pager.branch false
|
|
|
|
QStringList bNames;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
bool GitClient::gitCheckoutBranch() {
|
2023-08-02 15:17:10 +02:00
|
|
|
// TODO: nachsehen, ob der Branch ueberhaupt existiert
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
2023-08-04 13:33:25 +02:00
|
|
|
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
|
2023-08-02 15:17:10 +02:00
|
|
|
m_branchName = (zoneNr != 0)
|
|
|
|
? QString("zg1/zone%1").arg(zoneNr) : "master";
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
QString gitCommand("git checkout ");
|
|
|
|
gitCommand += m_branchName;
|
2023-08-02 15:17:10 +02:00
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
Command c(gitCommand);
|
|
|
|
return c.execute(m_customerRepository); // execute command in customerRepo
|
|
|
|
}
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("ERROR ") + m_customerRepository + " DOES NOT EXIST");
|
2023-07-14 13:16:01 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GitClient::gitCloneAndCheckoutBranch() {
|
|
|
|
qInfo() << "CLONE" << m_repositoryPath << "AND CHECKOUT" << m_branchName;
|
|
|
|
if (gitCloneCustomerRepository()) {
|
2023-07-17 16:49:44 +02:00
|
|
|
//if (copyGitConfigFromMaster()) {
|
2023-07-19 16:50:54 +02:00
|
|
|
if (gitCheckoutBranch()) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2023-08-02 15:17:10 +02:00
|
|
|
// TODO
|
2023-07-19 16:50:54 +02:00
|
|
|
}
|
2023-07-17 16:49:44 +02:00
|
|
|
//}
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("CLONE ") + m_repositoryPath + " AND CHECKOUT FAILED");
|
2023-07-14 13:16:01 +02:00
|
|
|
return false;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
|
2023-10-09 15:53:35 +02:00
|
|
|
QStringList GitClient::gitShowReason(QString branchName) {
|
2023-08-16 10:33:08 +02:00
|
|
|
QStringList lst;
|
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
// %h: commit (short form)
|
|
|
|
// %s: commit message
|
|
|
|
// %cI: commit date, strict ISO 8601 format
|
2023-10-09 15:53:35 +02:00
|
|
|
// Note: branch with branchName has to exist: format zg1/zone1
|
|
|
|
Command c(QString("git show origin/%1 -s --format=\"c=%h m=%s d=%cI\"").arg(branchName));
|
2023-08-16 10:33:08 +02:00
|
|
|
if (c.execute(m_customerRepository)) {
|
|
|
|
QString const s = c.getCommandResult().trimmed();
|
|
|
|
int const c = s.indexOf("c=");
|
|
|
|
int const m = s.indexOf("m=");
|
|
|
|
int const d = s.indexOf("d=");
|
2023-09-04 11:46:37 +02:00
|
|
|
|
|
|
|
QString msg = IsmasClient::getReasonForLastSendVersion();
|
|
|
|
QString commit{""}, date{""};
|
|
|
|
|
2023-08-16 10:33:08 +02:00
|
|
|
if (c != -1) {
|
|
|
|
int start = c + 2;
|
|
|
|
if (m >= start) {
|
|
|
|
int length = m - start;
|
|
|
|
commit = s.mid(start, length).trimmed();
|
|
|
|
|
|
|
|
start = m + 2;
|
|
|
|
if (d >= start) {
|
|
|
|
length = d - start;
|
2023-09-04 11:46:37 +02:00
|
|
|
msg += " (";
|
2023-08-16 10:33:08 +02:00
|
|
|
msg = s.mid(start, length).trimmed();
|
2023-09-04 11:46:37 +02:00
|
|
|
msg += ")";
|
2023-08-16 10:33:08 +02:00
|
|
|
|
|
|
|
start = d + 2;
|
|
|
|
date = s.mid(start);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!commit.isEmpty() && !msg.isEmpty() && !date.isEmpty()) {
|
|
|
|
lst << commit << msg << date;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
qCritical() << "CUSTOMER_REPOSITORY" << m_customerRepository
|
|
|
|
<< "DOES NOT EXIST";
|
|
|
|
}
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
/*
|
|
|
|
Zu beachten: wird eine datei neu hinzugefuegt (git add/commit) dann aber gleich
|
|
|
|
wieder geloscht, so wird sie im diff nicht angezeigt.
|
|
|
|
*/
|
2023-07-10 15:57:17 +02:00
|
|
|
std::optional<QStringList> GitClient::gitDiff(QString const &commits) {
|
2023-07-14 13:16:01 +02:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
// 409f198..6c22726
|
|
|
|
QString gitCommand("git diff --compact-summary ");
|
|
|
|
gitCommand += commits;
|
2023-07-10 15:57:17 +02:00
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
Command c(gitCommand);
|
|
|
|
if (c.execute(m_customerRepository)) { // execute command in local customerRepo
|
|
|
|
QString s = c.getCommandResult().trimmed();
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printInfoMsg("GIT DIFF RESULT " + s);
|
2023-08-09 16:12:56 +02:00
|
|
|
|
2023-08-11 11:12:09 +02:00
|
|
|
QStringList lines = Update::split(s, '\n');
|
2023-07-14 13:16:01 +02:00
|
|
|
QStringList fileNames;
|
|
|
|
// each line has the format "etc/psa_config/DC2C_print01.json | 1 +
|
|
|
|
// or the format "etc/psa_config/DC2C_print01.json (new) | 1 +
|
|
|
|
// the filenames are relativ to the repository
|
|
|
|
for (int i = 0; i < lines.size(); ++i) {
|
2023-08-09 16:12:56 +02:00
|
|
|
QString const &line = lines.at(i);
|
|
|
|
int newIndex = line.indexOf("(new"); // for new files
|
|
|
|
int goneIndex = line.indexOf("(gone"); // for removed files
|
|
|
|
int modeIndex = line.indexOf("(mode");
|
2023-08-11 11:12:09 +02:00
|
|
|
int pipeIndex = line.indexOf('|');
|
2023-07-14 13:16:01 +02:00
|
|
|
if (newIndex != -1) {
|
2023-08-09 16:12:56 +02:00
|
|
|
QString file = line.left(newIndex).trimmed();
|
|
|
|
qInfo() << "FILE (NEW)" << file;
|
|
|
|
fileNames << file;
|
|
|
|
} else
|
|
|
|
if (modeIndex != -1) {
|
|
|
|
QString const file = line.left(modeIndex).trimmed();
|
|
|
|
qInfo() << "FILE (MODE)" << file;
|
|
|
|
fileNames << file;
|
|
|
|
} else
|
|
|
|
if (goneIndex != -1) {
|
|
|
|
QString const file = line.left(goneIndex).trimmed();
|
|
|
|
qCritical() << "FILE (GONE)" << file;
|
2023-08-11 11:12:09 +02:00
|
|
|
} else
|
|
|
|
if (pipeIndex != -1) {
|
|
|
|
QString const file = line.left(pipeIndex).trimmed();
|
|
|
|
qInfo() << "FILE (PIPE)" << file;
|
|
|
|
fileNames << file;
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
if (!fileNames.isEmpty()) {
|
|
|
|
return fileNames;
|
|
|
|
}
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
2023-07-14 13:16:01 +02:00
|
|
|
/*
|
|
|
|
Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
|
|
|
|
*/
|
2023-10-18 11:37:46 +02:00
|
|
|
std::optional<QString> GitClient::gitPull() {
|
2023-07-17 16:49:44 +02:00
|
|
|
if (QDir(m_customerRepository).exists()) {
|
2023-08-09 15:03:14 +02:00
|
|
|
qInfo() << "BRANCH NAME" << m_branchName;
|
2023-08-02 15:17:10 +02:00
|
|
|
|
2023-10-18 11:37:46 +02:00
|
|
|
Command c("git pull");
|
2023-07-17 16:49:44 +02:00
|
|
|
if (c.execute(m_customerRepository)) {
|
2023-07-14 13:16:01 +02:00
|
|
|
QString const s = c.getCommandResult().trimmed();
|
|
|
|
if (!s.isEmpty()) {
|
|
|
|
QStringList lines = Update::split(s, '\n');
|
|
|
|
if (!lines.empty()) {
|
2023-08-04 13:35:42 +02:00
|
|
|
int zoneNr = Utils::read1stLineOfFile("/mnt/system_data/zone_nr");
|
|
|
|
m_branchName = (zoneNr != 0) ? QString("zg1/zone%1").arg(zoneNr) : "master";
|
|
|
|
// lines can look like this:
|
|
|
|
// From https://git.mimbach49.de/GerhardHoffmann/customer_281
|
|
|
|
// 41ec581..5d25ac3 master -> origin/master
|
|
|
|
// ff10f57..43530a1 zg1/zone1 -> origin/zg1/zone1
|
|
|
|
// 6ed893f..5d9882c zg1/zone2 -> origin/zg1/zone2
|
|
|
|
// 4384d17..77045d8 zg1/zone3 -> origin/zg1/zone3
|
|
|
|
// 89d2812..36a0d74 zg1/zone5 -> origin/zg1/zone5
|
|
|
|
bool found = false;
|
|
|
|
for (int i=0; i < lines.size(); ++i) {
|
|
|
|
if (lines.at(i).contains(m_branchName)) {
|
|
|
|
found = true;
|
|
|
|
// 409f198..6c22726 zg1/zone1 -> origin/zg1/zone1
|
|
|
|
static QRegularExpression re("(^\\s*)([0-9A-Fa-f]+..[0-9A-Fa-f]+)(.*$)");
|
|
|
|
QRegularExpressionMatch match = re.match(lines.at(i));
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
if (re.captureCount() == 3) { // start with full match (0), then the other 3 matches
|
|
|
|
return match.captured(2);
|
|
|
|
} else {
|
2023-10-18 11:38:26 +02:00
|
|
|
emit m_worker->showErrorMessage("git pull",
|
2023-08-04 13:35:42 +02:00
|
|
|
QString("(wrong cap-count (%1)").arg(re.captureCount()));
|
|
|
|
}
|
|
|
|
} else {
|
2023-10-18 11:38:26 +02:00
|
|
|
emit m_worker->showErrorMessage("git pull",
|
2023-08-09 15:03:14 +02:00
|
|
|
"no regex-match for commits");
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg("NO REGEX MATCH FOR COMMITS");
|
2023-08-04 13:35:42 +02:00
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
}
|
2023-08-04 13:35:42 +02:00
|
|
|
}
|
|
|
|
if (!found) {
|
2023-10-18 11:38:26 +02:00
|
|
|
emit m_worker->showErrorMessage("git pull",
|
2023-08-04 13:35:42 +02:00
|
|
|
QString("unkown branch name ") + m_branchName);
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg("UNKNOWN BRANCH NAME " + m_branchName);
|
2023-07-14 13:16:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2023-10-18 11:38:26 +02:00
|
|
|
emit m_worker->showErrorMessage("git pull",
|
|
|
|
QString("wrong format for result of 'git pull' ") + s);
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("WRONG FORMAT FOR RESULT OF 'GIT FETCH' ") + s);
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
} else {
|
2023-09-28 12:09:57 +02:00
|
|
|
// emit m_worker->showErrorMessage("git fetch", "empty result for 'git fetch'");
|
2023-10-18 11:38:26 +02:00
|
|
|
Utils::printInfoMsg("EMPTY RESULT FOR 'GIT PULL'");
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
} else {
|
2023-10-18 11:38:26 +02:00
|
|
|
emit m_worker->showErrorMessage("git pull", QString("repository ") + m_customerRepository + " does not exist");
|
2023-08-11 11:11:14 +02:00
|
|
|
Utils::printCriticalErrorMsg(QString("REPOSITORY ") + m_customerRepository + " DOES NOT EXIST");
|
2023-07-10 15:57:17 +02:00
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::optional<QStringList> GitClient::gitMerge() {
|
|
|
|
Command c("git merge");
|
|
|
|
if (c.execute(m_workingDirectory)) {
|
|
|
|
QString s = c.getCommandResult();
|
|
|
|
QStringList lst = Update::split(s, '\n');
|
|
|
|
return lst;
|
|
|
|
}
|
|
|
|
return std::nullopt;
|
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
|
|
|
|
QString GitClient::gitLastCommit(QString fileName) {
|
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
QString const filePath
|
|
|
|
= QDir::cleanPath(m_customerRepository + QDir::separator() + fileName);
|
2023-08-11 11:12:59 +02:00
|
|
|
if (QFile(filePath).exists()) {
|
|
|
|
QString const gitCommand = QString("git log %1 | head -n 1").arg(fileName);
|
|
|
|
Command c("bash");
|
|
|
|
if (c.execute(m_customerRepository, QStringList() << "-c" << gitCommand)) {
|
|
|
|
QString const r = c.getCommandResult();
|
|
|
|
int const idx = r.indexOf("commit ");
|
|
|
|
if (idx != -1) {
|
|
|
|
return r.mid(idx + 8).trimmed();
|
|
|
|
}
|
2023-07-14 13:16:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2023-07-19 16:50:54 +02:00
|
|
|
// fileName has to an absolute path
|
2023-07-14 13:16:01 +02:00
|
|
|
QString GitClient::gitBlob(QString fileName) {
|
2023-07-19 16:50:54 +02:00
|
|
|
QFileInfo fi(fileName);
|
|
|
|
if (fi.exists()) {
|
2023-07-14 13:16:01 +02:00
|
|
|
QString const gitCommand = QString("git hash-object %1").arg(fileName);
|
|
|
|
Command c(gitCommand);
|
2023-08-22 12:19:25 +02:00
|
|
|
if (c.execute("/tmp")) {
|
2023-07-19 16:50:54 +02:00
|
|
|
return c.getCommandResult().trimmed();
|
2023-07-14 13:16:01 +02:00
|
|
|
}
|
|
|
|
}
|
2023-07-19 16:50:54 +02:00
|
|
|
return "N/A";
|
2023-07-14 13:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QString GitClient::gitCommitForBlob(QString blob) {
|
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
QString const gitCommand
|
|
|
|
= QString("git whatchanged --all --find-object=%1 | head -n 1").arg(blob);
|
|
|
|
Command c(gitCommand);
|
|
|
|
if (c.execute(m_customerRepository)) {
|
|
|
|
return c.getCommandResult();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GitClient::gitIsFileTracked(QString fName) {
|
|
|
|
if (QDir(m_customerRepository).exists()) {
|
|
|
|
QString const gitCommand
|
|
|
|
= QString("git ls-files --error-unmatch %1").arg(fName);
|
|
|
|
Command c(gitCommand);
|
|
|
|
return c.execute(m_customerRepository);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//get_commit_for_blob () {
|
|
|
|
// # search for the blob in all commits for the file(name) $1
|
|
|
|
// echo $(git log --all --pretty=format:%H -- $2 |
|
|
|
|
// xargs -I{} bash -c "git ls-tree {} -- $2 |
|
|
|
|
// grep -q $1 && echo -n {} && head -n 1")
|
|
|
|
//}
|