From 2efd709896e1724803072538323b3332cf96a0b8 Mon Sep 17 00:00:00 2001 From: Andrew Witte Date: Tue, 2 Nov 2021 05:34:56 -0700 Subject: [PATCH] Ensure git Unicode filename mode is enabled Fixed Regex git version checking bugs Show native Windows dialog when missing features detected Fixed null-ref when renaming branches Added missing app.manifest file --- GitCommander/Properties/AssemblyInfo.cs | 2 +- GitCommander/Repository.cs | 40 ++++++++++ GitCommander/Repository_Changes.cs | 3 +- GitItGUI.Core/AppManager.cs | 29 ++++--- GitItGUI.Core/RepoManager.cs | 3 + GitItGUI.UI/GitItGUI.UI.csproj | 5 +- GitItGUI.UI/MainWindow.xaml.cs | 25 ++++-- GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs | 7 +- GitItGUI.UI/app.manifest | 79 +++++++++++++++++++ Installer/Git-It-GUI_Installer.aip | 6 +- .../VersionInfo.xml | 2 +- 11 files changed, 172 insertions(+), 29 deletions(-) create mode 100644 GitItGUI.UI/app.manifest rename {GitItGUI.UI => UpdateCheckFiles}/VersionInfo.xml (69%) diff --git a/GitCommander/Properties/AssemblyInfo.cs b/GitCommander/Properties/AssemblyInfo.cs index cef1ce3..28c3b36 100644 --- a/GitCommander/Properties/AssemblyInfo.cs +++ b/GitCommander/Properties/AssemblyInfo.cs @@ -37,7 +37,7 @@ public static class VersionInfo { - public const string version = "1.0.7"; + public const string version = "1.0.8"; #if DEBUG public const string versionType = version + "d"; diff --git a/GitCommander/Repository.cs b/GitCommander/Repository.cs index 738bc4c..930bb4f 100644 --- a/GitCommander/Repository.cs +++ b/GitCommander/Repository.cs @@ -273,5 +273,45 @@ public bool GetVersion(out string version) return result; } } + + public bool EnsureUnicodeDisabledLocally() + { + bool unicodeEntryExists = false; + void stdCallback(string line) + { + if (line != null) unicodeEntryExists = true; + } + + lock (this) + { + if (!SimpleGitInvoke("config --local core.quotepath", stdCallback:stdCallback)) return false; + if (unicodeEntryExists) + { + if (!SimpleGitInvoke("config --local --unset core.quotepath")) return false; + } + + return true; + } + } + + public bool EnsureUnicodeEnabledGlobally() + { + bool unicodeEnabled = false;; + void stdCallback(string line) + { + if (line == "off") unicodeEnabled = true; + } + + lock (this) + { + if (!SimpleGitInvoke("config --global core.quotepath", stdCallback:stdCallback)) return false; + if (!unicodeEnabled) + { + return SimpleGitInvoke("config --global core.quotepath off"); + } + + return true; + } + } } } diff --git a/GitCommander/Repository_Changes.cs b/GitCommander/Repository_Changes.cs index 442e510..7518c6f 100644 --- a/GitCommander/Repository_Changes.cs +++ b/GitCommander/Repository_Changes.cs @@ -218,13 +218,14 @@ bool addState(string type, FileStates stateType, FileConflictTypes conflictType } else { + var ext = Path.GetExtension(filePath); var state = new FileState() { filename = filePath, state = stateType, conflictType = conflictType, isSubmodule = isSubmodule, - isLFS = lfsExts.Contains(Path.GetExtension(filePath)) + isLFS = lfsExts.Contains(ext) }; states.Add(state); diff --git a/GitItGUI.Core/AppManager.cs b/GitItGUI.Core/AppManager.cs index 8552cc4..5e3e14e 100644 --- a/GitItGUI.Core/AppManager.cs +++ b/GitItGUI.Core/AppManager.cs @@ -29,7 +29,8 @@ public enum UpdateCheckResult BadVersionError, GitVersionCheckError, GitLFSVersionCheckError, - GitVersionToLowForLFS + GitVersionToLowForLFS, + UnicodeSettingsFailed } public delegate void CheckForUpdatesCallbackMethod(UpdateCheckResult result); @@ -216,7 +217,7 @@ public static void Dispose() DebugLog.Dispose(); } - public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod checkForUpdatesCallback) + public static void ValidateSystem(string url, CheckForUpdatesCallbackMethod checkForUpdatesCallback) { try { @@ -236,7 +237,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che catch { DebugLog.LogError("git is not installed correctly. (Make sure git is usable in the cmd/terminal)"); - client.Dispose(); if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitNotInstalledError); DownloadGit(); return; @@ -250,30 +250,24 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che catch { DebugLog.LogError("git-lfs is not installed correctly. (Make sure git-lfs is usable in the cmd/terminal)"); - client.Dispose(); if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitLFSNotInstalledError); DownloadGitLFS(); return; } // grab git version value - string appendix = ""; - if (PlatformInfo.platform == Platforms.Windows) appendix = @"\.windows"; - var match = Regex.Match(gitVersion, @"git version (.*)" + appendix); + var match = Regex.Match(gitVersion, @"git version (\d*\.\d*\.\d*)"); if (match.Success && match.Groups.Count == 2) gitVersion = match.Groups[1].Value; else { DebugLog.LogError("Failed to grab git version!"); - client.Dispose(); if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitVersionCheckError); DownloadGit(); return; } // grab lfs and required git version value - if (PlatformInfo.platform == Platforms.Windows) appendix = @"; git .*\)"; - else appendix = @"\)"; - match = Regex.Match(gitlfsVersion, @"git-lfs/(.*) \(GitHub; (\w*) (\w*); go (.*)" + appendix); + match = Regex.Match(gitlfsVersion, @"git-lfs/(\d*\.\d*\.\d*) \(GitHub; (\w*) (\w*); go (\d*\.\d*\.\d*)"); if (match.Success && match.Groups.Count == 5) { gitlfsVersion = match.Groups[1].Value; @@ -282,7 +276,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che else { DebugLog.LogError("Failed to grab git-lfs version!"); - client.Dispose(); if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitLFSVersionCheckError); DownloadGitLFS(); return; @@ -292,7 +285,6 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che if (!IsValidVersion(gitVersion, gitlfsRequiredGitVersion)) { DebugLog.LogError(string.Format("'git-lfs' version is not compatible with 'git' version installed!")); - client.Dispose(); if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.GitVersionToLowForLFS); DownloadGit(); DownloadGitLFS(); @@ -321,6 +313,14 @@ public static void CheckForUpdates(string url, CheckForUpdatesCallbackMethod che return; } + // make sure git prints unicode filenames + if (!repository.EnsureUnicodeEnabledGlobally()) + { + DebugLog.LogError("Git unicode support is not enabled or failed to be enabled!"); + if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.UnicodeSettingsFailed); + return; + } + // check app version client = new WebClient(); client.DownloadStringCompleted += Client_DownloadStringCompleted; @@ -419,6 +419,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString { DebugLog.LogError("Failed to check for updates: " + e.Error.Message); client.Dispose(); + client = null; if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.CommonError); return; } @@ -427,6 +428,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString { DebugLog.LogError("Update check canceled!"); client.Dispose(); + client = null; if (checkForUpdatesCallback != null) checkForUpdatesCallback(UpdateCheckResult.CommonError); return; } @@ -461,6 +463,7 @@ private static void Client_DownloadStringCompleted(object sender, DownloadString } client.Dispose(); + client = null; } } } diff --git a/GitItGUI.Core/RepoManager.cs b/GitItGUI.Core/RepoManager.cs index 6615d70..6822f06 100644 --- a/GitItGUI.Core/RepoManager.cs +++ b/GitItGUI.Core/RepoManager.cs @@ -141,6 +141,9 @@ public bool Open(string repoPath, bool checkForSettingErros = false) // load repo if (isRefreshMode) repository.Close(); if (!repository.Open(repoPath)) throw new Exception(repository.lastError); + + // validate unicode is disabled locally + if (!repository.EnsureUnicodeDisabledLocally()) return false; // check for git lfs lfsEnabled = repository.lfs.isEnabled; diff --git a/GitItGUI.UI/GitItGUI.UI.csproj b/GitItGUI.UI/GitItGUI.UI.csproj index 4e2b516..e035128 100644 --- a/GitItGUI.UI/GitItGUI.UI.csproj +++ b/GitItGUI.UI/GitItGUI.UI.csproj @@ -59,6 +59,9 @@ prompt true + + app.manifest + ..\packages\Magick.NET-Q16-x64.8.2.1\lib\net20\Magick.NET-Q16-x64.dll @@ -232,6 +235,7 @@ ResXFileCodeGenerator Resources.Designer.cs + SettingsSingleFileGenerator @@ -243,7 +247,6 @@ - diff --git a/GitItGUI.UI/MainWindow.xaml.cs b/GitItGUI.UI/MainWindow.xaml.cs index ac69253..aa54c46 100644 --- a/GitItGUI.UI/MainWindow.xaml.cs +++ b/GitItGUI.UI/MainWindow.xaml.cs @@ -30,8 +30,10 @@ public partial class MainWindow : Window public MainWindow() { // UnhandledException + #if !DEBUG AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Dispatcher.UnhandledException += Dispatcher_UnhandledException; + #endif // init debug log DebugLog.Log("Git-It-GUI v" + VersionInfo.version + Environment.NewLine); @@ -68,9 +70,9 @@ public MainWindow() if (AppManager.settings.winMaximized) WindowState = WindowState.Maximized; } - // version check + // validate system Title += " v" + VersionInfo.versionType; - AppManager.CheckForUpdates("http://reign-studios-services.com/GitItGUI/VersionInfo.xml", CheckForUpdatesCallback); + AppManager.ValidateSystem("http://reign-studios-services.com/GitItGUI/VersionInfo.xml", CheckForUpdatesCallback); } private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) @@ -115,6 +117,11 @@ internal void Dispatcher_UnhandledException(object sender, System.Windows.Thread Environment.Exit(2); } + public void ShowSystemErrorMessageBox(string title, string message) + { + MessageBox.Show(this, message, title, MessageBoxButton.OK, MessageBoxImage.Error); + } + private void CheckForUpdatesCallback(UpdateCheckResult result) { Dispatcher.InvokeAsync(delegate() @@ -122,14 +129,16 @@ private void CheckForUpdatesCallback(UpdateCheckResult result) bool shouldExit = true; switch (result) { - case UpdateCheckResult.BadVersionError: ShowMessageOverlay("Error", "Git or (git-lfs) versions are incompatible with this app"); break; - case UpdateCheckResult.GitVersionToLowForLFS: ShowMessageOverlay("Error", "The git version installed is incompatible with the lfs version isntalled"); break; + case UpdateCheckResult.BadVersionError: ShowSystemErrorMessageBox("Error", "Git or (git-lfs) versions are incompatible with this app"); break; + case UpdateCheckResult.GitVersionToLowForLFS: ShowSystemErrorMessageBox("Error", "The git version installed is incompatible with the lfs version isntalled"); break; - case UpdateCheckResult.GitNotInstalledError: ShowMessageOverlay("Error", "Git is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break; - case UpdateCheckResult.GitLFSNotInstalledError: ShowMessageOverlay("Error", "Git-LFS is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break; + case UpdateCheckResult.GitNotInstalledError: ShowSystemErrorMessageBox("Error", "Git is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break; + case UpdateCheckResult.GitLFSNotInstalledError: ShowSystemErrorMessageBox("Error", "Git-LFS is not installed or installed incorrectly.\nMake sure you're able to use it in cmd/term prompt"); break; - case UpdateCheckResult.GitVersionCheckError: ShowMessageOverlay("Error", "Git version parse failed.\nIts possible the git version you're using isn't supported"); break; - case UpdateCheckResult.GitLFSVersionCheckError: ShowMessageOverlay("Error", "Git-LFS version parse failed.\nIts possible the git-lfs version you're using isn't supported"); break; + case UpdateCheckResult.GitVersionCheckError: ShowSystemErrorMessageBox("Error", "Git version parse failed.\nIts possible the git version you're using isn't supported"); break; + case UpdateCheckResult.GitLFSVersionCheckError: ShowSystemErrorMessageBox("Error", "Git-LFS version parse failed.\nIts possible the git-lfs version you're using isn't supported"); break; + + case UpdateCheckResult.UnicodeSettingsFailed: ShowSystemErrorMessageBox("Error", "Git unicode support is not enabled or failed to be enabled!"); break; case UpdateCheckResult.AppVersionOutOfDate: shouldExit = false; diff --git a/GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs b/GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs index 229a6b0..a0266ce 100644 --- a/GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs +++ b/GitItGUI.UI/Overlays/NameEntryOverlay.xaml.cs @@ -64,7 +64,12 @@ private void okButton_Click(object sender, RoutedEventArgs e) { Visibility = Visibility.Hidden; var item = (ComboBoxItem)remoteComboBox.SelectedItem; - if (doneCallback != null) doneCallback(nameTextBox.Text, item.Content as string, true); + if (doneCallback != null) + { + string remoteName = null; + if (item != null) remoteName = item.Content as string; + doneCallback(nameTextBox.Text, remoteName, true); + } } } } diff --git a/GitItGUI.UI/app.manifest b/GitItGUI.UI/app.manifest new file mode 100644 index 0000000..9ce67d2 --- /dev/null +++ b/GitItGUI.UI/app.manifest @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Installer/Git-It-GUI_Installer.aip b/Installer/Git-It-GUI_Installer.aip index 7a88d9b..3165260 100644 --- a/Installer/Git-It-GUI_Installer.aip +++ b/Installer/Git-It-GUI_Installer.aip @@ -1,5 +1,5 @@ - + @@ -11,10 +11,10 @@ - + - + diff --git a/GitItGUI.UI/VersionInfo.xml b/UpdateCheckFiles/VersionInfo.xml similarity index 69% rename from GitItGUI.UI/VersionInfo.xml rename to UpdateCheckFiles/VersionInfo.xml index a8c0efc..d050394 100644 --- a/GitItGUI.UI/VersionInfo.xml +++ b/UpdateCheckFiles/VersionInfo.xml @@ -1,4 +1,4 @@  - 1.0.6 + 1.0.8