diff --git a/src/Files.App/Helpers/GitHelpers.cs b/src/Files.App/Helpers/GitHelpers.cs index 2ac828170b08..e97886564729 100644 --- a/src/Files.App/Helpers/GitHelpers.cs +++ b/src/Files.App/Helpers/GitHelpers.cs @@ -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 @@ -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; + } } } } diff --git a/src/Files.App/ViewModels/CurrentInstanceViewModel.cs b/src/Files.App/ViewModels/CurrentInstanceViewModel.cs index c87ee683b639..3ed00102b936 100644 --- a/src/Files.App/ViewModels/CurrentInstanceViewModel.cs +++ b/src/Files.App/ViewModels/CurrentInstanceViewModel.cs @@ -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;