Skip to content

Commit

Permalink
📢 More explicit merge success message 📢
Browse files Browse the repository at this point in the history
  • Loading branch information
louib authored and louib committed Jun 11, 2019
1 parent 39672b6 commit eef0c29
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/cli/Merge.cpp
Expand Up @@ -66,9 +66,12 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer

const QStringList args = parser->positionalArguments();

QString toDatabasePath = args.at(0);
QString fromDatabasePath = args.at(1);

QSharedPointer<Database> db2;
if (!parser->isSet(Merge::SameCredentialsOption)) {
db2 = Utils::unlockDatabase(args.at(1),
db2 = Utils::unlockDatabase(fromDatabasePath,
!parser->isSet(Merge::NoPasswordFromOption),
parser->value(Merge::KeyFileFromOption),
parser->isSet(Command::QuietOption) ? Utils::DEVNULL : Utils::STDOUT,
Expand All @@ -79,7 +82,7 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer
} else {
db2 = QSharedPointer<Database>::create();
QString errorMessage;
if (!db2->open(args.at(1), database->key(), &errorMessage, false)) {
if (!db2->open(fromDatabasePath, database->key(), &errorMessage, false)) {
errorTextStream << QObject::tr("Error reading merge file:\n%1").arg(errorMessage);
return EXIT_FAILURE;
}
Expand All @@ -94,13 +97,14 @@ int Merge::executeWithDatabase(QSharedPointer<Database> database, QSharedPointer

if (!changeList.isEmpty() && !parser->isSet(Merge::DryRunOption)) {
QString errorMessage;
if (!database->save(args.at(0), &errorMessage, true, false)) {
if (!database->save(toDatabasePath, &errorMessage, true, false)) {
errorTextStream << QObject::tr("Unable to save database to file : %1").arg(errorMessage) << endl;
return EXIT_FAILURE;
}
outputTextStream << "Successfully merged the database files." << endl;
outputTextStream << QObject::tr("Successfully merged %1 into %2.").arg(fromDatabasePath, toDatabasePath)
<< endl;
} else {
outputTextStream << "Database was not modified by merge operation." << endl;
outputTextStream << QObject::tr("Database was not modified by merge operation.") << endl;
}

return EXIT_SUCCESS;
Expand Down
6 changes: 4 additions & 2 deletions tests/TestCli.cpp
Expand Up @@ -978,7 +978,8 @@ void TestCli::testMerge()
QList<QByteArray> outLines1 = m_stdoutFile->readAll().split('\n');
QCOMPARE(outLines1.at(0).split('[').at(0), QByteArray("\tOverwriting Internet "));
QCOMPARE(outLines1.at(1).split('[').at(0), QByteArray("\tCreating missing Some Website "));
QCOMPARE(outLines1.at(2), QByteArray("Successfully merged the database files."));
QCOMPARE(outLines1.at(2),
QString("Successfully merged %1 into %2.").arg(sourceFile.fileName(), targetFile1.fileName()).toUtf8());

QFile readBack(targetFile1.fileName());
readBack.open(QIODevice::ReadOnly);
Expand Down Expand Up @@ -1039,7 +1040,8 @@ void TestCli::testMerge()
m_stdoutFile->readLine();
m_stdoutFile->readLine();
QList<QByteArray> outLines3 = m_stdoutFile->readAll().split('\n');
QCOMPARE(outLines3.at(2), QByteArray("Successfully merged the database files."));
QCOMPARE(outLines3.at(2),
QString("Successfully merged %1 into %2.").arg(sourceFile.fileName(), targetFile3.fileName()).toUtf8());

readBack.setFileName(targetFile3.fileName());
readBack.open(QIODevice::ReadOnly);
Expand Down

0 comments on commit eef0c29

Please sign in to comment.