Skip to content

Commit 5242552

Browse files
committed
feat(credential.helper): Display multi-value config
of credential.helper and hide effective value Refs: gitextensions#12426
1 parent f9a54d8 commit 5242552

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

src/app/GitUI/CommandsDialogs/SettingsDialog/Pages/GitConfigSettingsPage.cs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using GitCommands.DiffMergeTools;
99
using GitCommands.Settings;
1010
using GitCommands.Utils;
11+
using GitExtensions.Extensibility.Configurations;
1112
using GitExtensions.Extensibility.Settings;
1213
using Microsoft;
1314
using ResourceManager;
@@ -159,10 +160,22 @@ protected override void SettingsToPage()
159160

160161
GlobalUserName.Text = CurrentSettings.GetValue(SettingKeyString.UserName);
161162
GlobalUserEmail.Text = CurrentSettings.GetValue(SettingKeyString.UserEmail);
162-
cbxCredentialHelper.Text = CurrentSettings.GetValue("credential.helper");
163163
GlobalEditor.Text = CurrentSettings.GetValue("core.editor");
164164
txtCommitTemplatePath.Text = CurrentSettings.GetValue("commit.template");
165165

166+
// Hide credential helper because EffectiveGitConfigSettings can only return the last value
167+
GitConfigSettings? gitConfigSettings = TryGetGitConfigSettings(CurrentSettings);
168+
bool showCredentialHelper = gitConfigSettings is not null;
169+
lblCredentialHelper.Visible = showCredentialHelper;
170+
cbxCredentialHelper.Visible = showCredentialHelper;
171+
cbxCredentialHelper.Enabled = showCredentialHelper;
172+
if (gitConfigSettings is not null)
173+
{
174+
IReadOnlyList<string> values = gitConfigSettings.GetValues(SettingKeyString.CredentialHelper);
175+
cbxCredentialHelper.Enabled = values.Count <= 1;
176+
cbxCredentialHelper.Text = string.Join(", ", values);
177+
}
178+
166179
_NO_TRANSLATE_cboMergeTool.Text = mergeTool;
167180
txtMergeToolPath.Text = _diffMergeToolConfigurationManager.GetToolPath(mergeTool, DiffMergeToolType.Merge);
168181
txtMergeToolCommand.Text = _diffMergeToolConfigurationManager.GetToolCommand(mergeTool, DiffMergeToolType.Merge);
@@ -179,6 +192,17 @@ protected override void SettingsToPage()
179192
globalAutoCrlfNotSet.Checked = autocrlf is null;
180193

181194
base.SettingsToPage();
195+
196+
return;
197+
198+
static GitConfigSettings? TryGetGitConfigSettings(SettingsSource settingsSource)
199+
{
200+
return settingsSource is SettingsSource<IPersistentConfigValueStore> persistentSettingsSource
201+
? persistentSettingsSource.ConfigValueStore as GitConfigSettings
202+
: settingsSource is SettingsSource<IConfigValueStore> otherGenericSettingsSource
203+
? otherGenericSettingsSource.ConfigValueStore as GitConfigSettings
204+
: null;
205+
}
182206
}
183207

184208
/// <summary>
@@ -201,8 +225,11 @@ protected override void PageToSettings()
201225
CurrentSettings.SetValue(SettingKeyString.UserName, GlobalUserName.Text);
202226
CurrentSettings.SetValue(SettingKeyString.UserEmail, GlobalUserEmail.Text);
203227
CurrentSettings.SetValue("commit.template", txtCommitTemplatePath.Text);
204-
CurrentSettings.SetValue("credential.helper", cbxCredentialHelper.Text);
205228
CurrentSettings.SetValue("core.editor", GlobalEditor.Text.ConvertPathToGitSetting());
229+
if (cbxCredentialHelper.Enabled)
230+
{
231+
CurrentSettings.SetValue(SettingKeyString.CredentialHelper, cbxCredentialHelper.Text);
232+
}
206233

207234
Validates.NotNull(_diffMergeToolConfigurationManager);
208235

0 commit comments

Comments
 (0)