3
3
4
4
using Files . App . Dialogs ;
5
5
using LibGit2Sharp ;
6
- using Sentry ;
7
6
using Microsoft . Extensions . Logging ;
7
+ using Sentry ;
8
8
using System . Net . Http ;
9
9
using System . Net . Http . Json ;
10
- using System . Net . Sockets ;
11
10
using System . Text ;
12
- using System . Text . Json ;
13
11
14
12
namespace Files . App . Utils . Git
15
13
{
@@ -78,7 +76,7 @@ private set
78
76
79
77
try
80
78
{
81
- if ( Repository . IsValid ( path ) )
79
+ if ( IsRepoValid ( path ) )
82
80
return path ;
83
81
else
84
82
{
@@ -99,7 +97,7 @@ private set
99
97
100
98
public static string GetOriginRepositoryName ( string ? path )
101
99
{
102
- if ( string . IsNullOrWhiteSpace ( path ) || ! Repository . IsValid ( path ) )
100
+ if ( string . IsNullOrWhiteSpace ( path ) || ! IsRepoValid ( path ) )
103
101
return string . Empty ;
104
102
105
103
using var repository = new Repository ( path ) ;
@@ -114,7 +112,7 @@ public static string GetOriginRepositoryName(string? path)
114
112
115
113
public static async Task < BranchItem [ ] > GetBranchesNames ( string ? path )
116
114
{
117
- if ( string . IsNullOrWhiteSpace ( path ) || ! Repository . IsValid ( path ) )
115
+ if ( string . IsNullOrWhiteSpace ( path ) || ! IsRepoValid ( path ) )
118
116
return [ ] ;
119
117
120
118
var ( result , returnValue ) = await DoGitOperationAsync < ( GitOperationResult , BranchItem [ ] ) > ( ( ) =>
@@ -146,7 +144,7 @@ public static async Task<BranchItem[]> GetBranchesNames(string? path)
146
144
147
145
public static async Task < BranchItem ? > GetRepositoryHead ( string ? path )
148
146
{
149
- if ( string . IsNullOrWhiteSpace ( path ) || ! Repository . IsValid ( path ) )
147
+ if ( string . IsNullOrWhiteSpace ( path ) || ! IsRepoValid ( path ) )
150
148
return null ;
151
149
152
150
var ( _, returnValue ) = await DoGitOperationAsync < ( GitOperationResult , BranchItem ? ) > ( ( ) =>
@@ -181,7 +179,7 @@ public static async Task<bool> Checkout(string? repositoryPath, string? branch)
181
179
// Re-enable when Metris feature is available again
182
180
// SentrySdk.Metrics.Increment("Triggered git checkout");
183
181
184
- if ( string . IsNullOrWhiteSpace ( repositoryPath ) || ! Repository . IsValid ( repositoryPath ) )
182
+ if ( string . IsNullOrWhiteSpace ( repositoryPath ) || ! IsRepoValid ( repositoryPath ) )
185
183
return false ;
186
184
187
185
using var repository = new Repository ( repositoryPath ) ;
@@ -289,7 +287,7 @@ public static async Task DeleteBranchAsync(string? repositoryPath, string? activ
289
287
string . IsNullOrWhiteSpace ( activeBranch ) ||
290
288
string . IsNullOrWhiteSpace ( branchToDelete ) ||
291
289
activeBranch . Equals ( branchToDelete , StringComparison . OrdinalIgnoreCase ) ||
292
- ! Repository . IsValid ( repositoryPath ) )
290
+ ! IsRepoValid ( repositoryPath ) )
293
291
{
294
292
return ;
295
293
}
@@ -322,7 +320,7 @@ await DoGitOperationAsync<GitOperationResult>(() =>
322
320
323
321
public static bool ValidateBranchNameForRepository ( string branchName , string repositoryPath )
324
322
{
325
- if ( string . IsNullOrEmpty ( branchName ) || ! Repository . IsValid ( repositoryPath ) )
323
+ if ( string . IsNullOrEmpty ( branchName ) || ! IsRepoValid ( repositoryPath ) )
326
324
return false ;
327
325
328
326
var nameValidator = RegexHelpers . GitBranchName ( ) ;
@@ -649,7 +647,7 @@ public static bool IsRepositoryEx(string path, out string repoRootPath)
649
647
if ( string . IsNullOrEmpty ( repositoryRootPath ) )
650
648
return false ;
651
649
652
- if ( Repository . IsValid ( repositoryRootPath ) )
650
+ if ( ! IsRepoValid ( repositoryRootPath ) )
653
651
{
654
652
repoRootPath = repositoryRootPath ;
655
653
return true ;
@@ -737,6 +735,11 @@ public static async Task InitializeRepositoryAsync(string? path)
737
735
}
738
736
}
739
737
738
+ private static bool IsRepoValid ( string path )
739
+ {
740
+ return SafetyExtensions . IgnoreExceptions ( ( ) => Repository . IsValid ( path ) ) ;
741
+ }
742
+
740
743
private static IEnumerable < Branch > GetValidBranches ( BranchCollection branches )
741
744
{
742
745
foreach ( var branch in branches )
0 commit comments