1#include "gitresetdialog.h"
2#include "ui_gitresetdialog.h"
3#include "gitmanager.h"
4#include "../widgets/infomessagebox.h"
5
6GitResetDialog::GitResetDialog(const QString& folder, QWidget *parent) :
7 QDialog(parent),
8 ui(new Ui::GitResetDialog),
9 mFolder(folder)
10{
11 ui->setupUi(this);
12}
13
14GitResetDialog::~GitResetDialog()
15{
16 delete ui;
17}
18
19int GitResetDialog::resetToCommit(const QString &commit)
20{
21 GitManager manager;
22 QString branch;
23 if (!manager.hasRepository(mFolder,branch))
24 return QDialog::Rejected;
25 ui->rbBranch->setEnabled(false);
26 ui->cbBranches->setEnabled(false);
27 ui->rbTag->setEnabled(false);
28 ui->cbTags->setEnabled(false);
29 ui->rbCommit->setChecked(true);
30 ui->cbCommits->addItem(commit);
31 ui->rbMixed->setChecked(true);
32 ui->grpTarget->setTitle(tr("Reset current branch \"%1\" to").arg(branch));
33 return exec();
34}
35
36void GitResetDialog::on_btnOk_clicked()
37{
38 GitManager manager;
39 GitResetStrategy strategy = GitResetStrategy::Mixed;
40 if (ui->rbSoft->isChecked())
41 strategy = GitResetStrategy::Soft;
42 else if (ui->rbHard->isChecked())
43 strategy = GitResetStrategy::Hard;
44 QString commit;
45 if (ui->rbCommit->isChecked())
46 commit = ui->cbCommits->currentText();
47 else if (ui->rbTag->isChecked())
48 commit = ui->cbTags->currentText();
49 else if (ui->rbBranch->isChecked())
50 commit = ui->cbBranches->currentText();
51 if (commit.isEmpty())
52 reject();
53 QString output;
54 bool result = manager.reset(mFolder,commit,strategy,output);
55 if (!output.trimmed().isEmpty()) {
56 InfoMessageBox infoBox;
57 infoBox.showMessage(output);
58 }
59 if (result)
60 accept();
61 else
62 reject();
63}
64
65
66void GitResetDialog::on_btnCancel_clicked()
67{
68 reject();
69}
70
71