Implemented:
bool branchExistsRemotely();
	Check if branch exists in remote customer-repository.
    bool branchExistsLocally();
	Check if branch exists locally in customer-repository.
    bool gitPullNewBranches();
	In case the remote branch exists, but not the corresponding local one,
	then fetch the remote-branch.
			
			
This commit is contained in:
		@@ -6,6 +6,7 @@
 | 
				
			|||||||
#include <QRegularExpression>
 | 
					#include <QRegularExpression>
 | 
				
			||||||
#include <QDebug>
 | 
					#include <QDebug>
 | 
				
			||||||
#include <QDir>
 | 
					#include <QDir>
 | 
				
			||||||
 | 
					#include <QStringList>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
GitClient::GitClient(QString const &customerNrStr,
 | 
					GitClient::GitClient(QString const &customerNrStr,
 | 
				
			||||||
@@ -290,6 +291,100 @@ bool GitClient::gitFsck() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    return r;
 | 
					    return r;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool GitClient::branchExistsRemotely() {
 | 
				
			||||||
 | 
					    bool remoteBranchExists = false;
 | 
				
			||||||
 | 
					    if (QDir(m_customerRepository).exists()) {
 | 
				
			||||||
 | 
					        qInfo() << "BRANCH NAME" << m_branchName;
 | 
				
			||||||
 | 
					        QString const cmd = QString("git ls-remote --exit-code --heads origin %1").arg(m_branchName);
 | 
				
			||||||
 | 
					        Command c(cmd);
 | 
				
			||||||
 | 
					        if (c.execute(m_customerRepository)) {
 | 
				
			||||||
 | 
					            // expected result: c16c833c8778c1b3691a74afee5a469177e4e69b refs/heads/zg1/zone1000
 | 
				
			||||||
 | 
					            QString const s = c.getCommandResult().trimmed();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if (!s.isEmpty()) {
 | 
				
			||||||
 | 
					                // the result is only one line
 | 
				
			||||||
 | 
					                if ((remoteBranchExists = s.contains(m_branchName)) == true) {
 | 
				
			||||||
 | 
					                    qCritical() << "(" << __func__ << ":" << __LINE__ << ") branch"
 | 
				
			||||||
 | 
					                                << m_branchName << "EXISTS REMOTELY. (" << s << ")";
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                Utils::printCriticalErrorMsg(QString("EMPTY RESULT FOR CMD %1").arg(cmd));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            Utils::printCriticalErrorMsg(QString("FAILED TO EXEC '%1'").arg(cmd));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return remoteBranchExists;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool GitClient::branchExistsLocally() {
 | 
				
			||||||
 | 
					    Command c("git branch -l");
 | 
				
			||||||
 | 
					    if (c.execute(m_customerRepository)) {
 | 
				
			||||||
 | 
					        QString const s = c.getCommandResult().trimmed();
 | 
				
			||||||
 | 
					        if (!s.isEmpty()) {
 | 
				
			||||||
 | 
					            QStringList lines = Update::split(s, '\n');
 | 
				
			||||||
 | 
					            if (!lines.empty()) {
 | 
				
			||||||
 | 
					                for (int i=0; i < lines.size(); ++i) {
 | 
				
			||||||
 | 
					                    QString line = lines.at(i);
 | 
				
			||||||
 | 
					                    // expected: * [new branch]      zg1/zone12 -> origin/zg1/zone12"
 | 
				
			||||||
 | 
					                    if (line.contains(m_branchName)) {
 | 
				
			||||||
 | 
					                        if (m_worker) {
 | 
				
			||||||
 | 
					                            QStringList lst(QString("BRANCH-NAME %1 CONTAINED IN RESULT %2").arg(m_branchName).arg(s));
 | 
				
			||||||
 | 
					                            m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH;
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                        return true;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                if (m_worker) {
 | 
				
			||||||
 | 
					                    QStringList lst(QString("BRANCH-NAME %1 NOT CONTAINED IN RESULT %2").arg(m_branchName).arg(s));
 | 
				
			||||||
 | 
					                    m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH_FAILURE;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                if (m_worker) {
 | 
				
			||||||
 | 
					                    QStringList lst(QString("'git branch -l' RETURNED NO LINES"));
 | 
				
			||||||
 | 
					                    m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH_FAILURE;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            if (m_worker) {
 | 
				
			||||||
 | 
					                QStringList lst(QString("'git branch -l' RETURNED EMPTY RESULT"));
 | 
				
			||||||
 | 
					                m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH_FAILURE;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    } else {
 | 
				
			||||||
 | 
					        if (m_worker) {
 | 
				
			||||||
 | 
					            QStringList lst(QString("FAILED TO EXEC 'git branch -l'"));
 | 
				
			||||||
 | 
					            m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH_FAILURE;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					bool GitClient::gitPullNewBranches() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (QDir(m_customerRepository).exists()) {
 | 
				
			||||||
 | 
					        Command c("git pull");
 | 
				
			||||||
 | 
					        if (c.execute(m_customerRepository)) {
 | 
				
			||||||
 | 
					            QString const s = c.getCommandResult().trimmed();
 | 
				
			||||||
 | 
					            // expected: Already up-to-date.
 | 
				
			||||||
 | 
					            if (!s.isEmpty()) {
 | 
				
			||||||
 | 
					                QStringList lst;
 | 
				
			||||||
 | 
					                QString msg(QString("GIT-PULL-NEW-BRANCH. RESULT=%1").arg(s));
 | 
				
			||||||
 | 
					                if (m_worker) {
 | 
				
			||||||
 | 
					                    m_worker->CONSOLE(lst) << Worker::UPDATE_STEP::PULL_NEW_BRANCH;
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                return true;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return false;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
 | 
					 Hat sich nichts geaendert, so werden auch keine Commits <>..<> angezeigt
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user