Skip to content

Conversation

pmiossec
Copy link
Member

@pmiossec pmiossec commented Oct 2, 2024

and so that settings file can't be saved in a "not existing" local repository.

Check that repo is valid and provide the information when creating pages

Fixes #11907 (at least prevent one way to reproduce it)

Screenshots

Before

image

After

image

Test methodology

  • Manual (Opening settings from dashboard i.e. while no repo opened)

Test environment(s)

  • GIT
  • Windows

Merge strategy

I agree that the maintainer squash merge this PR (if the commit message is clear).
(Will be squashed before merging)


✒️ I contribute this code under The Developer Certificate of Origin.

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seem to work.

Does this changes the plugin interface?

@mstv
Copy link
Member

mstv commented Oct 2, 2024

Do we really need to pass this flag to all settings pages? It does not apply to more than half of them.

Copy link
Member

@RussKie RussKie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a suboptimal way of implementing the flag. Is there a reason the flag can't be initialised by the base page?

@pmiossec
Copy link
Member Author

pmiossec commented Oct 8, 2024

This feels like a suboptimal way of implementing the flag. Is there a reason the flag can't be initialised by the base page?

It can't because we don't have access to IGitModule in SettingsPageBase.

I discovered that we can get it through ISettingsPageHost (and so I pushed the beginning of a refactoring) but the property is set after and so the module is available later:
https://github.com/gitextensions/gitextensions/pull/11955/files#diff-f8be27a1112b9ef3c305709ea09203ee2a4f1c4cd3a37110498627d617607af0R70

I can continue the refactoring to require ISettingsPageHost in the constructor but the result will be that all the constructor will be updated (taking ISettingsPageHost instead of bool canSaveInsideRepo).

@RussKie I gave it a quick try in the last commit. Look if you find it better...

Do we really need to pass this flag to all settings pages? It does not apply to more than half of them.

The constructors of all the setting pages has to be updated due to how they are instantiated.

Does this changes the plugin interface?

I don't think so (and it seems to work without problem)

Copy link
Member

@mstv mstv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍, have not run

Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of changes, but hard to do in another way.
Have run briefly

@RussKie
Copy link
Member

RussKie commented Oct 10, 2024

I'm planning to review this, hopefully before the EOW.

{
_canSaveInsideRepo = pageHost.CheckSettingsLogic.CommonLogic.Module.IsValidGitWorkingDir();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the concrete type of serviceProvider? It's an instance of GitUICommands, which implements IGitUICommands and, thus, inherits from IServiceProvider.
image

Which makes this possible:

if (serviceProvider is IGitUICommands uiCommands)
{
    _canSaveInsideRepo = uiCommands.Module.IsValidGitWorkingDir();
}

It's a little hacky, but we some point I expect we'll have something like the following:

IGitUICommands uiCommands = serviceProvider.GetREquiredService<IGitUICommands>();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which makes this possible:

I saw that but it was (too) hacky for me that's why I have not decided to go that way.
It's you to decide...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end, ISettingsPageHost, that still need to be passed is now passed in the constructor to have it earlier than in a later call to do some initialization. It's indeed a lot of code changes but nothing silly...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current change introduces a hard coupling, and this I'd like to avoid.
Let's resolve from the service provider

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

and so when a setting could only be saved globally.

Fixes gitextensions#11907
@pmiossec pmiossec force-pushed the fix/settings-outside-repo branch from 2579834 to 698ef8c Compare October 19, 2024 20:47
@pmiossec pmiossec merged commit a6d047b into gitextensions:master Oct 19, 2024
4 checks passed
@pmiossec pmiossec deleted the fix/settings-outside-repo branch October 19, 2024 22:17
@RussKie RussKie added this to the 5.1 milestone Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[NBug] Value cannot be null. (Parameter 'targetName')
4 participants