Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Fixed crash that would occur in git directories on WSL drives #12307

Merged
merged 1 commit into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Files.App/Helpers/GitHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the MIT License. See the LICENSE.

using LibGit2Sharp;
using System;
using Files.App.Filesystem.StorageItems;

namespace Files.App.Helpers
Expand All @@ -22,9 +21,16 @@ public static class GitHelpers
)
return null;

return Repository.IsValid(path)
? path
: GetGitRepositoryPath(PathNormalization.GetParentDir(path), root);
try
{
return Repository.IsValid(path)
? path
: GetGitRepositoryPath(PathNormalization.GetParentDir(path), root);
}
catch (LibGit2SharpException)
{
return null;
}
}
}
}
4 changes: 2 additions & 2 deletions src/Files.App/ViewModels/CurrentInstanceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ public string GitBranchName
if (IsGitRepository)
{
using var repository = new Repository(gitRepositoryPath);
return repository.Branches.First(branch =>
branch.IsCurrentRepositoryHead).FriendlyName;
return repository.Branches.FirstOrDefault(branch =>
branch.IsCurrentRepositoryHead)?.FriendlyName ?? string.Empty;
}

return string.Empty;
Expand Down