Skip to content

Commit c3743bf

Browse files
Fix: Fixed crash that would occur in git directories on WSL drives (#12307)
1 parent 79754bf commit c3743bf

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Files.App/Helpers/GitHelpers.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License. See the LICENSE.
33

44
using LibGit2Sharp;
5-
using System;
65
using Files.App.Filesystem.StorageItems;
76

87
namespace Files.App.Helpers
@@ -22,9 +21,16 @@ public static class GitHelpers
2221
)
2322
return null;
2423

25-
return Repository.IsValid(path)
26-
? path
27-
: GetGitRepositoryPath(PathNormalization.GetParentDir(path), root);
24+
try
25+
{
26+
return Repository.IsValid(path)
27+
? path
28+
: GetGitRepositoryPath(PathNormalization.GetParentDir(path), root);
29+
}
30+
catch (LibGit2SharpException)
31+
{
32+
return null;
33+
}
2834
}
2935
}
3036
}

src/Files.App/ViewModels/CurrentInstanceViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ public string GitBranchName
181181
if (IsGitRepository)
182182
{
183183
using var repository = new Repository(gitRepositoryPath);
184-
return repository.Branches.First(branch =>
185-
branch.IsCurrentRepositoryHead).FriendlyName;
184+
return repository.Branches.FirstOrDefault(branch =>
185+
branch.IsCurrentRepositoryHead)?.FriendlyName ?? string.Empty;
186186
}
187187

188188
return string.Empty;

0 commit comments

Comments
 (0)