From 4d14302929726ac0d31273fd6c2c075b46ce6158 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 9 Oct 2024 14:20:43 +0800 Subject: [PATCH] refactor: remove scope parameter while getting git configuration (#544) --- src/Commands/Config.cs | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Commands/Config.cs b/src/Commands/Config.cs index 53416c86..2fb83325 100644 --- a/src/Commands/Config.cs +++ b/src/Commands/Config.cs @@ -7,17 +7,23 @@ namespace SourceGit.Commands { public Config(string repository) { - WorkingDirectory = repository; - Context = repository; + if (string.IsNullOrEmpty(repository)) + { + WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + } + else + { + WorkingDirectory = repository; + Context = repository; + _isLocal = true; + } + RaiseError = false; } public Dictionary ListAll() { - if (string.IsNullOrEmpty(WorkingDirectory)) - Args = "config --global -l"; - else - Args = "config -l"; + Args = "config -l"; var output = ReadToEnd(); var rs = new Dictionary(); @@ -47,22 +53,16 @@ namespace SourceGit.Commands public bool Set(string key, string value, bool allowEmpty = false) { + var scope = _isLocal ? "--local" : "--global"; + if (!allowEmpty && string.IsNullOrWhiteSpace(value)) - { - if (string.IsNullOrEmpty(WorkingDirectory)) - Args = $"config --global --unset {key}"; - else - Args = $"config --unset {key}"; - } + Args = $"config {scope} --unset {key}"; else - { - if (string.IsNullOrWhiteSpace(WorkingDirectory)) - Args = $"config --global {key} \"{value}\""; - else - Args = $"config {key} \"{value}\""; - } + Args = $"config {scope} {key} \"{value}\""; return Exec(); } + + private bool _isLocal = false; } }