mirror of
https://github.com/QRouland/UTPass.git
synced 2025-01-24 07:36:39 +00:00
Some cleanup
This commit is contained in:
parent
6ac11e2da7
commit
063f66e99a
@ -4,7 +4,7 @@ kill: UTPass
|
|||||||
|
|
||||||
scripts:
|
scripts:
|
||||||
style: >-
|
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'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ set(
|
|||||||
plugin.cpp
|
plugin.cpp
|
||||||
libgit.cpp
|
libgit.cpp
|
||||||
git.cpp
|
git.cpp
|
||||||
|
templates.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(CMAKE_AUTOMOC ON)
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
@ -6,14 +6,7 @@
|
|||||||
|
|
||||||
#include "git.h"
|
#include "git.h"
|
||||||
#include "libgit.h"
|
#include "libgit.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
template<class... Ts>
|
|
||||||
struct overload : Ts... {
|
|
||||||
using Ts::operator()...;
|
|
||||||
};
|
|
||||||
template<class... Ts>
|
|
||||||
overload(Ts...) -> overload<Ts...>;
|
|
||||||
|
|
||||||
|
|
||||||
QDir Git::clone_setup()
|
QDir Git::clone_setup()
|
||||||
@ -29,7 +22,7 @@ QDir Git::clone_setup()
|
|||||||
|
|
||||||
bool Git::clone_tear_down(QDir tmp_dir)
|
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)
|
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)
|
bool Git::clone(QString url, QString path, mode_type mode) //, GitPlugin::RepoType type, QString pass)
|
||||||
{
|
{
|
||||||
auto v = overload {
|
auto v = overload {
|
||||||
[](const Unset& x) { return "Unset"; },
|
[](const Unset & x) { return "Unset"; },
|
||||||
[](const HTTP& x) { return "Unset"; },
|
[](const HTTP & x) { return "Unset"; },
|
||||||
[](const HTTPAuth& x) { return "HTTPAuth"; },
|
[](const HTTPAuth & x) { return "HTTPAuth"; },
|
||||||
[](const SSHAuth& x) { return "SSHAuth"; },
|
[](const SSHAuth & x) { return "SSHAuth"; },
|
||||||
[](const SSHKey& x) { return "SSHKey"; },
|
[](const SSHKey & x) { return "SSHKey"; },
|
||||||
};
|
};
|
||||||
qInfo() << "Cloning " << url << " to destination " << path << " using " << std::visit(v, mode);
|
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();
|
qDebug() << "Cloning " << url << " to tmp dir " << tmp_dir.absolutePath();
|
||||||
auto ret = LibGit::instance()->clone(url, tmp_dir.absolutePath()); // TODO Better error handling
|
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());
|
LibGit::instance()->set_mode(Unset());
|
||||||
|
|
||||||
return ret ;
|
return ret ;
|
||||||
@ -77,7 +72,8 @@ bool Git::clone_http(QString url, QString path) //, GitPlugin::RepoType type, QS
|
|||||||
return this->clone(url, path, mode);
|
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 };
|
HTTPAuth mode = { pass };
|
||||||
return this->clone(url, path, mode);
|
return this->clone(url, path, mode);
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,9 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "libgit.h"
|
#include "libgit.h"
|
||||||
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
template<class... Ts>
|
|
||||||
struct overload : Ts... {
|
|
||||||
using Ts::operator()...;
|
|
||||||
};
|
|
||||||
template<class... Ts>
|
|
||||||
overload(Ts...) -> overload<Ts...>;
|
|
||||||
|
|
||||||
LibGit::LibGit()
|
LibGit::LibGit()
|
||||||
{
|
{
|
||||||
@ -26,7 +21,8 @@ LibGit::~LibGit()
|
|||||||
git_libgit2_shutdown();
|
git_libgit2_shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LibGit::set_mode(mode_type type) {
|
void LibGit::set_mode(mode_type type)
|
||||||
|
{
|
||||||
this->mode = type;
|
this->mode = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,29 +32,34 @@ int LibGit::credentials_cb(git_cred **out, const char *url, const char *username
|
|||||||
// TODO : More precise Error Handling for UI
|
// TODO : More precise Error Handling for UI
|
||||||
auto instance = LibGit::instance();
|
auto instance = LibGit::instance();
|
||||||
auto v = overload {
|
auto v = overload {
|
||||||
[](const Unset& x) {
|
[](const Unset & x)
|
||||||
|
{
|
||||||
qDebug() << "credentials_cb : Unset ";
|
qDebug() << "credentials_cb : Unset ";
|
||||||
qWarning() << "credentials_cb : callback should never be call for Unset ";
|
qWarning() << "credentials_cb : callback should never be call for Unset ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
},
|
},
|
||||||
[](const HTTP& x) {
|
[](const HTTP & x)
|
||||||
|
{
|
||||||
qDebug() << "credentials_cb : HTTP ";
|
qDebug() << "credentials_cb : HTTP ";
|
||||||
qWarning() << "credentials_cb : callback should never be call for HTTP ";
|
qWarning() << "credentials_cb : callback should never be call for HTTP ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
},
|
},
|
||||||
[&out, &username_from_url](const HTTPAuth& x) {
|
[&out, &username_from_url](const HTTPAuth & x)
|
||||||
|
{
|
||||||
qDebug() << "credentials_cb : HTTPAuth ";
|
qDebug() << "credentials_cb : HTTPAuth ";
|
||||||
if(!username_from_url) {
|
if (!username_from_url) {
|
||||||
qWarning() << "credentials_cb : no username provided ";
|
qWarning() << "credentials_cb : no username provided ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
}
|
}
|
||||||
return git_cred_userpass_plaintext_new(out, username_from_url, x.pass.toLocal8Bit().constData());
|
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 ";
|
qWarning() << "credentials_cb : SSHAuth to be implemented ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
}, // TODO
|
}, // TODO
|
||||||
[&](const SSHKey& x) {
|
[&](const SSHKey & x)
|
||||||
|
{
|
||||||
qWarning() << "credentials_cb : SSHKey to be implemented ";
|
qWarning() << "credentials_cb : SSHKey to be implemented ";
|
||||||
return (int) GIT_EUSER;
|
return (int) GIT_EUSER;
|
||||||
} // TODO
|
} // TODO
|
||||||
|
@ -12,7 +12,9 @@ extern "C" {
|
|||||||
|
|
||||||
struct Unset { };
|
struct Unset { };
|
||||||
struct HTTP { };
|
struct HTTP { };
|
||||||
struct HTTPAuth { QString pass; };
|
struct HTTPAuth {
|
||||||
|
QString pass;
|
||||||
|
};
|
||||||
struct SSHAuth { };
|
struct SSHAuth { };
|
||||||
struct SSHKey { };
|
struct SSHKey { };
|
||||||
typedef std::variant<Unset, HTTP, HTTPAuth, SSHAuth, SSHKey> mode_type;
|
typedef std::variant<Unset, HTTP, HTTPAuth, SSHAuth, SSHKey> mode_type;
|
||||||
|
11
plugins/Git/utils.h
Normal file
11
plugins/Git/utils.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#ifndef UTILS_H
|
||||||
|
#define UTILS_H
|
||||||
|
|
||||||
|
template<class... Ts>
|
||||||
|
struct overload : Ts... {
|
||||||
|
using Ts::operator()...;
|
||||||
|
};
|
||||||
|
template<class... Ts>
|
||||||
|
overload(Ts...) -> overload<Ts...>;
|
||||||
|
|
||||||
|
#endif // UTILS_H
|
@ -19,10 +19,10 @@ MainView {
|
|||||||
//TODO use parameters to impove passphrase dialog
|
//TODO use parameters to impove passphrase dialog
|
||||||
var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml"));
|
var passphraseDialog = PopupUtils.open(Qt.resolvedUrl("dialogs/PassphraseDialog.qml"));
|
||||||
passphraseDialog.activateFocus();
|
passphraseDialog.activateFocus();
|
||||||
var validated = function (passphrase) {
|
var validated = function validated(passphrase) {
|
||||||
responsePassphraseDialog(false, passphrase);
|
responsePassphraseDialog(false, passphrase);
|
||||||
};
|
};
|
||||||
var canceled = function () {
|
var canceled = function canceled() {
|
||||||
responsePassphraseDialog(true, "");
|
responsePassphraseDialog(true, "");
|
||||||
};
|
};
|
||||||
passphraseDialog.validated.connect(validated);
|
passphraseDialog.validated.connect(validated);
|
||||||
|
@ -69,12 +69,10 @@ Page {
|
|||||||
text: i18n.tr('Clone')
|
text: i18n.tr('Clone')
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var ret = false;
|
var ret = false;
|
||||||
if(repoPasswordInput.text === "") {
|
if (repoPasswordInput.text === "")
|
||||||
ret = Git.clone_http(repoUrlInput.text, Pass.password_store);
|
ret = Git.clone_http(repoUrlInput.text, Pass.password_store);
|
||||||
} else {
|
else
|
||||||
ret = Git.clone_http_pass(repoUrlInput.text, Pass.password_store, repoPasswordInput.text);
|
ret = Git.clone_http_pass(repoUrlInput.text, Pass.password_store, repoPasswordInput.text);
|
||||||
}
|
|
||||||
|
|
||||||
if (ret)
|
if (ret)
|
||||||
PopupUtils.open(dialogImportGitCloneSuccess);
|
PopupUtils.open(dialogImportGitCloneSuccess);
|
||||||
else
|
else
|
||||||
|
@ -8,7 +8,8 @@
|
|||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
|
||||||
QString TestsUtils::getTempPath() {
|
QString TestsUtils::getTempPath()
|
||||||
|
{
|
||||||
qFatal("yp");
|
qFatal("yp");
|
||||||
// Get the system's temporary directory
|
// Get the system's temporary directory
|
||||||
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
QString tempDir = QStandardPaths::writableLocation(QStandardPaths::CacheLocation);
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
|
import Git 1.0
|
||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtTest 1.2
|
import QtTest 1.2
|
||||||
import Git 1.0
|
|
||||||
|
|
||||||
TestCase {
|
TestCase {
|
||||||
name: "git"
|
|
||||||
|
|
||||||
function test_git_clone() {
|
function test_git_clone() {
|
||||||
|
verify(Git.clone("", ""));
|
||||||
verify(Git.clone("",""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name: "git"
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,11 @@
|
|||||||
|
import Git 1.0
|
||||||
import QtQuick 2.9
|
import QtQuick 2.9
|
||||||
import QtTest 1.2
|
import QtTest 1.2
|
||||||
import Git 1.0
|
|
||||||
|
|
||||||
TestCase {
|
TestCase {
|
||||||
name: "git"
|
|
||||||
|
|
||||||
function test_git_clone() {
|
function test_git_clone() {
|
||||||
|
verify(Git.clone("", ""));
|
||||||
verify(Git.clone("",""));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name: "git"
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,12 @@ import TestUtils 1.0
|
|||||||
import Utils 1.0
|
import Utils 1.0
|
||||||
|
|
||||||
TestCase {
|
TestCase {
|
||||||
name: "utils"
|
|
||||||
|
|
||||||
function test_unzip() {
|
function test_unzip() {
|
||||||
var tempPath = TestUtils.getTempPath() + "/password-store";
|
var tempPath = TestUtils.getTempPath() + "/password-store";
|
||||||
var zipUrl = Qt.resolvedUrl("../assets/archive.zip");
|
var zipUrl = Qt.resolvedUrl("../assets/archive.zip");
|
||||||
var r = Utils.unzip(zipUrl, tempPath)
|
var r = Utils.unzip(zipUrl, tempPath);
|
||||||
verify(r, "Unzip return an error %1".arg(zipUrl))
|
verify(r, "Unzip return an error %1".arg(zipUrl));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name: "utils"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user