#3472 Regression Test : Add GitDiff

This commit is contained in:
Magne Sjaastad 2018-10-08 11:41:35 +02:00
parent 7e251aaab6
commit 85197661fe
3 changed files with 183 additions and 0 deletions

View File

@ -40,6 +40,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaWeightedMeanCalculator.inl
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.h
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.h
${CMAKE_CURRENT_LIST_DIR}/RiaGitDiff.h
)
set (SOURCE_GROUP_SOURCE_FILES
@ -80,6 +81,7 @@ ${CMAKE_CURRENT_LIST_DIR}/RiaLineArcWellPathCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedGeometricMeanCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaWeightedHarmonicMeanCalculator.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaOptionItemFactory.cpp
${CMAKE_CURRENT_LIST_DIR}/RiaGitDiff.cpp
)
list(APPEND CODE_HEADER_FILES

View File

@ -0,0 +1,124 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#include "RiaGitDiff.h"
#include "cafUtils.h"
#include <QDir>
#include <QProcess>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaGitDiff::RiaGitDiff(const QString& pathToDiffTool)
: m_pathToGitTool(pathToDiffTool)
{
reset();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaGitDiff::~RiaGitDiff() {}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RiaGitDiff::reset()
{
m_lastError = IC_NO_ERROR;
m_errorMsg.clear();
m_errorDetails.clear();
m_diffOutput.clear();
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RiaGitDiff::executeDiff(const QString& baseFolder)
{
reset();
QString fullFilePath = "git";
if (!m_pathToGitTool.isEmpty())
{
fullFilePath = m_pathToGitTool + "/" + fullFilePath;
}
QString incomingCurrentPath = QDir::currentPath();
QDir::setCurrent(baseFolder);
QString args = "diff";
QString completeCommand = QString("\"%1\" %2").arg(fullFilePath).arg(args);
// Launch process and wait
QProcess proc;
proc.start(completeCommand);
proc.waitForFinished(30000);
QDir::setCurrent(incomingCurrentPath);
QProcess::ProcessError procError = proc.error();
if (procError != QProcess::UnknownError)
{
m_lastError = SEVERE_ERROR;
m_errorMsg = "Error running 'git' tool process";
m_errorDetails = completeCommand;
return false;
}
QByteArray stdErr = proc.readAllStandardError();
QByteArray stdOut = proc.readAllStandardOutput();
m_diffOutput = stdOut;
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RiaGitDiff::ErrorType RiaGitDiff::error() const
{
return m_lastError;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaGitDiff::errorMessage() const
{
return m_errorMsg;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaGitDiff::errorDetails() const
{
return m_errorDetails;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RiaGitDiff::diffOutput() const
{
return m_diffOutput;
}

View File

@ -0,0 +1,57 @@
/////////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2018 Statoil ASA
//
// ResInsight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.
//
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
// for more details.
//
/////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <QString>
//==================================================================================================
//
// Use external tool 'git' to produce a text string representing the diff
//
//==================================================================================================
class RiaGitDiff
{
public:
enum ErrorType
{
IC_NO_ERROR, // No error occurred
IC_ERROR, // An error occurred
SEVERE_ERROR // Severe error occurred, it is likely that another call to compare() will also fail
};
public:
explicit RiaGitDiff(const QString& pathToGitTool);
~RiaGitDiff();
bool executeDiff(const QString& baseFolder);
ErrorType error() const;
QString errorMessage() const;
QString errorDetails() const;
QString diffOutput() const;
private:
void reset();
private:
const QString m_pathToGitTool;
ErrorType m_lastError;
QString m_errorMsg;
QString m_errorDetails;
QString m_diffOutput;
};