From b4e9885b957d56cbaab837d2ec695702cde3931e Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 10 Dec 2023 13:12:01 +0100 Subject: [PATCH] set original commit message as default --- src/ui/RepoView.cpp | 3 ++ test/rebase.cpp | 93 +++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 89 insertions(+), 7 deletions(-) diff --git a/src/ui/RepoView.cpp b/src/ui/RepoView.cpp index b9ee2436..1f4866c6 100644 --- a/src/ui/RepoView.cpp +++ b/src/ui/RepoView.cpp @@ -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); } diff --git a/test/rebase.cpp b/test/rebase.cpp index 0abb0cd7..f80375df 100644 --- a/test/rebase.cpp +++ b/test/rebase.cpp @@ -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(); @@ -278,10 +279,6 @@ void TestRebase::conflictingRebase() { filewidgets.at(0)->stageStateChanged(filewidgets.at(0)->modelIndex(), git::Index::StagedState::Staged); - QTextEdit *editor = repoView->findChild("MessageEditor"); - QVERIFY(editor); - editor->setText("Test message"); - refreshTriggered = 0; rebaseConflict = 0; repoView->continueRebase(); @@ -293,9 +290,8 @@ void TestRebase::conflictingRebase() { QList 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); @@ -313,6 +309,89 @@ void TestRebase::conflictingRebase() { QCOMPARE(rebaseConflict, 0); } +void TestRebase::conflictingRebaseCustomMessage() { + INIT_REPO("rebaseConflicts.zip", true); + + auto *detailview = repoView->findChild(); + QVERIFY(detailview); + auto *abortRebaseButton = detailview->findChild("AbortRebase"); + QVERIFY(abortRebaseButton); + auto *continueRebaseButton = + detailview->findChild("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(); + QCOMPARE(filewidgets.length(), 1); + filewidgets.at(0)->stageStateChanged(filewidgets.at(0)->modelIndex(), + git::Index::StagedState::Staged); + + QTextEdit *editor = repoView->findChild("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 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);