Fix AUR builds Fix tests to work on machines without GIT configured Disable tests that touch global configuration by default Remove empty HunkWidget test Make resource install directory configurable Copy resources into output directory so that debugging works Replace "OK" button with "Remind me later" and "Skip this version" for non-updateable builds Allow using system-wide installations of most dependencies Make debug output suppressable and disable it in CI builds

This commit is contained in:
kas 2022-10-16 11:31:07 +02:00
parent be5c9269ac
commit fffa3c7350
27 changed files with 308 additions and 177 deletions

View File

@ -263,7 +263,7 @@ jobs:
run: |
mkdir -p build/release
cd build/release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DDEBUG_OUTPUT=OFF -DGITTYUP_CI_TESTS=ON ${{ env.CMAKE_FLAGS }} ${{ matrix.env.cmake_flags }} ../..
- name: Build Information
run: |

View File

@ -45,6 +45,23 @@ set(BUILD_SHARED_LIBS OFF)
option(FLATPAK "Building for flatpak" OFF)
option(DEBUG_FLATPAK "Building but using flatpak urls for testing" OFF)
option(USE_SYSTEM_OPENSSL "Use the system-wide OpenSSL installation" OFF)
option(
USE_SYSTEM_LIBGIT2
"Use the system-wide libgit2 installation (Gittyup requires the current development branch)"
OFF)
option(USE_SYSTEM_LIBSSH2 "Use the system-wide libssh2 installation" OFF)
option(USE_SYSTEM_GIT "Use the system-wide GIT installation" OFF)
option(USE_SYSTEM_QT "Don't copy QT files into the installation directory" OFF)
option(USE_SYSTEM_LUA "Use the system-wide Lua installation" OFF)
option(USE_SYSTEM_HUNSPELL "Use the system-wide hunspell installation" OFF)
option(USE_SYSTEM_CMARK "Use the system-wide cmark installation" OFF)
set(LUA_MODULES_PATH
CACHE
PATH
"Path to the directory with native Lua modules (only relevant if system-wide Lua installation is used)"
)
# Require C++17.
set(CMAKE_CXX_STANDARD 17)
@ -68,6 +85,11 @@ if(UNIX)
set(QT_MODULES ${QT_MODULES} DBus)
endif()
option(DEBUG_OUTPUT "Print debug output" ON)
if(NOT DEBUG_OUTPUT)
add_compile_definitions(QT_NO_DEBUG_OUTPUT)
endif()
find_package(
Qt5 5.12
COMPONENTS ${QT_MODULES} LinguistTools
@ -105,5 +127,5 @@ endif()
add_subdirectory(dep)
add_subdirectory(src)
add_subdirectory(l10n)
add_subdirectory(test)
add_subdirectory(pack)
add_subdirectory(test)

View File

@ -1,15 +1,28 @@
set(CMARK_TESTS
OFF
CACHE BOOL "" FORCE)
set(CMARK_SHARED
OFF
CACHE BOOL "" FORCE)
if(USE_SYSTEM_CMARK)
if(PKG_CONFIG_FOUND)
pkg_check_modules(CMARK libcmark)
add_executable(cmark_exe IMPORTED GLOBAL)
set_property(TARGET cmark_exe PROPERTY IMPORTED_LOCATION cmark)
endif()
add_subdirectory(cmark)
target_include_directories(
cmark_static
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cmark/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/cmark/src>)
set(LIBCMARK_LIBRARIES
set(LIBCMARK_LIBRARIES
cmark
CACHE INTERNAL "libcmark implementation" FORCE)
else()
set(CMARK_TESTS
OFF
CACHE BOOL "" FORCE)
set(CMARK_SHARED
OFF
CACHE BOOL "" FORCE)
add_subdirectory(cmark)
target_include_directories(
cmark_static
CACHE INTERNAL "libcmark implementation" FORCE)
INTERFACE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cmark/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/cmark/src>)
set(LIBCMARK_LIBRARIES
cmark_static
CACHE INTERNAL "libcmark implementation" FORCE)
endif()

View File

@ -1,36 +1,38 @@
set(PATH ${CMAKE_CURRENT_SOURCE_DIR}/git/contrib/credential)
if(NOT USE_SYSTEM_GIT)
set(PATH ${CMAKE_CURRENT_SOURCE_DIR}/git/contrib/credential)
macro(add_helper NAME)
set(TARGET git-credential-${NAME})
add_executable(${TARGET} ${PATH}/${NAME}/${TARGET}.c)
set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
$<TARGET_FILE_DIR:gittyup>)
macro(add_helper NAME)
set(TARGET git-credential-${NAME})
add_executable(${TARGET} ${PATH}/${NAME}/${TARGET}.c)
set_target_properties(${TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY
$<TARGET_FILE_DIR:gittyup>)
if(${ARGC} GREATER 1)
target_link_libraries(${TARGET} ${ARGV1})
endif()
if(${ARGC} GREATER 1)
target_link_libraries(${TARGET} ${ARGV1})
endif()
if(NOT APPLE)
install(
TARGETS ${TARGET}
DESTINATION .
COMPONENT ${GITTYUP_NAME})
endif()
endmacro()
if(NOT APPLE)
install(
TARGETS ${TARGET}
DESTINATION .
COMPONENT ${GITTYUP_NAME})
endif()
endmacro()
if(APPLE)
add_helper(osxkeychain "-framework Security")
elseif(WIN32)
add_helper(wincred)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSECRET IMPORTED_TARGET libsecret-1)
if(LIBSECRET_FOUND)
add_helper(libsecret PkgConfig::LIBSECRET)
endif()
if(APPLE)
add_helper(osxkeychain "-framework Security")
elseif(WIN32)
add_helper(wincred)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBSECRET IMPORTED_TARGET libsecret-1)
if(LIBSECRET_FOUND)
add_helper(libsecret PkgConfig::LIBSECRET)
endif()
pkg_check_modules(GNOME_KEYRING IMPORTED_TARGET gnome-keyring-1)
if(GNOME_KEYRING_FOUND)
add_helper(gnome-keyring PkgConfig::GNOME_KEYRING)
pkg_check_modules(GNOME_KEYRING IMPORTED_TARGET gnome-keyring-1)
if(GNOME_KEYRING_FOUND)
add_helper(gnome-keyring PkgConfig::GNOME_KEYRING)
endif()
endif()
endif()

View File

@ -5,7 +5,7 @@ if(HUNSPELL_FOUND)
# target_compile_definitions(hunspell PUBLIC HUNSPELL_STATIC)
target_include_directories(hunspell INTERFACE ${HUNSPELL_INCLUDE_DIRS})
target_link_libraries(hunspell INTERFACE ${HUNSPELL_LINK_LIBRARIES})
else()
elseif(NOT USE_SYSTEM_HUNSPELL)
set(HUNSPELL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/hunspell)
add_library(

View File

@ -32,6 +32,8 @@ if(WIN32)
CACHE BOOL "" FORCE)
endif()
add_subdirectory(libgit2)
target_include_directories(
git2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libgit2/include)
if(NOT USE_SYSTEM_LIBGIT2)
add_subdirectory(libgit2)
target_include_directories(
git2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/libgit2/include)
endif()

View File

@ -1,22 +1,25 @@
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBSSH2 libssh2)
if(USE_SYSTEM_LIBSSH2)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBSSH2 libssh2)
endif()
else()
add_subdirectory(libssh2)
set(BUILD_EXAMPLES
OFF
CACHE BOOL "" FORCE)
set(BUILD_TESTING
OFF
CACHE BOOL "" FORCE)
set(LIBSSH2_FOUND
TRUE
PARENT_SCOPE)
set(LIBSSH2_LIBRARIES
libssh2
PARENT_SCOPE)
set(LIBSSH2_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/libssh2/include
PARENT_SCOPE)
endif()
set(BUILD_EXAMPLES
OFF
CACHE BOOL "" FORCE)
set(BUILD_TESTING
OFF
CACHE BOOL "" FORCE)
add_subdirectory(libssh2)
set(LIBSSH2_FOUND
TRUE
PARENT_SCOPE)
set(LIBSSH2_LIBRARIES
libssh2
PARENT_SCOPE)
set(LIBSSH2_INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/libssh2/include
PARENT_SCOPE)

View File

@ -3,7 +3,7 @@ if(LUA_FOUND)
add_library(lua INTERFACE)
target_include_directories(lua INTERFACE ${LUA_INCLUDE_DIR})
target_link_libraries(lua INTERFACE ${LUA_LIBRARIES})
else()
elseif(NOT USE_SYSTEM_LUA)
set(LUA_DIR lua-5.4.0)
add_library(

View File

@ -1,14 +1,16 @@
if(EXISTS ${CMAKE_BINARY_DIR}/../openssl)
set(OPENSSL_DIR
${CMAKE_BINARY_DIR}/../openssl
CACHE PATH "")
else()
set(OPENSSL_DIR
${CMAKE_CURRENT_SOURCE_DIR}/openssl
CACHE PATH "")
endif()
if(NOT USE_SYSTEM_OPENSSL)
if(EXISTS ${CMAKE_BINARY_DIR}/../openssl)
set(OPENSSL_DIR
${CMAKE_BINARY_DIR}/../openssl
CACHE PATH "")
else()
set(OPENSSL_DIR
${CMAKE_CURRENT_SOURCE_DIR}/openssl
CACHE PATH "")
endif()
# This is a hint for the FindOpenSSL module.
set(OPENSSL_ROOT_DIR
${OPENSSL_DIR}
PARENT_SCOPE)
# This is a hint for the FindOpenSSL module.
set(OPENSSL_ROOT_DIR
${OPENSSL_DIR}
PARENT_SCOPE)
endif()

View File

@ -19,7 +19,7 @@ endif()
if(FLATPAK)
qt_import_plugins(gittyup INCLUDE ${QT_PLUGINS})
else()
elseif(NOT USE_SYSTEM_QT)
foreach(QT_PLUGIN ${QT_PLUGINS})
if(NOT TARGET Qt5::${QT_PLUGIN})
if(UNIX OR APPLE)
@ -68,9 +68,7 @@ else()
)" COMPONENT ${GITTYUP_NAME})
endif()
endforeach()
endif()
if(NOT FLATPAK)
# Install Qt libraries.
foreach(QT_MODULE ${QT_MODULES})
get_target_property(QT_LIBRARY Qt5::${QT_MODULE}
@ -122,31 +120,33 @@ if(NOT FLATPAK)
endif()
endif()
endforeach()
endif()
# Install XcbQpa library.
if(UNIX AND NOT APPLE)
set(LIB_NAME libQt5XcbQpa)
get_target_property(QT_CORE_LIBRARY Qt5::Core LOCATION)
get_filename_component(LIB_PATH ${QT_CORE_LIBRARY} PATH)
get_filename_component(LIB_EXT ${QT_CORE_LIBRARY} EXT)
# Install XcbQpa library.
if(UNIX AND NOT APPLE)
set(LIB_NAME libQt5XcbQpa)
get_target_property(QT_CORE_LIBRARY Qt5::Core LOCATION)
get_filename_component(LIB_PATH ${QT_CORE_LIBRARY} PATH)
get_filename_component(LIB_EXT ${QT_CORE_LIBRARY} EXT)
install(
FILES "${LIB_PATH}/${LIB_NAME}${LIB_EXT}"
DESTINATION .
PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
COMPONENT ${GITTYUP_NAME}
RENAME ${LIB_NAME}.so.5)
endif()
install(
FILES "${LIB_PATH}/${LIB_NAME}${LIB_EXT}"
DESTINATION .
PERMISSIONS
OWNER_READ
OWNER_WRITE
OWNER_EXECUTE
GROUP_READ
GROUP_EXECUTE
WORLD_READ
WORLD_EXECUTE
COMPONENT ${GITTYUP_NAME}
RENAME ${LIB_NAME}.so.5)
endif()
# Install SSL libraries.
if(NOT APPLE)
# Install SSL libraries.
if(NOT APPLE)
if(NOT USE_SYSTEM_OPENSSL)
if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(SSL_LIB_SUFFIX "-1_1-x64.dll")
@ -192,10 +192,10 @@ if(NOT FLATPAK)
endif()
if(UNIX AND NOT APPLE)
install(
DIRECTORY ${RSRC_DIR}/Gittyup.iconset
DESTINATION ${CMAKE_INSTALL_DATADIR}/Gittyup/Resources
COMPONENT ${GITTYUP_NAME})
install(
DIRECTORY ${RSRC_DIR}/Gittyup.iconset
DESTINATION "Resources"
COMPONENT ${GITTYUP_NAME})
endif()
# Sign bundle on macOS.

View File

@ -6,48 +6,80 @@
pkgname=gittyup
pkgrel=3
pkgver=1.0.0
branch="master"
pkgver=1.1.1
branch="arch-aur-build"
pkgdesc='Understand your Git history!'
url='TODO replace: https://www.gitahead.com/'
url='https://murmele.github.io/Gittyup'
arch=('x86_64')
license=('MIT')
depends=('desktop-file-utils' 'qt5-base' 'git')
depends=('desktop-file-utils' 'qt5-base' 'git' 'openssl' 'libssh2' 'hunspell' 'cmark' 'lua' 'lua-lpeg')
makedepends=('cmake' 'ninja' 'git' 'qt5-tools' 'qt5-translations')
source=(
"git+https://github.com/Murmele/Gittyup#branch=${branch}"
"git+https://github.com/exactly-one-kas/Gittyup#branch=${branch}"
)
sha256sums=(
'SKIP'
)
prepare() {
cd "$srcdir/gittyup"
cd "$srcdir/Gittyup"
git config submodule.dep/openssl/openssl.update none
git config submodule.dep/libssh2/libssh2.update none
git config submodule.dep/git/git.update none
git config submodule.dep/hunspell/hunspell.update none
git config submodule.dep/cmark/cmark.update none
git submodule update --init --recursive
}
build() {
if [ ! -d "$srcdir/gittyup-build" ]; then
mkdir "$srcdir/gittyup-build"
fi
cd "$srcdir/gittyup-build"
cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=/usr \
-DDEBUG_OUTPUT=OFF \
-DUSE_SYSTEM_OPENSSL=ON \
-DUSE_SYSTEM_LIBSSH2=ON \
-DUSE_SYSTEM_GIT=ON \
-DUSE_SYSTEM_LUA=ON \
-DUSE_SYSTEM_HUNSPELL=ON \
-DUSE_SYSTEM_CMARK=ON \
-DLUA_MODULES_PATH=/usr/lib/lua/5.4 \
../Gittyup
}
build() {
cd "$srcdir/gittyup-build"
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/lib ../gittyup
ninja
}
check() {
cd "$srcdir/gittyup-build"
ninja check
}
package() {
cd "$srcdir/gittyup-build"
ninja package
mkdir -p "${pkgdir}/usr/"{share,bin}
mkdir -p "${pkgdir}/usr/"{share/gittyup,bin}
rm -rf "${srcdir}/pack"
mkdir -p "${srcdir}/pack"
cp -r "${srcdir}/gittyup-build/_CPack_Packages/Linux/STGZ/Gittyup-${pkgver}" "${pkgdir}/usr/share/gittyup"
tar xf "${srcdir}/gittyup-build/pack/Gittyup-${pkgver}.tar.gz" -C "${srcdir}/pack"
cd "${srcdir}/pack"/Gittyup-*
rm -rf "${pkgdir}/usr/share/gittyup/"*.so.*
ln -s "/usr/share/gittyup/Gittyup" "${pkgdir}/usr/bin/gittyup"
rm -rf *.so.*
rm -rf Plugins
cp -Rv . "${pkgdir}/usr/share/gittyup"
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/gittyup_logo.svg" "${pkgdir}/usr/share/icons/hicolor/scalable/apps/gittyup.svg"
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/icon_16x16.png" "${pkgdir}/usr/share/icons/hicolor/16x16/apps/gittyup.png"
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/icon_32x32.png" "${pkgdir}/usr/share/icons/hicolor/32x32/apps/gittyup.png"
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/icon_64x64.png" "${pkgdir}/usr/share/icons/hicolor/64x64/apps/gittyup.png"
@ -55,6 +87,8 @@ package() {
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/icon_256x256.png" "${pkgdir}/usr/share/icons/hicolor/256x256/apps/gittyup.png"
install -D -m644 "${pkgdir}/usr/share/gittyup/Resources/Gittyup.iconset/icon_512x512.png" "${pkgdir}/usr/share/icons/hicolor/512x512/apps/gittyup.png"
install -D -m644 ${srcdir}/gittyup/LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -D -m644 "${srcdir}/gittyup/rsrc/linux/io.github.gittyup.gittyup.desktop" "${pkgdir}/usr/share/applications/gittyup.desktop"
install -D -m644 ${srcdir}/Gittyup/LICENSE.md "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
install -D -m644 "${srcdir}/Gittyup/rsrc/linux/com.github.Murmele.Gittyup.desktop" "${pkgdir}/usr/share/applications/gittyup.desktop"
sed -i 's/Exec=Gittyup/Exec=gittyup/' "${pkgdir}/usr/share/applications/gittyup.desktop"
}

View File

@ -206,7 +206,10 @@ execute_process(COMMAND
COMPONENT ${GITTYUP_NAME})
else()
# must be ./ otherwise it is interpreted as absolute path
set(RESOURCES_INSTALL_DIR "${CMAKE_INSTALL_DATADIR}/Gittyup/Resources")
set(RESOURCES_INSTALL_DIR
"Resources"
CACHE STRING "The path for installing resource files")
# Install config files.
if(CHANGELOG_HTML
AND ACKNOWLEDGMENTS_HTML
@ -224,11 +227,21 @@ else()
DESTINATION ${RESOURCES_INSTALL_DIR}
COMPONENT ${GITTYUP_NAME})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${EMOJI}
${CMAKE_BINARY_DIR}/Resources/emoji.json)
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${MERGETOOLS}
${CMAKE_BINARY_DIR}/Resources/mergetools)
foreach(CONFIG_FILE ${CONFIG_FILES})
install(
FILES ${CONFIG_FILE}
DESTINATION ${RESOURCES_INSTALL_DIR}
COMPONENT ${GITTYUP_NAME})
file(RELATIVE_PATH CONFIG_FILE_DEST ${CONF_DIR} ${CONFIG_FILE})
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CONFIG_FILE}
${CMAKE_BINARY_DIR}/Resources/${CONFIG_FILE_DEST})
endforeach()
install(
@ -236,20 +249,43 @@ else()
DESTINATION ${RESOURCES_INSTALL_DIR}/dictionaries
COMPONENT ${GITTYUP_NAME})
foreach(DICTIONARY ${DICTIONARIES})
file(RELATIVE_PATH DICTIONARY_DEST ${CONF_DIR} ${DICTIONARY})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${DICTIONARY}
${CMAKE_BINARY_DIR}/Resources/${DICTIONARY_DEST})
endforeach()
install(
FILES ${THEMES}
DESTINATION ${RESOURCES_INSTALL_DIR}/themes
COMPONENT ${GITTYUP_NAME})
foreach(THEME ${THEMES})
file(RELATIVE_PATH THEME_DEST ${CONF_DIR} ${THEME})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${THEME}
${CMAKE_BINARY_DIR}/Resources/${THEME_DEST})
endforeach()
install(
FILES ${LUA_PLUGINS}
DESTINATION ${RESOURCES_INSTALL_DIR}/plugins
COMPONENT ${GITTYUP_NAME})
foreach(LUA_PLUGIN ${LUA_PLUGINS})
file(RELATIVE_PATH LUA_PLUGIN_DEST ${CONF_DIR} ${LUA_PLUGIN})
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${LUA_PLUGIN}
${CMAKE_BINARY_DIR}/Resources/${LUA_PLUGIN_DEST})
endforeach()
foreach(SCINTILLUA_LEXER ${SCINTILLUA_LEXERS})
install(
FILES ${SCINTILLUA_LEXER}
DESTINATION ${RESOURCES_INSTALL_DIR}/lexers
COMPONENT ${GITTYUP_NAME})
get_filename_component(SCINTILLUA_LEXER_DEST ${SCINTILLUA_LEXER} NAME)
execute_process(
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${SCINTILLUA_LEXER}
${CMAKE_BINARY_DIR}/Resources/lexers/${SCINTILLUA_LEXER_DEST})
endforeach()
endif()

View File

@ -6,7 +6,13 @@ target_link_libraries(conf lua Qt5::Core util)
target_compile_definitions(
conf PRIVATE SCINTILLUA_LEXERS_DIR="${SCINTILLUA_LEXERS_DIR}")
target_compile_definitions(conf PRIVATE CONF_DIR="${CMAKE_INSTALL_DATADIR}/Resources"
L10N_DIR="${CMAKE_INSTALL_DATADIR}/Resources/l10n")
if(UNIX)
target_compile_definitions(
conf
PRIVATE CONF_DIR="${CMAKE_INSTALL_FULL_DATADIR}/gittyup/Resources"
L10N_DIR="${CMAKE_INSTALL_FULL_DATADIR}/gittyup/Resources/l10n")
else()
target_compile_definitions(conf PRIVATE CONF_DIR="" L10N_DIR="")
endif()
set_target_properties(conf PROPERTIES AUTOMOC ON)

View File

@ -94,6 +94,8 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
QDialogButtonBox *buttons = new QDialogButtonBox(this);
#if !defined(Q_OS_LINUX) || defined(FLATPAK) || defined(DEBUG_FLATPAK)
buttons->addButton(tr("Install Update"), QDialogButtonBox::AcceptRole);
#endif
buttons->addButton(tr("Remind Me Later"), QDialogButtonBox::RejectRole);
connect(buttons, &QDialogButtonBox::accepted, this, &UpdateDialog::accept);
@ -109,9 +111,6 @@ UpdateDialog::UpdateDialog(const QString &platform, const QString &version,
settings->endGroup();
reject();
});
#else
buttons->addButton(tr("OK"), QDialogButtonBox::RejectRole);
#endif
connect(buttons, &QDialogButtonBox::rejected, this, &UpdateDialog::reject);

View File

@ -2,7 +2,7 @@
macro(test)
cmake_parse_arguments(ARG "NO_WIN32_OFFSCREEN" "NAME" "" ${ARGN})
add_executable(test_${ARG_NAME} ${ARG_NAME}.cpp)
add_executable(test_${ARG_NAME} EXCLUDE_FROM_ALL ${ARG_NAME}.cpp)
target_link_libraries(test_${ARG_NAME} testlib)
set_target_properties(test_${ARG_NAME} PROPERTIES OUTPUT_NAME ${ARG_NAME}
@ -69,8 +69,10 @@ add_custom_target(
enable_testing()
# Add test library.
set(CMAKE_DISABLE_TESTING ON)
add_subdirectory(dep/zip)
add_library(testlib Test.cpp)
add_library(testlib EXCLUDE_FROM_ALL Test.cpp)
target_link_libraries(testlib app git ui Qt5::Test zip)
target_include_directories(testlib PRIVATE ${CMAKE_SOURCE_DIR}/src)
target_compile_definitions(
@ -79,12 +81,17 @@ target_compile_definitions(
PUBLIC SSH_CONFIG="${CMAKE_CURRENT_SOURCE_DIR}"
PUBLIC GIT_EXECUTABLE="${GIT_EXECUTABLE}")
execute_process(
COMMAND
${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_BINARY_DIR}/../Resources/
${CMAKE_CURRENT_BINARY_DIR}/Resources)
# Add tests.
test(NAME bare_repo)
test(NAME init_repo)
test(NAME merge)
test(NAME external_tools_dialog)
test(NAME config)
test(NAME branches_panel NO_WIN32_OFFSCREEN)
test(NAME editor NO_WIN32_OFFSCREEN)
test(NAME index)
@ -93,7 +100,6 @@ test(NAME log)
test(NAME main_window)
test(NAME new_branch_dialog)
test(NAME sanity)
test(NAME HunkWidget)
test(NAME Diff)
test(NAME EditorLineInfos)
test(NAME CommitAuthorCommitter)
@ -103,3 +109,8 @@ test(NAME Submodule)
test(NAME referencelist)
test(NAME amend)
test(NAME SshConfig)
option(GITTYUP_CI_TESTS "Run tests that change global settings" OFF)
if(GITTYUP_CI_TESTS)
test(NAME config)
endif()

View File

@ -12,7 +12,8 @@
QString path = Test::extractRepository(repoPath, useTempDir); \
QVERIFY(!path.isEmpty()); \
git::Repository repo = git::Repository::open(path); \
QVERIFY(repo.isValid());
QVERIFY(repo.isValid()); \
Test::initRepo(repo);
using namespace QTest;

View File

@ -19,6 +19,7 @@
QVERIFY2(!path.isEmpty(), qPrintable("Extracting repository failed")); \
mRepo = git::Repository::open(path); \
QVERIFY2(mRepo.isValid(), qPrintable("Unable to open repository")); \
Test::initRepo(mRepo); \
MainWindow window(mRepo); \
window.show(); \
QVERIFY(QTest::qWaitForWindowExposed(&window)); \

View File

@ -1,30 +0,0 @@
#include "Test.h"
#include "dialogs/ExternalToolsDialog.h"
#include "ui/DiffView/HunkWidget.h"
#include "ui/DiffView/Line.h"
#include <QString>
using namespace QTest;
class TestHunkWidget : public QObject {
Q_OBJECT
private slots:
void initTestCase();
void cleanupTestCase();
private:
int closeDelay = 0;
HunkWidget *mHunk{nullptr};
};
void TestHunkWidget::initTestCase() {
bool lfs = false;
bool submodule = false;
}
void TestHunkWidget::cleanupTestCase() { qWait(closeDelay); }
TEST_MAIN(TestHunkWidget)
#include "HunkWidget.moc"

View File

@ -28,6 +28,7 @@
QVERIFY(!path.isEmpty()); \
auto repo = git::Repository::open(path); \
QVERIFY(repo.isValid()); \
Test::initRepo(repo); \
MainWindow window(repo); \
window.show(); \
QVERIFY(QTest::qWaitForWindowExposed(&window)); \

View File

@ -8,6 +8,7 @@
//
#include "Test.h"
#include "git/Config.h"
#include "ui/RepoView.h"
//#include <JlCompress.h>
#include <exception>
@ -143,9 +144,16 @@ QString extractRepository(const QString &filename, bool useTempDir) {
return exportFolder; // successfully extracted
}
void initRepo(git::Repository &repo) {
repo.config().setValue("user.name", QString("testuser"));
repo.config().setValue("user.email", QString("test@user"));
}
ScratchRepository::ScratchRepository(bool autoRemove) {
mDir.setAutoRemove(autoRemove);
mRepo = git::Repository::init(mDir.path());
QVERIFY(mRepo);
initRepo(mRepo);
}
ScratchRepository::operator git::Repository() { return mRepo; }

View File

@ -57,6 +57,7 @@ private:
void refresh(RepoView *repoView, bool expectDirty = true);
void fetch(RepoView *repoView, git::Remote remote);
QString extractRepository(const QString &filename, bool useTempDir);
void initRepo(git::Repository &repo);
Application createApp(int &argc, char *argv[]);

View File

@ -13,6 +13,7 @@ using namespace QTest;
QVERIFY(!path.isEmpty()); \
auto repo = git::Repository::open(path); \
QVERIFY(repo.isValid()); \
Test::initRepo(repo); \
MainWindow window(repo); \
window.show(); \
QVERIFY(QTest::qWaitForWindowExposed(&window)); \

View File

@ -18,7 +18,8 @@
QString path = Test::extractRepository(repoPath, useTempDir); \
QVERIFY(!path.isEmpty()); \
git::Repository repo = git::Repository::open(path); \
QVERIFY(repo.isValid());
QVERIFY(repo.isValid()); \
Test::initRepo(repo);
class TestAmend : public QObject {
Q_OBJECT

View File

@ -44,9 +44,8 @@ void TestBranchesPanel::initTestCase() {
mWindow = new MainWindow(mRepo);
RepoView *view = mWindow->currentView();
QString repoPath = Test::extractRepository("gitahead-test.zip", false);
git::Remote remote = mRepo->addRemote("origin", repoPath);
git::Remote remote = mRepo->addRemote(
"origin", "https://github.com/Murmele/GittyupTestRepo.git");
fetch(view, remote);
git::Branch upstream =
@ -70,28 +69,35 @@ void TestBranchesPanel::createBranch() {
QWidget *panel = stack->currentWidget();
Footer *remotesFooter = panel->findChild<Footer *>();
QToolButton *addRemote = remotesFooter->findChild<QToolButton *>();
QVERIFY(addRemote);
mouseClick(addRemote, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(),
inputDelay);
// Click upstream combobox
QComboBox *referenceList = panel->findChild<QComboBox *>();
QVERIFY(referenceList);
mouseClick(referenceList, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(),
inputDelay);
// Select upstream test_remote/master
QMenu *menu = qobject_cast<QMenu *>(QApplication::activePopupWidget());
auto *menu = qobject_cast<QFrame *>(QApplication::activePopupWidget());
QVERIFY(menu);
keyClick(menu, Qt::Key_Down, Qt::NoModifier, inputDelay);
keyClick(menu, Qt::Key_Return, Qt::NoModifier, inputDelay);
// Click Accept
QDialog *newBranchDialog = panel->findChild<QDialog *>();
QVERIFY(newBranchDialog);
QList<QPushButton *> buttons = newBranchDialog->findChildren<QPushButton *>();
QVERIFY(buttons.count() >= 2);
QPushButton *createBranch = buttons.at(1);
QVERIFY(createBranch);
mouseClick(createBranch, Qt::LeftButton, Qt::KeyboardModifiers(), QPoint(),
inputDelay);
// Verify branch created
QTableView *branchTable = panel->findChild<QTableView *>();
QVERIFY(branchTable);
QVERIFY(branchTable->rowAt(0) != -1);
}

View File

@ -27,6 +27,7 @@
#include <QTextEdit>
#include <QTextStream>
#include <QToolButton>
#include <qtestcase.h>
using namespace Test;
using namespace QTest;
@ -90,6 +91,12 @@ void TestInitRepo::initTestCase() {
// Wait on the new window.
mWindow = MainWindow::activeWindow();
QVERIFY(mWindow && qWaitForWindowExposed(mWindow));
RepoView *view = mWindow->currentView();
QVERIFY(view);
git::Repository repo = view->repo();
QVERIFY(repo.isValid());
initRepo(repo);
}
void TestInitRepo::addFile() {

View File

@ -36,6 +36,7 @@
QVERIFY(!path.isEmpty()); \
mRepo = git::Repository::open(path); \
QVERIFY(mRepo.isValid()); \
Test::initRepo(mRepo); \
MainWindow window(mRepo); \
window.show(); \
QVERIFY(QTest::qWaitForWindowExposed(&window)); \

View File

@ -56,16 +56,19 @@ void TestReferenceList::test() {
qWait(300);
}
QVERIFY(view);
git::Repository repo = view->repo();
QVERIFY(repo.isValid());
initRepo(repo);
const ReferenceView::Kinds kRefKinds =
ReferenceView::InvalidRef | ReferenceView::LocalBranches |
ReferenceView::RemoteBranches | ReferenceView::Tags;
ReferenceList *rl = new ReferenceList(view->repo(), kRefKinds);
ReferenceList *rl = new ReferenceList(repo, kRefKinds);
{
// Only one tag
git::Commit commit =
view->repo().lookupCommit("99219268e1f838b0da616761fd7a184676965a69");
repo.lookupCommit("99219268e1f838b0da616761fd7a184676965a69");
QVERIFY(commit.isValid());
rl->setCommit(commit);
QVERIFY(rl->target().isValid());
@ -75,7 +78,7 @@ void TestReferenceList::test() {
{
// Only one remote
git::Commit commit =
view->repo().lookupCommit("79f4bee33320391fa99a8ef3f504b2ba229a8181");
repo.lookupCommit("79f4bee33320391fa99a8ef3f504b2ba229a8181");
QVERIFY(commit.isValid());
rl->setCommit(commit);
QVERIFY(rl->target().isValid());
@ -85,7 +88,7 @@ void TestReferenceList::test() {
{
// Only one branch
git::Commit commit =
view->repo().lookupCommit("54ecb63965b50287ceb73095c72f344c1611d94a");
repo.lookupCommit("54ecb63965b50287ceb73095c72f344c1611d94a");
QVERIFY(commit.isValid());
rl->setCommit(commit);
QVERIFY(rl->target().isValid());
@ -95,7 +98,7 @@ void TestReferenceList::test() {
{
// No branch, no remote, no tag
git::Commit commit =
view->repo().lookupCommit("63460da2b069250c34506249516029f2ba7c6057");
repo.lookupCommit("63460da2b069250c34506249516029f2ba7c6057");
QVERIFY(commit.isValid());
rl->setCommit(commit);
QVERIFY(rl->target().isValid());