2022-02-22 09:16:20 +08:00
|
|
|
#include "gitresetdialog.h"
|
|
|
|
#include "ui_gitresetdialog.h"
|
2022-02-22 17:12:54 +08:00
|
|
|
#include "gitmanager.h"
|
|
|
|
#include "../widgets/infomessagebox.h"
|
2022-02-22 09:16:20 +08:00
|
|
|
|
|
|
|
GitResetDialog::GitResetDialog(const QString& folder, QWidget *parent) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::GitResetDialog),
|
|
|
|
mFolder(folder)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GitResetDialog::~GitResetDialog()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
int GitResetDialog::resetToCommit(const QString &commit)
|
|
|
|
{
|
2022-02-22 17:12:54 +08:00
|
|
|
GitManager manager;
|
|
|
|
QString branch;
|
|
|
|
if (!manager.hasRepository(mFolder,branch))
|
|
|
|
return QDialog::Rejected;
|
2022-02-22 09:16:20 +08:00
|
|
|
ui->rbBranch->setEnabled(false);
|
|
|
|
ui->cbBranches->setEnabled(false);
|
|
|
|
ui->rbTag->setEnabled(false);
|
|
|
|
ui->cbTags->setEnabled(false);
|
|
|
|
ui->rbCommit->setChecked(true);
|
|
|
|
ui->cbCommits->addItem(commit);
|
|
|
|
ui->rbMixed->setChecked(true);
|
2022-02-22 17:12:54 +08:00
|
|
|
ui->grpTarget->setTitle(tr("Reset current branch \"%1\" to").arg(branch));
|
2022-02-22 09:16:20 +08:00
|
|
|
return exec();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GitResetDialog::on_btnOk_clicked()
|
|
|
|
{
|
2022-02-22 17:12:54 +08:00
|
|
|
GitManager manager;
|
|
|
|
GitResetStrategy strategy = GitResetStrategy::Mixed;
|
|
|
|
if (ui->rbSoft->isChecked())
|
|
|
|
strategy = GitResetStrategy::Soft;
|
|
|
|
else if (ui->rbHard->isChecked())
|
|
|
|
strategy = GitResetStrategy::Hard;
|
|
|
|
QString commit;
|
|
|
|
if (ui->rbCommit->isChecked())
|
|
|
|
commit = ui->cbCommits->currentText();
|
|
|
|
else if (ui->rbTag->isChecked())
|
|
|
|
commit = ui->cbTags->currentText();
|
|
|
|
else if (ui->rbBranch->isChecked())
|
|
|
|
commit = ui->cbBranches->currentText();
|
|
|
|
if (commit.isEmpty())
|
|
|
|
reject();
|
|
|
|
QString output;
|
|
|
|
bool result = manager.reset(mFolder,commit,strategy,output);
|
|
|
|
if (!output.trimmed().isEmpty()) {
|
|
|
|
InfoMessageBox infoBox;
|
|
|
|
infoBox.showMessage(output);
|
|
|
|
}
|
|
|
|
if (result)
|
|
|
|
accept();
|
|
|
|
else
|
|
|
|
reject();
|
2022-02-22 09:16:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GitResetDialog::on_btnCancel_clicked()
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|