Skip to content

Commit

Permalink
fixup! Ignore nonexisting submodule paths
Browse files Browse the repository at this point in the history
  • Loading branch information
gerhardol committed Jan 19, 2022
1 parent 910867b commit bfee15f
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
12 changes: 8 additions & 4 deletions GitUI/BranchTreePanel/RepoObjectsTree.Nodes.Submodules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 1 addition & 2 deletions GitUI/CommandsDialogs/FormBrowse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
9 changes: 8 additions & 1 deletion GitUI/CommandsDialogs/RevisionFileTreeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions GitUI/GitUICommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions GitUI/MessageBoxes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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");

Expand Down
16 changes: 16 additions & 0 deletions GitUI/Translation/English.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -8649,6 +8649,18 @@ help</source>
<source>Archive revision</source>
<target />
</trans-unit>
<trans-unit id="_cannotOpenGitExtensionsCaption.Text">
<source>Cannot open Git Extensions</source>
<target />
</trans-unit>
<trans-unit id="_cannotOpenSubmoduleCaption.Text">
<source>Cannot open submodule</source>
<target />
</trans-unit>
<trans-unit id="_directoryDoesNotExist.Text">
<source>The directory "{0}" does not exist.</source>
<target />
</trans-unit>
<trans-unit id="_failedToExecuteScript.Text">
<source>Failed to execute script</source>
<target />
Expand Down Expand Up @@ -8711,6 +8723,10 @@ Do you want to trust this host key and then try again?</source>
<source>Shell not found</source>
<target />
</trans-unit>
<trans-unit id="_submoduleDirectoryDoesNotExist.Text">
<source>The directory "{0}" does not exist for submodule "{1}".</source>
<target />
</trans-unit>
<trans-unit id="_theRepositorySubmodules.Text">
<source>Update submodules on checkout?</source>
<target />
Expand Down
9 changes: 8 additions & 1 deletion GitUI/UserControls/FileStatusList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ListViewItem, bool> predicate)
Expand Down

0 comments on commit bfee15f

Please sign in to comment.