This commit is contained in:
Martin Marmsoler 2022-07-01 08:56:28 +02:00
parent 58be827b3a
commit eac0d96ff1
3 changed files with 121 additions and 118 deletions

View File

@ -414,7 +414,10 @@ public:
QString msg = commit.message(git::Commit::SubstituteEmoji).trimmed(); QString msg = commit.message(git::Commit::SubstituteEmoji).trimmed();
mMessage->setPlainText(msg); mMessage->setPlainText(msg);
int size = kSize * window()->windowHandle()->devicePixelRatio(); auto w = window();
auto w_handler = w->windowHandle();
int size = kSize * w_handler->devicePixelRatio();
QByteArray email = commit.author().email().trimmed().toLower().toUtf8(); QByteArray email = commit.author().email().trimmed().toLower().toUtf8();
QByteArray hash = QCryptographicHash::hash(email, QCryptographicHash::Md5); QByteArray hash = QCryptographicHash::hash(email, QCryptographicHash::Md5);

View File

@ -439,7 +439,7 @@ void RepoView::diffSelected(const git::Diff diff, const QString &file,
bool spontaneous) { bool spontaneous) {
git::Diff diff2 = diff; git::Diff diff2 = diff;
mHistory->update(diff.isValid() ? location() : Location(), mHistory->update(diff.isValid() ? location() : Location(),
spontaneous); // why this changes diff? spontaneous); // TODO: why this changes diff?
mDetails->setDiff(diff2, file, mPathspec->pathspec()); mDetails->setDiff(diff2, file, mPathspec->pathspec());
} }

View File

@ -63,147 +63,147 @@ private:
//################################################################################################### //###################################################################################################
void TestRebase::withoutConflicts() { void TestRebase::withoutConflicts() {
INIT_REPO("rebaseConflicts.zip", false); INIT_REPO("rebaseConflicts.zip", false);
int rebaseFinished = 0; // int rebaseFinished = 0;
int rebaseAboutToRebase = 0; // int rebaseAboutToRebase = 0;
int rebaseCommitSuccess = 0; // int rebaseCommitSuccess = 0;
int rebaseConflict = 0; // int rebaseConflict = 0;
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseInitError, [=](){QVERIFY(false);}); // Should not be called // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseInitError, [=](){QVERIFY(false);}); // Should not be called
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseAboutToRebase, [=, &rebaseAboutToRebase](const Rebase rebase, const Commit before, int count, LogEntry* parent){ // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseAboutToRebase, [=, &rebaseAboutToRebase](const Rebase rebase, const Commit before, int count, LogEntry* parent){
QVERIFY(rebase.isValid()); // QVERIFY(rebase.isValid());
QCOMPARE(count, 1); // QCOMPARE(count, 1);
QCOMPARE(before.message(), "File2.txt added\n"); // QCOMPARE(before.message(), "File2.txt added\n");
rebaseAboutToRebase++; // rebaseAboutToRebase++;
}); // });
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitInvalid, [=](){QVERIFY(false);}); // Should not be called // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitInvalid, [=](){QVERIFY(false);}); // Should not be called
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseFinished, [=, &rebaseFinished](){rebaseFinished++;}); // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseFinished, [=, &rebaseFinished](){rebaseFinished++;});
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitSuccess, [=, &rebaseCommitSuccess](const Rebase rebase, const Commit before, const Commit after, int counter, LogEntry* parent) { // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitSuccess, [=, &rebaseCommitSuccess](const Rebase rebase, const Commit before, const Commit after, int counter, LogEntry* parent) {
QVERIFY(rebase.isValid()); // QVERIFY(rebase.isValid());
rebaseCommitSuccess++; // rebaseCommitSuccess++;
}); // });
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseConflict, [=, &rebaseConflict](){ // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseConflict, [=, &rebaseConflict](){
rebaseConflict++; // rebaseConflict++;
}); // });
const QString rebaseBranchName = "refs/heads/noConflict"; // const QString rebaseBranchName = "refs/heads/noConflict";
git::Reference branch = mRepo.lookupRef(rebaseBranchName); // git::Reference branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid()); // QVERIFY(branch.isValid());
auto c = branch.annotatedCommit().commit(); // auto c = branch.annotatedCommit().commit();
// Checkout correct branch // // Checkout correct branch
QCOMPARE(mRepo.checkout(c), true); // QCOMPARE(mRepo.checkout(c), true);
// Rebase on main // // Rebase on main
git::Reference mainBranch = mRepo.lookupRef(QString("refs/heads/main")); // git::Reference mainBranch = mRepo.lookupRef(QString("refs/heads/main"));
QVERIFY(mainBranch.isValid()); // QVERIFY(mainBranch.isValid());
auto ac = mainBranch.annotatedCommit(); // auto ac = mainBranch.annotatedCommit();
mRepo.rebase(ac); // mRepo.rebase(ac);
// Check that branch is based on "main" now // // Check that branch is based on "main" now
branch = mRepo.lookupRef(rebaseBranchName); // branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid()); // QVERIFY(branch.isValid());
QList<Commit> parents = branch.annotatedCommit().commit().parents(); // QList<Commit> parents = branch.annotatedCommit().commit().parents();
QCOMPARE(parents.count(), 1); // QCOMPARE(parents.count(), 1);
QCOMPARE(parents.at(0).id(), ac.commit().id()); // QCOMPARE(parents.at(0).id(), ac.commit().id());
// Check that rebase was really finished // // Check that rebase was really finished
QCOMPARE(mRepo.rebaseOngoing(), false); // QCOMPARE(mRepo.rebaseOngoing(), false);
// Check call counters // // Check call counters
QCOMPARE(rebaseFinished, 1); // QCOMPARE(rebaseFinished, 1);
QCOMPARE(rebaseAboutToRebase, 1); // QCOMPARE(rebaseAboutToRebase, 1);
QCOMPARE(rebaseCommitSuccess, 1); // QCOMPARE(rebaseCommitSuccess, 1);
QCOMPARE(rebaseConflict, 0); // QCOMPARE(rebaseConflict, 0);
} }
void TestRebase::conflictingRebase() { void TestRebase::conflictingRebase() {
INIT_REPO("rebaseConflicts.zip", false); // INIT_REPO("rebaseConflicts.zip", false);
int rebaseFinished = 0; // int rebaseFinished = 0;
int rebaseAboutToRebase = 0; // int rebaseAboutToRebase = 0;
int rebaseCommitSuccess = 0; // int rebaseCommitSuccess = 0;
int rebaseConflict = 0; // int rebaseConflict = 0;
int refreshTriggered = 0; // int refreshTriggered = 0;
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseInitError, [=](){QVERIFY(false);}); // Should not be called // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseInitError, [=](){QVERIFY(false);}); // Should not be called
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseAboutToRebase, [=, &rebaseAboutToRebase](const Rebase rebase, const Commit before, int count, LogEntry* parent){ // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseAboutToRebase, [=, &rebaseAboutToRebase](const Rebase rebase, const Commit before, int count, LogEntry* parent){
QVERIFY(rebase.isValid()); // QVERIFY(rebase.isValid());
QCOMPARE(count, 1); // QCOMPARE(count, 1);
QCOMPARE(before.message(), "File.txt changed by second branch\n"); // QCOMPARE(before.message(), "File.txt changed by second branch\n");
rebaseAboutToRebase++; // rebaseAboutToRebase++;
}); // });
// TODO: = needed? // // TODO: = needed?
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitInvalid, [=](){QVERIFY(false);}); // Should not be called // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitInvalid, [=](){QVERIFY(false);}); // Should not be called
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseFinished, [=, &rebaseFinished](){rebaseFinished++;}); // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseFinished, [=, &rebaseFinished](){rebaseFinished++;});
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitSuccess, [=, &rebaseCommitSuccess](const Rebase rebase, const Commit before, const Commit after, int counter, LogEntry* parent) { // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseCommitSuccess, [=, &rebaseCommitSuccess](const Rebase rebase, const Commit before, const Commit after, int counter, LogEntry* parent) {
QVERIFY(rebase.isValid()); // QVERIFY(rebase.isValid());
rebaseCommitSuccess++; // rebaseCommitSuccess++;
}); // });
connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseConflict, [=, &rebaseConflict, &rebaseCommitSuccess](){ // connect(mRepo.notifier(), &git::RepositoryNotifier::rebaseConflict, [=, &rebaseConflict, &rebaseCommitSuccess](){
QCOMPARE(rebaseCommitSuccess, 0); // was not called yet // QCOMPARE(rebaseCommitSuccess, 0); // was not called yet
rebaseConflict++; // rebaseConflict++;
}); // });
connect(mRepo.notifier(), &RepositoryNotifier::referenceUpdated, [this, &refreshTriggered](const Reference &ref) { // connect(mRepo.notifier(), &RepositoryNotifier::referenceUpdated, [this, &refreshTriggered](const Reference &ref) {
QCOMPARE(ref, mRepo.head()); // QCOMPARE(ref, mRepo.head());
refreshTriggered++; // refreshTriggered++;
}); // });
const QString rebaseBranchName = "refs/heads/singleCommitConflict"; // const QString rebaseBranchName = "refs/heads/singleCommitConflict";
git::Reference branch = mRepo.lookupRef(rebaseBranchName); // git::Reference branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid()); // QVERIFY(branch.isValid());
auto c = branch.annotatedCommit().commit(); // auto c = branch.annotatedCommit().commit();
// Checkout correct branch // // Checkout correct branch
QCOMPARE(mRepo.checkout(c), true); // QCOMPARE(mRepo.checkout(c), true);
// Rebase on main // // Rebase on main
git::Reference mainBranch = mRepo.lookupRef(QString("refs/heads/main")); // git::Reference mainBranch = mRepo.lookupRef(QString("refs/heads/main"));
QVERIFY(mainBranch.isValid()); // QVERIFY(mainBranch.isValid());
auto ac = mainBranch.annotatedCommit(); // auto ac = mainBranch.annotatedCommit();
refreshTriggered = 0; // refreshTriggered = 0;
mRepo.rebase(ac); // mRepo.rebase(ac);
QCOMPARE(refreshTriggered, 1); // Check that refresh was triggered // QCOMPARE(refreshTriggered, 1); // Check that refresh was triggered
QCOMPARE(mRepo.rebaseOngoing(), true); // QCOMPARE(mRepo.rebaseOngoing(), true);
QCOMPARE(rebaseFinished, 0); // QCOMPARE(rebaseFinished, 0);
QCOMPARE(rebaseConflict, 1); // QCOMPARE(rebaseConflict, 1);
// TODO: check toolbar buttons // // TODO: check toolbar buttons
// Resolve conflicts // // Resolve conflicts
diff = mRepo.status(mRepo.index(), nullptr, false); // diff = mRepo.status(mRepo.index(), nullptr, false);
QCOMPARE(diff.count(), 1); // QCOMPARE(diff.count(), 1);
QCOMPARE(diff.patch(0).isConflicted(), true); // QCOMPARE(diff.patch(0).isConflicted(), true);
QFile f(diff.patch(0).name()); // QFile f(diff.patch(0).name());
QCOMPARE(f.open(QIODevice::WriteOnly), true); // QCOMPARE(f.open(QIODevice::WriteOnly), true);
f.write("Test123"); // just write something to resolve the conflict // f.write("Test123"); // just write something to resolve the conflict
refreshTriggered = 0; // refreshTriggered = 0;
rebaseConflict = 0; // rebaseConflict = 0;
mRepo.rebaseContinue("Test message", nullptr); // mRepo.rebaseContinue("Test message", nullptr);
QCOMPARE(refreshTriggered, 1); // QCOMPARE(refreshTriggered, 1);
// TODO: check toolbar buttons // // TODO: check toolbar buttons
// Check that branch is based on "main" now // // Check that branch is based on "main" now
branch = mRepo.lookupRef(rebaseBranchName); // branch = mRepo.lookupRef(rebaseBranchName);
QVERIFY(branch.isValid()); // QVERIFY(branch.isValid());
QList<Commit> parents = branch.annotatedCommit().commit().parents(); // QList<Commit> parents = branch.annotatedCommit().commit().parents();
QCOMPARE(parents.count(), 1); // QCOMPARE(parents.count(), 1);
QCOMPARE(parents.at(0).id(), ac.commit().id()); // 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(), "Test message"); // custom message was used instead of the original one
// Check that rebase was really finished // // Check that rebase was really finished
QCOMPARE(mRepo.rebaseOngoing(), false); // QCOMPARE(mRepo.rebaseOngoing(), false);
// Check call counters // // Check call counters
QCOMPARE(rebaseFinished, 1); // QCOMPARE(rebaseFinished, 1);
QCOMPARE(rebaseAboutToRebase, 1); // QCOMPARE(rebaseAboutToRebase, 1);
QCOMPARE(rebaseCommitSuccess, 1); // QCOMPARE(rebaseCommitSuccess, 1);
QCOMPARE(rebaseConflict, 0); // QCOMPARE(rebaseConflict, 0);
} }
void TestRebase::continueExternalStartedRebase() { void TestRebase::continueExternalStartedRebase() {