diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 0bcace3b..499c01e4 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -6896,6 +6896,7 @@ void MainWindow::on_actionGit_Log_triggered() return; GitLogDialog dialog(folder); if (dialog.exec()==QDialog::Accepted) { + qDebug()<<"yes"; //update project view if (mProject) { mProject->model()->beginUpdate(); diff --git a/RedPandaIDE/vcs/gitlogdialog.cpp b/RedPandaIDE/vcs/gitlogdialog.cpp index 999021c6..a00ea15b 100644 --- a/RedPandaIDE/vcs/gitlogdialog.cpp +++ b/RedPandaIDE/vcs/gitlogdialog.cpp @@ -1,6 +1,7 @@ #include "gitlogdialog.h" #include "ui_gitlogdialog.h" #include "gitmanager.h" +#include "gitresetdialog.h" #include @@ -77,6 +78,20 @@ QVariant GitLogModel::headerData(int section, Qt::Orientation orientation, int r return QVariant(); } +PGitCommitInfo GitLogModel::commitInfo(const QModelIndex &index) +{ + if (!index.isValid()) + return PGitCommitInfo(); + int row = index.row(); + GitManager manager; + QList listCommitInfos = + manager.log(mFolder,row,1); + if (listCommitInfos.isEmpty()) { + return PGitCommitInfo(); + } + return listCommitInfos[0]; +} + const QString &GitLogModel::folder() const { return mFolder; @@ -94,10 +109,10 @@ void GitLogDialog::onLogsContextMenu(const QPoint &pos) GitManager manager; if (!manager.hasRepository(mModel.folder(), branch)) return; - menu.addAction(ui->actionRevert); +// menu.addAction(ui->actionRevert); menu.addAction(ui->actionReset); - menu.addAction(ui->actionBranch); - menu.addAction(ui->actionTag); +// menu.addAction(ui->actionBranch); +// menu.addAction(ui->actionTag); ui->actionReset->setText(tr("Reset \"%1\" to this...").arg(branch)); ui->actionRevert->setText(tr("Revert \"%1\" to this...").arg(branch)); ui->actionBranch->setText(tr("Create Branch at this version...")); @@ -105,3 +120,15 @@ void GitLogDialog::onLogsContextMenu(const QPoint &pos) menu.exec(ui->tblLogs->mapToGlobal(pos)); } + +void GitLogDialog::on_actionReset_triggered() +{ + QModelIndex index = ui->tblLogs->currentIndex(); + if (!index.isValid()) + return; + PGitCommitInfo commitInfo = mModel.commitInfo(index); + GitResetDialog resetDialog(mModel.folder()); + if (resetDialog.resetToCommit(commitInfo->commitHash)==QDialog::Accepted) + accept(); +} + diff --git a/RedPandaIDE/vcs/gitlogdialog.h b/RedPandaIDE/vcs/gitlogdialog.h index 43b1995c..918b79bf 100644 --- a/RedPandaIDE/vcs/gitlogdialog.h +++ b/RedPandaIDE/vcs/gitlogdialog.h @@ -20,12 +20,12 @@ public: int columnCount(const QModelIndex &parent) const override; QVariant data(const QModelIndex &index, int role) const override; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; + PGitCommitInfo commitInfo(const QModelIndex &index); const QString &folder() const; private: QString mFolder; int mCount; - QMap mGitCommitInfos; }; class GitLogDialog : public QDialog @@ -40,6 +40,8 @@ private slots: void on_btnClose_clicked(); void onLogsContextMenu(const QPoint &pos); + void on_actionReset_triggered(); + private: Ui::GitLogDialog *ui; GitLogModel mModel; diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index e9169dec..faf16c18 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -148,7 +148,7 @@ QList GitManager::log(const QString &folder, int start, int coun QStringList args; args.append("log"); args.append("--skip"); - args.append(QString("%1").arg(start-1)); + args.append(QString("%1").arg(start)); args.append("-n"); args.append(QString("%1").arg(count)); args.append("--format=medium"); @@ -332,7 +332,9 @@ void GitManager::revert(const QString &folder) runGit(folder,args); } -void GitManager::reset(const QString &folder, const QString &commit, GitResetStrategy strategy) +bool GitManager::reset(const QString &folder, const QString &commit, + GitResetStrategy strategy, + QString& ouput) { //todo reset type QStringList args; @@ -355,7 +357,8 @@ void GitManager::reset(const QString &folder, const QString &commit, GitResetStr break; } args.append(commit); - runGit(folder,args); + QString output = runGit(folder,args); + return !output.startsWith("error") && !output.startsWith("fatal"); } bool GitManager::isValid() diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index c3a3756c..882cedbc 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -56,7 +56,7 @@ public: void clone(const QString& folder, const QString& url); void commit(const QString& folder, const QString& message, bool autoStage); void revert(const QString& folder); - void reset(const QString& folder, const QString& commit, GitResetStrategy strategy); + bool reset(const QString& folder, const QString& commit, GitResetStrategy strategy, QString& output); bool isValid(); diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index ecb902eb..c56c9ab7 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -72,11 +72,6 @@ void GitRepository::revert() mManager->revert(mRealFolder); } -void GitRepository::reset(const QString &commit, GitResetStrategy strategy) -{ - mManager->reset(mRealFolder,commit,strategy); -} - void GitRepository::setFolder(const QString &newFolder) { mFolder = newFolder; diff --git a/RedPandaIDE/vcs/gitrepository.h b/RedPandaIDE/vcs/gitrepository.h index b1101c91..d4521158 100644 --- a/RedPandaIDE/vcs/gitrepository.h +++ b/RedPandaIDE/vcs/gitrepository.h @@ -63,7 +63,6 @@ public: void clone(const QString& url); void commit(const QString& message, bool autoStage=true); void revert(); - void reset(const QString& commit, GitResetStrategy strategy); void setFolder(const QString &newFolder); diff --git a/RedPandaIDE/vcs/gitresetdialog.cpp b/RedPandaIDE/vcs/gitresetdialog.cpp index dd4e5d0f..0f61236c 100644 --- a/RedPandaIDE/vcs/gitresetdialog.cpp +++ b/RedPandaIDE/vcs/gitresetdialog.cpp @@ -1,5 +1,7 @@ #include "gitresetdialog.h" #include "ui_gitresetdialog.h" +#include "gitmanager.h" +#include "../widgets/infomessagebox.h" GitResetDialog::GitResetDialog(const QString& folder, QWidget *parent) : QDialog(parent), @@ -16,6 +18,10 @@ GitResetDialog::~GitResetDialog() int GitResetDialog::resetToCommit(const QString &commit) { + GitManager manager; + QString branch; + if (!manager.hasRepository(mFolder,branch)) + return QDialog::Rejected; ui->rbBranch->setEnabled(false); ui->cbBranches->setEnabled(false); ui->rbTag->setEnabled(false); @@ -23,12 +29,37 @@ int GitResetDialog::resetToCommit(const QString &commit) ui->rbCommit->setChecked(true); ui->cbCommits->addItem(commit); ui->rbMixed->setChecked(true); + ui->grpTarget->setTitle(tr("Reset current branch \"%1\" to").arg(branch)); return exec(); } void GitResetDialog::on_btnOk_clicked() { - accept(); + 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(); } diff --git a/RedPandaIDE/widgets/infomessagebox.cpp b/RedPandaIDE/widgets/infomessagebox.cpp index 983b0701..d8dbfc30 100644 --- a/RedPandaIDE/widgets/infomessagebox.cpp +++ b/RedPandaIDE/widgets/infomessagebox.cpp @@ -18,6 +18,12 @@ InfoMessageBox::~InfoMessageBox() delete ui; } +void InfoMessageBox::showMessage(const QString message) +{ + setMessage(message); + exec(); +} + void InfoMessageBox::on_btnOk_clicked() { accept(); diff --git a/RedPandaIDE/widgets/infomessagebox.h b/RedPandaIDE/widgets/infomessagebox.h index 252c9044..57c5aeb4 100644 --- a/RedPandaIDE/widgets/infomessagebox.h +++ b/RedPandaIDE/widgets/infomessagebox.h @@ -15,6 +15,7 @@ public: explicit InfoMessageBox(QWidget *parent = nullptr); void setMessage(const QString message); ~InfoMessageBox(); + void showMessage(const QString message); private slots: void on_btnOk_clicked();