diff --git a/NEWS.md b/NEWS.md index 2cef7280..cc067443 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ Red Panda C++ Version 0.14.3 - enhancement: git - commit - enhancement: git - restore - enhancement: git - branch / switch + - enhancement: git - merge - fix: compiler set index not correctly saved, when remove compiler sets in options dialog - enhancement: when create a repository in a project, auto add it's files to the repository - enhancement: when add files to project, auto add it to git (if the project has a git repository) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index 2fe16834..4d20b552 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -93,6 +93,7 @@ SOURCES += \ toolsmanager.cpp \ vcs/gitbranchdialog.cpp \ vcs/gitmanager.cpp \ + vcs/gitmergedialog.cpp \ vcs/gitrepository.cpp \ vcs/gitutils.cpp \ widgets/aboutdialog.cpp \ @@ -226,6 +227,7 @@ HEADERS += \ toolsmanager.h \ vcs/gitbranchdialog.h \ vcs/gitmanager.h \ + vcs/gitmergedialog.h \ vcs/gitrepository.h \ vcs/gitutils.h \ widgets/aboutdialog.h \ @@ -322,6 +324,7 @@ FORMS += \ settingsdialog/toolsgeneralwidget.ui \ settingsdialog/toolsgitwidget.ui \ vcs/gitbranchdialog.ui \ + vcs/gitmergedialog.ui \ widgets/aboutdialog.ui \ widgets/cpudialog.ui \ mainwindow.ui \ diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 14a62e9e..39955295 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -170,7 +170,9 @@ QStringList GitManager::listBranches(const QString &folder, int ¤t) return temp; } -bool GitManager::switchToBranch(const QString &folder, const QString &branch, bool create, bool force, bool merge, bool track, bool noTrack, bool forceCreation) +bool GitManager::switchToBranch(const QString &folder, const QString &branch, + bool create, bool force, bool merge, bool track, + bool noTrack, bool forceCreation, QString& output) { QStringList args; args.append("switch"); @@ -187,8 +189,51 @@ bool GitManager::switchToBranch(const QString &folder, const QString &branch, bo else if (noTrack) args.append("--no-track"); args.append(branch); + output = runGit(folder,args); + return !output.startsWith("error") && !output.startsWith("fatal"); +} + +bool GitManager::merge(const QString &folder, const QString &commit, bool squash, + bool fastForwardOnly, bool noFastForward, bool noCommit, + QString& output, + const QString& commitMessage) +{ + QStringList args; + args.append("merge"); + if (squash) + args.append("--squash"); + if (fastForwardOnly) + args.append("--ff-only"); + else if (noFastForward) + args.append("--no-ff"); + if (noCommit) + args.append("--no-commit"); + if (!commitMessage.isEmpty() + && commitMessage != QObject::tr("")){ + args.append("-m"); + args.append(commitMessage); + } + args.append(commit); + output = runGit(folder,args); + return !output.startsWith("error") && !output.startsWith("fatal"); +} + +bool GitManager::continueMerge(const QString &folder) +{ + QStringList args; + args.append("merge"); + args.append("--continue"); QString output = runGit(folder,args); return !output.startsWith("error") && !output.startsWith("fatal"); + +} + +void GitManager::abortMerge(const QString &folder) +{ + QStringList args; + args.append("merge"); + args.append("--abort"); + runGit(folder,args); } void GitManager::clone(const QString &folder, const QString &url) diff --git a/RedPandaIDE/vcs/gitmanager.h b/RedPandaIDE/vcs/gitmanager.h index 3641ee37..59c93edf 100644 --- a/RedPandaIDE/vcs/gitmanager.h +++ b/RedPandaIDE/vcs/gitmanager.h @@ -38,7 +38,15 @@ public: QStringList listChangedFiles(const QString& folder); QStringList listBranches(const QString& folder, int& current); bool switchToBranch(const QString& folder, const QString& branch, bool create, - bool force, bool merge, bool track, bool noTrack, bool forceCreation ); + bool force, bool merge, bool track, bool noTrack, bool forceCreation, + QString& output); + bool merge(const QString& folder, const QString& commit, bool squash, bool fastForwardOnly, + bool noFastForward, bool noCommit, + QString& output, + const QString& commitMessage=QString() + ); + bool continueMerge(const QString& folder); + void abortMerge(const QString& folder); void clone(const QString& folder, const QString& url); void commit(const QString& folder, const QString& message, bool autoStage); diff --git a/RedPandaIDE/vcs/gitmergedialog.cpp b/RedPandaIDE/vcs/gitmergedialog.cpp new file mode 100644 index 00000000..507a3b10 --- /dev/null +++ b/RedPandaIDE/vcs/gitmergedialog.cpp @@ -0,0 +1,18 @@ +#include "gitmergedialog.h" +#include "ui_gitmergedialog.h" +#include "gitmanager.h" + +GitMergeDialog::GitMergeDialog(const QString& folder, QWidget *parent) : + QDialog(parent), + ui(new Ui::GitMergeDialog), + mFolder(folder) +{ + ui->setupUi(this); + mManager = new GitManager(); +} + +GitMergeDialog::~GitMergeDialog() +{ + delete mManager; + delete ui; +} diff --git a/RedPandaIDE/vcs/gitmergedialog.h b/RedPandaIDE/vcs/gitmergedialog.h new file mode 100644 index 00000000..27a8a363 --- /dev/null +++ b/RedPandaIDE/vcs/gitmergedialog.h @@ -0,0 +1,25 @@ +#ifndef GITMERGEDIALOG_H +#define GITMERGEDIALOG_H + +#include + +namespace Ui { +class GitMergeDialog; +} + +class GitManager; +class GitMergeDialog : public QDialog +{ + Q_OBJECT + +public: + explicit GitMergeDialog(const QString& folder, QWidget *parent = nullptr); + ~GitMergeDialog(); + +private: + Ui::GitMergeDialog *ui; + GitManager *mManager; + QString mFolder; +}; + +#endif // GITMERGEDIALOG_H diff --git a/RedPandaIDE/vcs/gitmergedialog.ui b/RedPandaIDE/vcs/gitmergedialog.ui new file mode 100644 index 00000000..a4312308 --- /dev/null +++ b/RedPandaIDE/vcs/gitmergedialog.ui @@ -0,0 +1,147 @@ + + + GitMergeDialog + + + + 0 + 0 + 597 + 508 + + + + Dialog + + + + + + From + + + + + + Branch + + + + + + + + 0 + 0 + + + + + + + + + + + Option + + + + + + No Commit + + + + + + + Squash + + + + + + + No Fast Forward + + + + + + + Fast Forward Only + + + + + + + + + + Merge Message + + + + + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Ok + + + + + + + PushButton + + + + + + + + + + + diff --git a/RedPandaIDE/vcs/gitutils.h b/RedPandaIDE/vcs/gitutils.h index d42214d6..2453ec9a 100644 --- a/RedPandaIDE/vcs/gitutils.h +++ b/RedPandaIDE/vcs/gitutils.h @@ -9,4 +9,25 @@ enum class GitResetStrategy { Keep }; +enum class GitMergeStrategy { + Resolve, + Recursive, + Ours, + Subtree +}; + +enum class GitMergeStrategyOption { + Ours, + Theirs, + Patience, + Ignore_Space_Change, + Ignore_All_Space, + Ignore_Space_At_Eol, + Renormalize, + No_Renormalize, + Find_Names, + Rename_Threshold, + Subtree +}; + #endif // GITUTILS_H