Skip to content

Commit

Permalink
Rebase: Use original commit message as default message
Browse files Browse the repository at this point in the history
Merge pull request Murmele#674 from Murmele/rebase
  • Loading branch information
Murmele authored Dec 10, 2023
2 parents 71da998 + b4e9885 commit 66bc256
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/ui/DetailView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,7 @@ DetailView::DetailView(const git::Repository &repo, QWidget *parent)
mDetail->setVisible(false);
layout->addWidget(mDetail);

// Shown when a commit is selected
mDetail->addWidget(new CommitDetail(this));

mAuthorLabel = new QLabel(this);
Expand All @@ -508,6 +509,7 @@ DetailView::DetailView(const git::Repository &repo, QWidget *parent)
&DetailView::authorLinkActivated);
updateAuthor();

// Shown when the working directory is dirty
mCommitEditor = new CommitEditor(repo, this);

auto editorFrame = new QWidget(this);
Expand Down
3 changes: 3 additions & 0 deletions src/ui/RepoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,9 @@ void RepoView::rebaseConflict(const git::Rebase rebase) {
if (mRebase) {
mRebase->addEntry(tr("Please resolve conflicts before continue"),
tr("Conflict"));
mDetails->setCommitMessage(rebase.commitToRebase()
.message(git::Commit::SubstituteEmoji)
.trimmed());
}
refresh(false);
}
Expand Down
93 changes: 86 additions & 7 deletions test/rebase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class TestRebase : public QObject {
private slots:
void withoutConflicts();
void conflictingRebase();
void conflictingRebaseCustomMessage();
void continueExternalStartedRebase(); // must have conflicts otherwise it is
// not possible to continue
void startRebaseContinueInCLI();
Expand Down Expand Up @@ -278,10 +279,6 @@ void TestRebase::conflictingRebase() {
filewidgets.at(0)->stageStateChanged(filewidgets.at(0)->modelIndex(),
git::Index::StagedState::Staged);

QTextEdit *editor = repoView->findChild<QTextEdit *>("MessageEditor");
QVERIFY(editor);
editor->setText("Test message");

refreshTriggered = 0;
rebaseConflict = 0;
repoView->continueRebase();
Expand All @@ -293,9 +290,8 @@ void TestRebase::conflictingRebase() {
QList<Commit> parents = branch.annotatedCommit().commit().parents();
QCOMPARE(parents.count(), 1);
QCOMPARE(parents.at(0).id(), ac.commit().id());
QCOMPARE(
branch.annotatedCommit().commit().message(),
"Test message"); // custom message was used instead of the original one
QCOMPARE(branch.annotatedCommit().commit().message(),
"File.txt changed by second branch"); // original message is shown

// Check that rebase was really finished
QCOMPARE(mRepo.rebaseOngoing(), false);
Expand All @@ -313,6 +309,89 @@ void TestRebase::conflictingRebase() {
QCOMPARE(rebaseConflict, 0);
}

void TestRebase::conflictingRebaseCustomMessage() {
INIT_REPO("rebaseConflicts.zip", true);

auto *detailview = repoView->findChild<DetailView *>();
QVERIFY(detailview);
auto *abortRebaseButton = detailview->findChild<QPushButton *>("AbortRebase");
QVERIFY(abortRebaseButton);
auto *continueRebaseButton =
detailview->findChild<QPushButton *>("ContinueRebase");
QVERIFY(continueRebaseButton);
QCOMPARE(continueRebaseButton->isVisible(), false);
QCOMPARE(abortRebaseButton->isVisible(), false);

const QString rebaseBranchName = "refs/heads/singleCommitConflict";

git::Reference branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid());
auto c = branch.annotatedCommit().commit();

// Checkout correct branch
repoView->checkout(branch);

QTest::qWait(100);

// Rebase on main
git::Reference mainBranch = mRepo.lookupRef(QString("refs/heads/main"));
QVERIFY(mainBranch.isValid());
auto ac = mainBranch.annotatedCommit();
LogEntry *entry = repoView->addLogEntry("Rebase", "Rebase", nullptr);
repoView->rebase(ac, entry);

QCOMPARE(mRepo.rebaseOngoing(), true);

// Check that buttons are visible
QTest::qWait(100);

// Resolve conflicts
diff = mRepo.status(mRepo.index(), nullptr, false);
QCOMPARE(diff.count(), 1);
QCOMPARE(diff.patch(0).isConflicted(), true);
QFile f(mRepo.workdir().filePath(diff.patch(0).name()));
QCOMPARE(f.open(QIODevice::WriteOnly), true);
QVERIFY(f.write("Test123") !=
-1); // just write something to resolve the conflict
f.close();

QTest::qWait(100);

repoView->continueRebase(); // should fail

QTest::qWait(100); // Wait until refresh is done

// Staging the file
auto filewidgets = repoView->findChildren<FileWidget *>();
QCOMPARE(filewidgets.length(), 1);
filewidgets.at(0)->stageStateChanged(filewidgets.at(0)->modelIndex(),
git::Index::StagedState::Staged);

QTextEdit *editor = repoView->findChild<QTextEdit *>("MessageEditor");
QVERIFY(editor);
editor->setText("Test message"); // modify message

repoView->continueRebase();

// Check that branch is based on "main" now
branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid());
QList<Commit> parents = branch.annotatedCommit().commit().parents();
QCOMPARE(parents.count(), 1);
QCOMPARE(parents.at(0).id(), ac.commit().id());
QCOMPARE(branch.annotatedCommit().commit().message(),
"Test message"); // Modified message is shown

// Check that rebase was really finished
QCOMPARE(mRepo.rebaseOngoing(), false);

QTest::qWait(100); // Wait until refresh finished

// Check that buttons are visible
QCOMPARE(continueRebaseButton->isVisible(), false);
QCOMPARE(abortRebaseButton->isVisible(), false);
}

void TestRebase::continueExternalStartedRebase() {
// INIT_REPO("rebaseConflicts.zip", true);

Expand Down

0 comments on commit 66bc256

Please sign in to comment.