From 6641bdf3baa61af33f0d15ff90a3c9a36dcb1d6b Mon Sep 17 00:00:00 2001 From: Michael Seibt Date: Wed, 16 Jun 2021 23:16:19 +0200 Subject: [PATCH] Create empty AppSettings file in order to not let the FileSettingsCache skip the activation of its FileSystemWatcher Fixes #9288 (cherry picked from commit ac314554b48368fc5971043a5cfcf98a4c36ce3c) --- GitCommands/Settings/AppSettings.cs | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/GitCommands/Settings/AppSettings.cs b/GitCommands/Settings/AppSettings.cs index 813a10bb0e3..b360389763e 100644 --- a/GitCommands/Settings/AppSettings.cs +++ b/GitCommands/Settings/AppSettings.cs @@ -108,15 +108,39 @@ static AppSettings() return path; }); + bool newFile = CreateEmptySettingsFileIfMissing(); + SettingsContainer = new RepoDistSettings(null, GitExtSettingsCache.FromCache(SettingsFilePath), SettingLevel.Unknown); - if (!File.Exists(SettingsFilePath)) + if (newFile || !File.Exists(SettingsFilePath)) { ImportFromRegistry(); } MigrateAvatarSettings(); MigrateSshSettings(); + + return; + + static bool CreateEmptySettingsFileIfMissing() + { + try + { + string dir = Path.GetDirectoryName(SettingsFilePath); + if (!Directory.Exists(dir) || File.Exists(SettingsFilePath)) + { + return false; + } + } + catch (ArgumentException) + { + // Illegal characters in the filename + return false; + } + + File.WriteAllText(SettingsFilePath, "", Encoding.UTF8); + return true; + } } ///