From bfee15fce666dc7411028ae3bc62f162673c78aa Mon Sep 17 00:00:00 2001 From: Gerhard Olsson Date: Wed, 19 Jan 2022 21:48:32 +0100 Subject: [PATCH] fixup! Ignore nonexisting submodule paths --- .../RepoObjectsTree.Nodes.Submodules.cs | 12 ++++++++---- GitUI/CommandsDialogs/FormBrowse.cs | 3 +-- GitUI/CommandsDialogs/RevisionFileTreeControl.cs | 9 ++++++++- GitUI/GitUICommands.cs | 4 +--- GitUI/MessageBoxes.cs | 14 ++++++++++++++ GitUI/Translation/English.xlf | 16 ++++++++++++++++ GitUI/UserControls/FileStatusList.cs | 9 ++++++++- 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs b/GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs index a2a5e3f252a..204405bb99c 100644 --- a/GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs +++ b/GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs @@ -95,8 +95,7 @@ public void Open() { if (!Directory.Exists(Info.Path)) { - MessageBox.Show(null, $@"The directory ""{Info.Path}"" does not exist for submodule ""{Info.Text}"".", "Cannot open submodule", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, Info.Path, Info.Text); return; } @@ -111,6 +110,12 @@ public void Open() public void LaunchGitExtensions() { + if (!Directory.Exists(Info.Path)) + { + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, Info.Path, Info.Text); + return; + } + GitUICommands.LaunchBrowse(workingDir: Info.Path.EnsureTrailingPathSeparator(), ObjectId.WorkTreeId, Info?.Detailed?.RawStatus?.OldCommit); } @@ -409,8 +414,7 @@ private void CreateSubmoduleNodes(SubmoduleInfoResult result, GitModule threadMo string? superPath = GetSubmoduleSuperPath(submoduleInfo.Path); if (!Directory.Exists(superPath)) { - MessageBox.Show(null, $@"The directory ""{superPath}"" does not exist for submodule ""{submoduleInfo.Text}"".", "Cannot open submodule", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, superPath ?? submoduleInfo.Path, submoduleInfo.Text); continue; } diff --git a/GitUI/CommandsDialogs/FormBrowse.cs b/GitUI/CommandsDialogs/FormBrowse.cs index 307251712b3..6c53fe50ed9 100644 --- a/GitUI/CommandsDialogs/FormBrowse.cs +++ b/GitUI/CommandsDialogs/FormBrowse.cs @@ -2498,8 +2498,7 @@ private void SubmoduleToolStripButtonClick(object sender, EventArgs e) string path = menuSender.Tag as string; if (!Directory.Exists(path)) { - MessageBox.Show(null, $@"The directory ""{path}"" does not exist.", "Cannot open submodule", - MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, path); return; } diff --git a/GitUI/CommandsDialogs/RevisionFileTreeControl.cs b/GitUI/CommandsDialogs/RevisionFileTreeControl.cs index c9a85e88f52..3021710e366 100644 --- a/GitUI/CommandsDialogs/RevisionFileTreeControl.cs +++ b/GitUI/CommandsDialogs/RevisionFileTreeControl.cs @@ -345,7 +345,14 @@ private void OnItemActivated() private void SpawnCommitBrowser(GitItem item) { - GitUICommands.LaunchBrowse(workingDir: _fullPathResolver.Resolve(item.FileName.EnsureTrailingPathSeparator()) ?? "", selectedId: item.ObjectId); + string path = _fullPathResolver.Resolve(item.FileName.EnsureTrailingPathSeparator()) ?? ""; + if (!Directory.Exists(path)) + { + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, path, item.Name); + return; + } + + GitUICommands.LaunchBrowse(workingDir: path, selectedId: item.ObjectId); } private void tvGitTree_AfterSelect(object sender, TreeViewEventArgs e) diff --git a/GitUI/GitUICommands.cs b/GitUI/GitUICommands.cs index ad29e03ecba..2ab2c9da9b8 100644 --- a/GitUI/GitUICommands.cs +++ b/GitUI/GitUICommands.cs @@ -373,9 +373,7 @@ public static void LaunchBrowse(string workingDir = "", ObjectId? selectedId = n { if (!Directory.Exists(workingDir)) { - MessageBox.Show(null, $@"The directory ""{workingDir}"" does not exist.", "Cannot open Git Extensions", - MessageBoxButtons.OK, MessageBoxIcon.Error); - + MessageBoxes.GitExtensionsDirectoryDoesNotExist(null, workingDir); return; } diff --git a/GitUI/MessageBoxes.cs b/GitUI/MessageBoxes.cs index 1e379c367a5..2225ddb8ad9 100644 --- a/GitUI/MessageBoxes.cs +++ b/GitUI/MessageBoxes.cs @@ -44,6 +44,11 @@ public class MessageBoxes : Translate private readonly TranslationString _shellNotFound = new("The selected shell is not installed, or is not on your path."); private readonly TranslationString _resetChangesCaption = new("Reset changes"); + private readonly TranslationString _submoduleDirectoryDoesNotExist = new(@"The directory ""{0}"" does not exist for submodule ""{1}""."); + private readonly TranslationString _directoryDoesNotExist = new(@"The directory ""{0}"" does not exist."); + private readonly TranslationString _cannotOpenSubmoduleCaption = new("Cannot open submodule"); + private readonly TranslationString _cannotOpenGitExtensionsCaption = new("Cannot open Git Extensions"); + // internal for FormTranslate internal MessageBoxes() { @@ -81,6 +86,15 @@ public static void PAgentNotFound(IWin32Window? owner) public static void SelectOnlyOneOrTwoRevisions(IWin32Window? owner) => ShowError(owner, Instance._selectOnlyOneOrTwoRevisions.Text, Instance._archiveRevisionCaption.Text); + public static void SubmoduleDirectoryDoesNotExist(IWin32Window? owner, string directory, string submoduleName) + => ShowError(owner, string.Format(Instance._submoduleDirectoryDoesNotExist.Text, directory, submoduleName), Instance._cannotOpenSubmoduleCaption.Text); + + public static void SubmoduleDirectoryDoesNotExist(IWin32Window? owner, string directory) + => ShowError(owner, string.Format(Instance._directoryDoesNotExist.Text, directory), Instance._cannotOpenSubmoduleCaption.Text); + + public static void GitExtensionsDirectoryDoesNotExist(IWin32Window? owner, string directory) + => ShowError(owner, string.Format(Instance._directoryDoesNotExist.Text, directory), Instance._cannotOpenGitExtensionsCaption.Text); + public static bool CacheHostkey(IWin32Window? owner) => Confirm(owner, Instance._serverHostkeyNotCachedText.Text, "SSH"); diff --git a/GitUI/Translation/English.xlf b/GitUI/Translation/English.xlf index be3f60f7931..6e97f5d5dfa 100644 --- a/GitUI/Translation/English.xlf +++ b/GitUI/Translation/English.xlf @@ -8649,6 +8649,18 @@ help Archive revision + + Cannot open Git Extensions + + + + Cannot open submodule + + + + The directory "{0}" does not exist. + + Failed to execute script @@ -8711,6 +8723,10 @@ Do you want to trust this host key and then try again? Shell not found + + The directory "{0}" does not exist for submodule "{1}". + + Update submodules on checkout? diff --git a/GitUI/UserControls/FileStatusList.cs b/GitUI/UserControls/FileStatusList.cs index 7c0cefc7631..fc383a653f0 100644 --- a/GitUI/UserControls/FileStatusList.cs +++ b/GitUI/UserControls/FileStatusList.cs @@ -852,7 +852,14 @@ public async Task OpenSubmoduleAsync() : status?.Commit; ObjectId? firstId = status?.OldCommit; - GitUICommands.LaunchBrowse(workingDir: _fullPathResolver.Resolve(submoduleName.EnsureTrailingPathSeparator()) ?? "", selectedId, firstId); + string path = _fullPathResolver.Resolve(submoduleName.EnsureTrailingPathSeparator()) ?? ""; + if (!Directory.Exists(path)) + { + MessageBoxes.SubmoduleDirectoryDoesNotExist(null, path, submoduleName); + return; + } + + GitUICommands.LaunchBrowse(workingDir: path, selectedId, firstId); } private void SelectItems(Func predicate)