diff --git a/clickable.yaml b/clickable.yaml index f226e2c..4c3d522 100644 --- a/clickable.yaml +++ b/clickable.yaml @@ -4,7 +4,7 @@ kill: UTPass scripts: style: >- - echo 'Running Astyle :' && astyle --options=.astylerc main.cpp && astyle --options=.astylerc --recursive 'plugins/*.cpp,*.h' && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success' + echo 'Running Astyle :' && astyle --options=.astylerc --recursive '*.cpp,*.h' --exclude=build && echo 'Running QmlFormat' && find . -name "*.qml" -exec qmlformat -i {} \; && echo 'Success' diff --git a/plugins/Git/CMakeLists.txt b/plugins/Git/CMakeLists.txt index 5f06fe8..541aca0 100644 --- a/plugins/Git/CMakeLists.txt +++ b/plugins/Git/CMakeLists.txt @@ -6,7 +6,7 @@ set( plugin.cpp libgit.cpp git.cpp - + templates.h ) set(CMAKE_AUTOMOC ON) diff --git a/plugins/Git/git.cpp b/plugins/Git/git.cpp index 1d8910c..83f0836 100644 --- a/plugins/Git/git.cpp +++ b/plugins/Git/git.cpp @@ -6,14 +6,7 @@ #include "git.h" #include "libgit.h" - - -template -struct overload : Ts... { - using Ts::operator()...; -}; -template -overload(Ts...) -> overload; +#include "utils.h" QDir Git::clone_setup() @@ -29,7 +22,7 @@ QDir Git::clone_setup() bool Git::clone_tear_down(QDir tmp_dir) { - tmp_dir.removeRecursively(); + return tmp_dir.removeRecursively(); } bool Git::move_to_destination(QString path, QDir tmp_dir) @@ -49,11 +42,11 @@ bool Git::move_to_destination(QString path, QDir tmp_dir) bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass) { auto v = overload { - [](const Unset& x) { return "Unset"; }, - [](const HTTP& x) { return "Unset"; }, - [](const HTTPAuth& x) { return "HTTPAuth"; }, - [](const SSHAuth& x) { return "SSHAuth"; }, - [](const SSHKey& x) { return "SSHKey"; }, + [](const Unset & x) { return "Unset"; }, + [](const HTTP & x) { return "Unset"; }, + [](const HTTPAuth & x) { return "HTTPAuth"; }, + [](const SSHAuth & x) { return "SSHAuth"; }, + [](const SSHKey & x) { return "SSHKey"; }, }; qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode); @@ -63,9 +56,11 @@ bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoTy qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath(); auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling - if (ret) { this->move_to_destination(path, tmp_dir);} + if (ret) { + this->move_to_destination(path, tmp_dir); + } - tmp_dir.removeRecursively(); + this->clone_tear_down(tmp_dir); LibGit::instance()->set_mode(Unset()); return ret ; @@ -77,7 +72,8 @@ bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QS return this->clone(url, path, mode); } -bool Git::clone_http_pass(QString url, QString path, QString pass) { +bool Git::clone_http_pass(QString url, QString path, QString pass) +{ HTTPAuth mode = { pass }; return this->clone(url, path, mode); } diff --git a/plugins/Git/libgit.cpp b/plugins/Git/libgit.cpp index c300e56..f2dff81 100644 --- a/plugins/Git/libgit.cpp +++ b/plugins/Git/libgit.cpp @@ -7,14 +7,9 @@ extern "C" { } #include "libgit.h" +#include "utils.h" -template -struct overload : Ts... { - using Ts::operator()...; -}; -template -overload(Ts...) -> overload; LibGit::LibGit() { @@ -26,7 +21,8 @@ LibGit::~LibGit() git_libgit2_shutdown(); } -void LibGit::set_mode(mode_type type) { +void LibGit::set_mode(mode_type type) +{ this->mode = type; } @@ -36,30 +32,35 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username // TODO : More precise Error Handling for UI auto instance = LibGit::instance(); auto v = overload { - [](const Unset& x) { + [](const Unset & x) + { qDebug() << "credentials_cb : Unset "; qWarning() << "credentials_cb : callback should never be call for Unset "; return (int) GIT_EUSER; }, - [](const HTTP& x) { + [](const HTTP & x) + { qDebug() << "credentials_cb : HTTP "; qWarning() << "credentials_cb : callback should never be call for HTTP "; return (int) GIT_EUSER; }, - [&out, &username_from_url](const HTTPAuth& x) { + [&out, &username_from_url](const HTTPAuth & x) + { qDebug() << "credentials_cb : HTTPAuth "; - if(!username_from_url) { + if (!username_from_url) { qWarning() << "credentials_cb : no username provided "; return (int) GIT_EUSER; } return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData()); }, - [&](const SSHAuth& x) { + [&](const SSHAuth & x) + { qWarning() << "credentials_cb : SSHAuth to be implemented "; return (int) GIT_EUSER; }, // TODO - [&](const SSHKey& x) { - qWarning() << "credentials_cb : SSHKey to be implemented "; + [&](const SSHKey & x) + { + qWarning() << "credentials_cb : SSHKey to be implemented "; return (int) GIT_EUSER; } // TODO }; @@ -76,10 +77,10 @@ bool LibGit::clone(QString url, QString path) int ret = git_clone(&repo, url.toLocal8Bit().data(), path.toLocal8Bit().data(), &opts); if (ret != 0) { - qDebug() << git_error_last()->message; + qDebug() << git_error_last()->message; } if (repo) { - git_repository_free(repo); + git_repository_free(repo); } return ret == 0; // TODO Clean error handling to return specifics errors for the ui diff --git a/plugins/Git/libgit.h b/plugins/Git/libgit.h index cb02f5d..8a78788 100644 --- a/plugins/Git/libgit.h +++ b/plugins/Git/libgit.h @@ -12,7 +12,9 @@ extern "C" { struct Unset { }; struct HTTP { }; -struct HTTPAuth { QString pass; }; +struct HTTPAuth { + QString pass; +}; struct SSHAuth { }; struct SSHKey { }; typedef std::variant mode_type; diff --git a/plugins/Git/utils.h b/plugins/Git/utils.h new file mode 100644 index 0000000..29a3365 --- /dev/null +++ b/plugins/Git/utils.h @@ -0,0 +1,11 @@ +#ifndef UTILS_H +#define UTILS_H + +template +struct overload : Ts... { + using Ts::operator()...; +}; +template +overload(Ts...) -> overload; + +#endif // UTILS_H diff --git a/qml/Main.qml b/qml/Main.qml index a9f26e8..1f22bcc 100644 --- a/qml/Main.qml +++ b/qml/Main.qml @@ -19,10 +19,10 @@ MainView { //TODO use parameters to impove passphrase dialog var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml")); passphraseDialog.activateFocus(); - var validated = function (passphrase) { + var validated = function validated(passphrase) { responsePassphraseDialog(false, passphrase); }; - var canceled = function () { + var canceled = function canceled() { responsePassphraseDialog(true, ""); }; passphraseDialog.validated.connect(validated); diff --git a/qml/pages/settings/ImportGitClone.qml b/qml/pages/settings/ImportGitClone.qml index 6a426b8..2373938 100644 --- a/qml/pages/settings/ImportGitClone.qml +++ b/qml/pages/settings/ImportGitClone.qml @@ -69,12 +69,10 @@ Page { text: i18n.tr('Clone') onClicked: { var ret = false; - if(repoPasswordInput.text === "") { + if (repoPasswordInput.text === "") ret = Git.clone_http(repoUrlInput.text, Pass.password_store); - } else { + else ret = Git.clone_http_pass(repoUrlInput.text, Pass.password_store, repoPasswordInput.text); - } - if (ret) PopupUtils.open(dialogImportGitCloneSuccess); else diff --git a/tests/plugins/TestsUtils/utils.cpp b/tests/plugins/TestsUtils/utils.cpp index 47495c5..1176d1d 100644 --- a/tests/plugins/TestsUtils/utils.cpp +++ b/tests/plugins/TestsUtils/utils.cpp @@ -8,7 +8,8 @@ #include "utils.h" -QString TestsUtils::getTempPath() { +QString TestsUtils::getTempPath() +{ qFatal("yp"); // Get the system's temporary directory QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation); diff --git a/tests/unit/tst_git.qml b/tests/unit/tst_git.qml index 542304b..1f47773 100644 --- a/tests/unit/tst_git.qml +++ b/tests/unit/tst_git.qml @@ -1,12 +1,11 @@ +import Git 1.0 import QtQuick 2.9 import QtTest 1.2 -import Git 1.0 TestCase { - name: "git" - function test_git_clone() { - - verify(Git.clone("","")); + verify(Git.clone("", "")); } + + name: "git" } diff --git a/tests/unit/tst_pass.qml b/tests/unit/tst_pass.qml index 542304b..1f47773 100644 --- a/tests/unit/tst_pass.qml +++ b/tests/unit/tst_pass.qml @@ -1,12 +1,11 @@ +import Git 1.0 import QtQuick 2.9 import QtTest 1.2 -import Git 1.0 TestCase { - name: "git" - function test_git_clone() { - - verify(Git.clone("","")); + verify(Git.clone("", "")); } + + name: "git" } diff --git a/tests/unit/tst_utils.qml b/tests/unit/tst_utils.qml index 25e5295..c8f0f4b 100644 --- a/tests/unit/tst_utils.qml +++ b/tests/unit/tst_utils.qml @@ -4,12 +4,12 @@ import TestUtils 1.0 import Utils 1.0 TestCase { - name: "utils" - function test_unzip() { var tempPath = TestUtils.getTempPath() + "/password-store"; var zipUrl = Qt.resolvedUrl("../assets/archive.zip"); - var r = Utils.unzip(zipUrl, tempPath) - verify(r, "Unzip return an error %1".arg(zipUrl)) + var r = Utils.unzip(zipUrl, tempPath); + verify(r, "Unzip return an error %1".arg(zipUrl)); } + + name: "utils" }