[Bug 347351] Display dialog to configure user.name or user.email in git, if commiting without it configured
ClosedPublic

Authored by apuzio on Jan 21 2016, 7:26 PM.

Details

Summary

Added function to get git config
Added checking of user.email and user.name when committing
Added possibility to configure global git parameters
Added QDialog extension to choose the name and email, with possibility to save the settings as global and validation.
Used the extension to handle the lack of user.name or user.email configured when committing.
Added unit tests for readConfigOption and setConfigOption.
This fixes the Bug 347351

Test Plan

The new dialog works fine.
Tests pass.

Diff Detail

Repository
R33 KDevPlatform
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
apuzio updated this revision to Diff 2059.Jan 21 2016, 7:26 PM
apuzio retitled this revision from to Display dialog to configure user.name or user.email in git, if commiting without it configured.
apuzio updated this object.
apuzio edited the test plan for this revision. (Show Details)
apuzio added a reviewer: kfunk.
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptJan 21 2016, 7:26 PM
mwolff added a subscriber: mwolff.Jan 21 2016, 7:51 PM

can you create a test for that please?

plugins/git/gitnameemaildialog.cpp
33

could you use a .ui file created in designer please? that makes it simpler to maintain UI and change it in the future

apuzio retitled this revision from Display dialog to configure user.name or user.email in git, if commiting without it configured to [Bug 347351] Display dialog to configure user.name or user.email in git, if commiting without it configured.Jan 21 2016, 7:53 PM
apuzio updated this object.
apuzio removed a subscriber: mwolff.
apuzio added a subscriber: mwolff.

@mwolff What do you want my to tests using unit test?
The dialog source (especially after using .ui from Designer) will be very simple. I will only use some abstract functions from other classes. So the potential unit test will in fact be testing the functionality of QRegExpValidator and I don't actually know what else there is to test.
The changes to commit function could be tested (I actually don't know how to test UI interactions, if I don't have the pointer to the QDialog), but again what is there to test? I'm just invoking a getConfigOption, setConfigOption and the QDialog.
What could be tested is the getConfigOption and changes to setConfigOption, but this are also very very simple functions and there isn't any test for the old setConfigOption.

apuzio updated this revision to Diff 2061.Jan 21 2016, 10:05 PM

Changed to .ui file from Designer instead of deffineing the ui in c++ source
Style fixed in gitplugin.cpp

apuzio marked an inline comment as done.Jan 21 2016, 10:06 PM
mwolff added inline comments.Jan 22 2016, 9:09 AM
plugins/git/gitplugin.cpp
427

QStringLiteral

plugins/git/gitplugin.h
148–149

add spaces around the = please

149

remove the "get" prefix, just remove it or replace it by "read". these two functions is also what I'd like to see tested. the set of a global option and the getter.

apuzio updated this revision to Diff 2065.Jan 22 2016, 6:13 PM
  • Fixed isssues and moved value.chop() to readConfigOption funtion
  • Added unit tests for readConfigOption and setConfigOption
apuzio marked 3 inline comments as done.Jan 22 2016, 6:14 PM
apuzio updated this object.Jan 22 2016, 6:29 PM
apuzio edited the test plan for this revision. (Show Details)
mwolff added inline comments.Jan 23 2016, 5:04 PM
plugins/git/gitnameemaildialog.cpp
41

use QRegularExpressionValidator

58

remove extra spaces

66

add newlines between functions

plugins/git/gitnameemaildialog.h
45

remove get prefix, i.e. follow the Qt style. Also remove the Field everywhere.

void setName(const QString& name); // also note the const!
void setEmail(const QString& email); // also note the const!
QString nameField() const;
QString emailField() const;
bool isGlobal() const;
52

both of these could be put into QScopedPointer or std::unique_ptr. Then remove the delete ... lines from the destructor. I.e. in the .cpp file then write:

GitNameEmailDialog::~GitNameEmailDialog() = default;
plugins/git/gitnameemaildialog.ui
54

rephrase slightly:

You have not yet configured the name and email to be associated with your Git commits.
The values you enter here will be written to the Git configuration, either locally for
the current project only, or globally for all Git projects.

114

no buttonbox?

plugins/git/gitplugin.cpp
429
if (email.isEmpty() || name.isEmpty())
1485

please share code, make the QStringList accessible and append --global optionally. No need to copy'n'paste 99% of the code for just that purpose

1504

this may still break on windows, so either use QTextStream and it's readLine, or return a trimmed value. I can't think of a situation where that could break. Whitespaces in config values should not matter afaik.

plugins/git/tests/test_git.cpp
271

remove the QDebug, and rewrite this test to make it data-driven, (i.e. use QTest::newColumn, QTest::addRow, QFETCH and a testLocalConfig_data()).

plugins/git/tests/test_git.h
46

const& the QString args

apuzio added inline comments.Jan 23 2016, 6:09 PM
plugins/git/gitnameemaildialog.ui
114

In Qt-designer it's not possible to add custom name to a button in button box. (or I wasn't able to find a way)

plugins/git/tests/test_git.cpp
271

At first I tried to make it data driven, but the initTestCase() and cleanupTestCase() seamed to be interfering with this test. As I don't understand how they are working, I haven't touched them. What I found out is, that repoInit() has to be called at the beginning of the test, because the repo seams to be deleted between tests. If I used data-driven tests the repo would be reinitialized between each test case and that would break my tests.

apuzio updated this revision to Diff 2075.Jan 23 2016, 6:23 PM
  • Fixed style
  • Changed description in dialog
  • QRegExp -> QRegularExpression
  • \* -> QScopedPointer
apuzio marked 7 inline comments as done.Jan 23 2016, 6:25 PM
apuzio updated this revision to Diff 2076.Jan 23 2016, 6:26 PM
  • or -> ||
apuzio marked 3 inline comments as done.Jan 23 2016, 6:27 PM
kfunk added inline comments.Jan 25 2016, 12:19 PM
plugins/git/gitnameemaildialog.cpp
24

No global module includes please. Use QDialog and friends

41

I don't get that regexp. This is accepting everything, right...? Which makes it useless as a validator regex.

plugins/git/gitnameemaildialog.h
43

Style: Use const QString& name, same below and in other places

50

Typo: refresh. Better just call that function updateUi

plugins/git/gitplugin.cpp
434

Style: { on same line, same below

mwolff added inline comments.Jan 26 2016, 9:14 AM
plugins/git/gitnameemaildialog.cpp
41

It's everything *except* nothing :) So this is an easy validator to ensure the field is not empty.

kfunk added inline comments.Jan 26 2016, 9:20 AM
plugins/git/gitnameemaildialog.cpp
41

Oh, indeed. Not an issue then. Thanks.

apuzio updated this revision to Diff 2098.Jan 26 2016, 12:43 PM
apuzio marked 3 inline comments as done.

Fixed issues: style, #include <QtWidgets> -> #include <QDialog>

apuzio marked 2 inline comments as done.Jan 26 2016, 12:45 PM
apuzio updated this revision to Diff 2099.Jan 26 2016, 2:32 PM
apuzio marked an inline comment as done.

Fixed style issues

apuzio marked an inline comment as done.Jan 26 2016, 2:33 PM
kfunk added inline comments.Jan 26 2016, 8:04 PM
plugins/git/tests/test_git.cpp
268

This test is too complicated for the test coverage it achieves.

This would basically reach the same coverage:

  • test reading an option which does not exist, assert value empty
  • test setting a option
  • test reading back that option, compare values

Kill GitInitTest::runTestLocalConfig, call {set,read}ConfigOption directly in here.

apuzio updated this revision to Diff 2116.Jan 27 2016, 11:54 AM
apuzio marked an inline comment as done.

Simplified the test

kfunk edited edge metadata.Feb 2 2016, 10:04 PM

LGTM, I'll take care of pushing (I have some minor amendments in mind)

kfunk accepted this revision.Feb 2 2016, 10:04 PM
kfunk edited edge metadata.
This revision is now accepted and ready to land.Feb 2 2016, 10:04 PM
This revision was automatically updated to reflect the committed changes.