Skip to content

Commit

Permalink
Merge branch 'master' of github.com:francescmm/GitQlient
Browse files Browse the repository at this point in the history
  • Loading branch information
francescmm committed May 9, 2020
2 parents fe4870c + d8cdf75 commit 9647b9d
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ git:
sudo: required
dist: xenial
env:
- VERSION="1.0.0"
- VERSION="1.1.0"
install:
- bash ci-scripts/$TRAVIS_OS_NAME/install.sh
script:
Expand Down
50 changes: 45 additions & 5 deletions src/aux_widgets/CreateRepoDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <GitQlientSettings.h>

#include <QFileDialog>
#include <QMessageBox>
#include <QLogger.h>

using namespace QLogger;

CreateRepoDlg::CreateRepoDlg(CreateRepoDlgType type, QSharedPointer<GitConfig> git, QWidget *parent)
: QDialog(parent)
Expand Down Expand Up @@ -39,7 +43,9 @@ CreateRepoDlg::CreateRepoDlg(CreateRepoDlgType type, QSharedPointer<GitConfig> g

GitQlientSettings settings;
const auto configGitUser = settings.value("GitConfigRepo", true).toBool();

ui->cbGitUser->setChecked(configGitUser);
showGitControls();
}

CreateRepoDlg::~CreateRepoDlg()
Expand Down Expand Up @@ -84,26 +90,52 @@ void CreateRepoDlg::showGitControls()

void CreateRepoDlg::accept()
{
auto url = ui->leURL->text();
auto path = ui->lePath->text();
auto repoName = ui->leRepoName->text();

if (!url.isEmpty() && !path.isEmpty() && !repoName.isEmpty())
if (!path.isEmpty() && !repoName.isEmpty())
{
repoName.replace(" ", "\\ ");
const auto fullPath = path.append("/").append(repoName);

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));

auto ret = false;
GitExecResult ret;
QString actionApplied;

if (mType == CreateRepoDlgType::CLONE)
ret = mGit->clone(url, fullPath);
{
const auto url = ui->leURL->text();

if (!url.isEmpty())
{
actionApplied = "clone";

QDir dir(fullPath);

if (!dir.exists())
dir.mkpath(fullPath);

ret = mGit->clone(url, fullPath);
}
else
{
const auto msg = QString("You need to provider a URL to clone a repository.");

QMessageBox::critical(this, tr("Nor URL provided"), msg);

QLog_Error("UI", msg);
}
}
else if (mType == CreateRepoDlgType::INIT)
{
actionApplied = "init";
ret = mGit->initRepo(fullPath);
}

QApplication::restoreOverrideCursor();

if (ret)
if (ret.success)
{
if (ui->cbGitUser->isChecked())
mGit->setLocalUserInfo({ ui->leGitName->text(), ui->leGitEmail->text() });
Expand All @@ -113,5 +145,13 @@ void CreateRepoDlg::accept()

QDialog::accept();
}
else
{
const auto msg = ret.output.toString();

QMessageBox::critical(this, tr("Error when %1").arg(actionApplied), msg);

QLog_Error("UI", msg);
}
}
}
2 changes: 1 addition & 1 deletion src/big_widgets/GitQlientRepo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ void GitQlientRepo::setRepository(const QString &newDir)

QScopedPointer<GitConfig> git(new GitConfig(mGitBase));

if (!git->getGlobalUserInfo().isValid())
if (!git->getGlobalUserInfo().isValid() && !git->getLocalUserInfo().isValid())
{
QLog_Info("UI", QString("Configuring Git..."));

Expand Down
2 changes: 1 addition & 1 deletion src/branches/BranchTreeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void BranchTreeWidget::showBranchesContextMenu(const QPoint &pos)
auto currentBranch = mGit->getCurrentBranch();
auto selectedBranch = item->data(0, Qt::UserRole + 1).toString();

if (!mLocal)
if (mLocal)
selectedBranch = selectedBranch.remove("origin/");

const auto menu = new BranchContextMenu({ currentBranch, selectedBranch, mLocal, mGit }, this);
Expand Down
29 changes: 28 additions & 1 deletion src/config/GitConfigDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <GitConfig.h>
#include <GitQlientStyles.h>

#include <QCloseEvent>
#include <QKeyEvent>

GitConfigDlg::GitConfigDlg(const QSharedPointer<GitBase> &gitBase, QWidget *parent)
: QDialog(parent)
, ui(new Ui::GitConfigDlg)
Expand All @@ -13,7 +16,6 @@ GitConfigDlg::GitConfigDlg(const QSharedPointer<GitBase> &gitBase, QWidget *pare
ui->setupUi(this);

setWindowFlags(Qt::FramelessWindowHint);
setAttribute(Qt::WA_DeleteOnClose);
setStyleSheet(GitQlientStyles::getStyles());

QScopedPointer<GitConfig> git(new GitConfig(mGit));
Expand All @@ -35,6 +37,31 @@ GitConfigDlg::~GitConfigDlg()
delete ui;
}

void GitConfigDlg::keyPressEvent(QKeyEvent *e)
{
const auto key = e->key();

if (key == Qt::Key_Escape)
return;

QDialog::keyPressEvent(e);
}

void GitConfigDlg::closeEvent(QCloseEvent *e)
{
if (!mPrepareToClose)
e->ignore();
else
QDialog::closeEvent(e);
}

void GitConfigDlg::close()
{
mPrepareToClose = true;

QDialog::close();
}

void GitConfigDlg::accept()
{
QScopedPointer<GitConfig> git(new GitConfig(mGit));
Expand Down
19 changes: 19 additions & 0 deletions src/config/GitConfigDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,28 @@ class GitConfigDlg : public QDialog
*/
~GitConfigDlg() override;

/**
* @brief Detects the press event to avoid closing the dialog when the Esc key is pressed.
*
* @param e The press event
*/
void keyPressEvent(QKeyEvent *e) override;
/**
* @brief Detects the close event to filter the close event and only close the dialog if the user clicked on the
* button.
*
* @param e The close event
*/
void closeEvent(QCloseEvent *e) override;
/**
* @brief Closes the dialog by user's action.
*/
void close();

private:
Ui::GitConfigDlg *ui;
QSharedPointer<GitBase> mGit;
bool mPrepareToClose = false;

/*!
\brief Validates the data input by the user and stores it if correct.
Expand Down
15 changes: 11 additions & 4 deletions src/git/GitConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@ GitExecResult GitConfig::setLocalData(const QString &key, const QString &value)
return mGitBase->run(QString("git config --local %1 \"%2\"").arg(key, value));
}

bool GitConfig::clone(const QString &url, const QString &fullPath)
GitExecResult GitConfig::clone(const QString &url, const QString &fullPath)
{
const auto asyncRun = new GitCloneProcess(mGitBase->getWorkingDir());
connect(asyncRun, &GitCloneProcess::signalProgress, this, &GitConfig::signalCloningProgress, Qt::DirectConnection);

return asyncRun->run(QString("git clone --progress %1 %2").arg(url, fullPath)).success;
mGitBase->setWorkingDir(fullPath);

return asyncRun->run(QString("git clone --progress %1 %2").arg(url, fullPath));
}

bool GitConfig::initRepo(const QString &fullPath)
GitExecResult GitConfig::initRepo(const QString &fullPath)
{
return mGitBase->run(QString("git init %1").arg(fullPath)).success;
const auto ret = mGitBase->run(QString("git init %1").arg(fullPath));

if (ret.success)
mGitBase->setWorkingDir(fullPath);

return ret;
}

GitExecResult GitConfig::getLocalConfig() const
Expand Down
4 changes: 2 additions & 2 deletions src/git/GitConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class GitConfig : public QObject
GitUserInfo getLocalUserInfo() const;
void setLocalUserInfo(const GitUserInfo &info);
GitExecResult setLocalData(const QString &key, const QString &value);
bool clone(const QString &url, const QString &fullPath);
bool initRepo(const QString &fullPath);
GitExecResult clone(const QString &url, const QString &fullPath);
GitExecResult initRepo(const QString &fullPath);
GitExecResult getLocalConfig() const;
GitExecResult getGlobalConfig() const;
GitExecResult getRemoteForBranch(const QString &branch);
Expand Down

0 comments on commit 9647b9d

Please sign in to comment.