Skip to content

Commit

Permalink
#278 Adding the basic rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
francescmm committed Nov 5, 2023
1 parent 2ce7019 commit 4beead6
Show file tree
Hide file tree
Showing 11 changed files with 125 additions and 3 deletions.
16 changes: 16 additions & 0 deletions src/big_widgets/GitQlientRepo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ GitQlientRepo::GitQlientRepo(const QSharedPointer<GitBase> &git, const QSharedPo
connect(mHistoryWidget, &HistoryWidget::signalOpenDiff, this, &GitQlientRepo::openCommitDiff);
connect(mHistoryWidget, &HistoryWidget::changesCommitted, this, &GitQlientRepo::onChangesCommitted);
connect(mHistoryWidget, &HistoryWidget::signalShowFileHistory, this, &GitQlientRepo::showFileHistory);
connect(mHistoryWidget, &HistoryWidget::signalRebaseConflict, mControls, &Controls::activateMergeWarning);
connect(mHistoryWidget, &HistoryWidget::signalRebaseConflict, this, &GitQlientRepo::showRebaseConflict);
connect(mHistoryWidget, &HistoryWidget::signalMergeConflicts, mControls, &Controls::activateMergeWarning);
connect(mHistoryWidget, &HistoryWidget::signalMergeConflicts, this, &GitQlientRepo::showWarningMerge);
connect(mHistoryWidget, &HistoryWidget::signalCherryPickConflict, mControls, &Controls::activateMergeWarning);
Expand Down Expand Up @@ -456,6 +458,20 @@ void GitQlientRepo::showWarningMerge()
mMergeWidget->configure(file.value(), MergeWidget::ConflictReason::Merge);
}

void GitQlientRepo::showRebaseConflict()
{
showMergeView();

const auto wipCommit = mGitQlientCache->commitInfo(ZERO_SHA);

WipHelper::update(mGitBase, mGitQlientCache);

const auto files = mGitQlientCache->revisionFile(ZERO_SHA, wipCommit.firstParent());

if (files)
mMergeWidget->configureForRebase();
}

// TODO: Optimize
void GitQlientRepo::showCherryPickConflict(const QStringList &shas)
{
Expand Down
3 changes: 3 additions & 0 deletions src/big_widgets/GitQlientRepo.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ class GitQlientRepo : public QFrame
*/
void showWarningMerge();

void showRebaseConflict();

/*!
* \brief Configures the merge widget when a conflict happens and is due to a cherry-pick. The conflicts are shown in
* the merge view.
Expand Down
1 change: 1 addition & 0 deletions src/big_widgets/HistoryWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ HistoryWidget::HistoryWidget(const QSharedPointer<GitCache> &cache, const QShare
commitSelected(rowIndex);
});
connect(mRepositoryView, &CommitHistoryView::signalAmendCommit, this, &HistoryWidget::onAmendCommit);
connect(mRepositoryView, &CommitHistoryView::signalRebaseConflict, this, &HistoryWidget::signalRebaseConflict);
connect(mRepositoryView, &CommitHistoryView::signalMergeRequired, this, &HistoryWidget::mergeBranch);
connect(mRepositoryView, &CommitHistoryView::mergeSqushRequested, this, &HistoryWidget::mergeSquashBranch);
connect(mRepositoryView, &CommitHistoryView::signalCherryPickConflict, this,
Expand Down
6 changes: 6 additions & 0 deletions src/big_widgets/HistoryWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ class HistoryWidget : public QFrame
\brief Signal triggered when the user performs a merge and it contains conflicts.
*/
void signalMergeConflicts();

/**
* @brief Signal triggered when trying to rebase and a conflict happens.
*/
void signalRebaseConflict();

/*!
* \brief signalConflict Signal triggered when trying to cherry-pick or pull and a conflict happens.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/big_widgets/MergeWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ void MergeWidget::configureForCherryPick(const RevisionFiles &files, const QStri
fillButtonFileList(files);
}

void MergeWidget::configureForRebase()
{

}

void MergeWidget::fillButtonFileList(const RevisionFiles &files)
{
for (auto i = 0; i < files.count(); ++i)
Expand Down
2 changes: 2 additions & 0 deletions src/big_widgets/MergeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class MergeWidget : public QFrame
*/
void configureForCherryPick(const RevisionFiles &files, const QStringList &pendingShas = QStringList());

void configureForRebase();

private:
QSharedPointer<GitCache> mGitQlientCache;
QSharedPointer<GitBase> mGit;
Expand Down
2 changes: 1 addition & 1 deletion src/git
Submodule git updated 3 files
+2 −2 GitLocal.cpp
+18 −0 GitMerge.cpp
+2 −0 GitMerge.h
74 changes: 72 additions & 2 deletions src/history/CommitHistoryContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <GitConfig.h>
#include <GitHistory.h>
#include <GitLocal.h>
#include <GitMerge.h>
#include <GitPatches.h>
#include <GitQlientSettings.h>
#include <GitQlientStyles.h>
Expand Down Expand Up @@ -386,6 +387,67 @@ void CommitHistoryContextMenu::cherryPickCommit()
}
}

void CommitHistoryContextMenu::rebase()
{
const auto action = qobject_cast<QAction *>(sender());
const auto branchToRebase = action->data().toString();

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
QScopedPointer<GitMerge> git(new GitMerge(mGit));
const auto ret = git->rebase(branchToRebase);
QApplication::restoreOverrideCursor();

if (ret.success)
{
if (!ret.output.isEmpty())
{
if (ret.output.contains("error: could not apply", Qt::CaseInsensitive)
|| ret.output.contains(" conflict", Qt::CaseInsensitive))
{
QMessageBox msgBox(
QMessageBox::Warning, tr("Rebase status"),
QString(tr(
"There were problems during the rebase. Please, see the detailed description for more "
"information.<br><br>GitQlient cannot handle these conflicts at the moment.<br><br>The rebase will "
"be aborted.")),
QMessageBox::Ok, this);
msgBox.setDetailedText(ret.output);
msgBox.setStyleSheet(GitQlientStyles::getStyles());
msgBox.exec();

git->rebaseAbort();

// TODO: For future implementation of manage rebase conflics
// emit signalRebaseConflict();
}
}
else
{
WipHelper::update(mGit, mCache);

emit fullReload();
}
}
else
{
QMessageBox msgBox(
QMessageBox::Critical, tr("Rebase failed"),
QString(
tr("There were problems during the rebase. Please, see the detailed description for more "
"information.<br><br>GitQlient cannot handle these conflicts at the moment.<br><br>The rebase will be "
"aborted.")),
QMessageBox::Ok, this);
msgBox.setDetailedText(ret.output);
msgBox.setStyleSheet(GitQlientStyles::getStyles());
msgBox.exec();

git->rebaseAbort();

// TODO: For future implementation of manage rebase conflics
// emit signalRebaseConflict();
}
}

void CommitHistoryContextMenu::applyPatch()
{
const QString fileName(QFileDialog::getOpenFileName(this, tr("Select a patch to apply")));
Expand Down Expand Up @@ -667,17 +729,25 @@ void CommitHistoryContextMenu::addBranchActions(const QString &sha)

if (QScopedPointer<GitBranches> git(new GitBranches(mGit)); !git->isCommitInCurrentGeneologyTree(sha))
{
const auto rebaseMenu = !branchTracking.isEmpty() ? addMenu(tr("Rebase")) : this;
const auto mergeMenu = !branchTracking.isEmpty() ? addMenu(tr("Merge")) : this;
const auto squashMergeMenu = !branchTracking.isEmpty() ? addMenu(tr("Squash-merge")) : this;

for (const auto &pair : branchTracking.toStdMap())
{
if (!pair.first.isEmpty() && pair.first != currentBranch
&& pair.first != QString("origin/%1").arg(currentBranch))
{
// If is the last commit of a branch
const auto mergeBranchAction = addAction(QString(tr("Merge %1")).arg(pair.first));
const auto rebaseBranchAction = rebaseMenu->addAction(QString(tr("%1")).arg(pair.first));
rebaseBranchAction->setData(pair.first);
connect(rebaseBranchAction, &QAction::triggered, this, &CommitHistoryContextMenu::rebase);

const auto mergeBranchAction = mergeMenu->addAction(QString(tr("%1")).arg(pair.first));
mergeBranchAction->setData(pair.first);
connect(mergeBranchAction, &QAction::triggered, this, &CommitHistoryContextMenu::merge);

const auto mergeSquashBranchAction = addAction(QString(tr("Squash-merge %1")).arg(pair.first));
const auto mergeSquashBranchAction = squashMergeMenu->addAction(QString(tr("%1")).arg(pair.first));
mergeSquashBranchAction->setData(pair.first);
connect(mergeSquashBranchAction, &QAction::triggered, this, &CommitHistoryContextMenu::mergeSquash);
}
Expand Down
12 changes: 12 additions & 0 deletions src/history/CommitHistoryContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ class CommitHistoryContextMenu : public QMenu
\param sha The SHA of the commit to amend.
*/
void signalAmendCommit(const QString &sha);

/**
* @brief Signal triggered when trying to rebase and a conflict happens.
*/
void signalRebaseConflict();

/*!
\brief Signal triggered when a merge has been requested. Since it involves a lot of changes at UI level this action
is not performed here.
Expand Down Expand Up @@ -187,6 +193,12 @@ class CommitHistoryContextMenu : public QMenu
\brief Resets the current branch reference into the selected commit overriding all changes.
*/
void resetHard();

/**
* @brief Rebases the current branch over the selected branch.
*/
void rebase();

/*!
\brief Merges the \p branchFrom into the current branch.
Expand Down
1 change: 1 addition & 0 deletions src/history/CommitHistoryView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ void CommitHistoryView::showContextMenu(const QPoint &pos)
connect(menu, &CommitHistoryContextMenu::signalOpenDiff, this, &CommitHistoryView::signalOpenDiff);
connect(menu, &CommitHistoryContextMenu::signalAmendCommit, this, &CommitHistoryView::signalAmendCommit);
connect(menu, &CommitHistoryContextMenu::signalMergeRequired, this, &CommitHistoryView::signalMergeRequired);
connect(menu, &CommitHistoryContextMenu::signalRebaseConflict, this, &CommitHistoryView::signalRebaseConflict);
connect(menu, &CommitHistoryContextMenu::mergeSqushRequested, this, &CommitHistoryView::mergeSqushRequested);
connect(menu, &CommitHistoryContextMenu::signalCherryPickConflict, this,
&CommitHistoryView::signalCherryPickConflict);
Expand Down
6 changes: 6 additions & 0 deletions src/history/CommitHistoryView.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class CommitHistoryView : public QTreeView
\param sha The SHA of the commit to amend.
*/
void signalAmendCommit(const QString &sha);

/**
* @brief Signal triggered when trying to rebase and a conflict happens.
*/
void signalRebaseConflict();

/*!
\brief Signal triggered when a merge has been requested. Since it involves a lot of changes at UI level this action
is not performed here.
Expand Down

0 comments on commit 4beead6

Please sign in to comment.