@@ -74,17 +74,12 @@ public static async Task<int> MigrateAsync(
74
74
new [ ] { outDir , PathUtils . GetLeaf ( rootPath ) , projectCollectionUrl . Segments . LastOrDefault ( ) }
75
75
. First ( name => ! string . IsNullOrEmpty ( name ) ) ! ) ;
76
76
77
- Directory . CreateDirectory ( outputDirectory ) ;
78
- if ( Directory . GetFileSystemEntries ( outputDirectory ) . Any ( ) )
79
- {
80
- Console . WriteLine ( $ "Cannot create Git repository at { outputDirectory } because the directory is not empty.") ;
77
+ using var repo = InitRepository ( outputDirectory ) ;
78
+ if ( repo is null )
81
79
return 1 ;
82
- }
83
80
84
81
var authorsLookup = LoadAuthors ( authors ) ;
85
82
86
- using var repo = new Repository ( Repository . Init ( outputDirectory ) ) ;
87
-
88
83
Console . WriteLine ( "Connecting..." ) ;
89
84
90
85
using var connection = new VssConnection (
@@ -339,6 +334,32 @@ pat is not null
339
334
return 0 ;
340
335
}
341
336
337
+ private static Repository ? InitRepository ( string outputDirectory )
338
+ {
339
+ Directory . CreateDirectory ( outputDirectory ) ;
340
+
341
+ var existingFileSystemEntries = Directory . GetFileSystemEntries ( outputDirectory ) ;
342
+ if ( ! existingFileSystemEntries . Any ( ) )
343
+ return new Repository ( Repository . Init ( outputDirectory ) ) ;
344
+
345
+ if ( existingFileSystemEntries is not [ var singleFileSystemEntry ]
346
+ || ! ".git" . Equals ( Path . GetFileName ( singleFileSystemEntry ) , StringComparison . OrdinalIgnoreCase ) )
347
+ {
348
+ Console . WriteLine ( $ "Cannot create Git repository at { outputDirectory } because the directory is not empty.") ;
349
+ return null ;
350
+ }
351
+
352
+ var repository = new Repository ( singleFileSystemEntry ) ;
353
+ if ( repository . ObjectDatabase . Any ( ) )
354
+ {
355
+ repository . Dispose ( ) ;
356
+ Console . WriteLine ( $ "A Git repository at { outputDirectory } already exists and is not empty.") ;
357
+ return null ;
358
+ }
359
+
360
+ return repository ;
361
+ }
362
+
342
363
private static ImmutableDictionary < BranchIdentity , ImmutableArray < ( string GitRepositoryPath , TfvcItem DownloadSource ) > > MapItemsToDownloadSources (
343
364
ImmutableArray < ( BranchIdentity Branch , RepositoryBranchMapping Mapping ) > branchMappingsInDependentOperationOrder ,
344
365
ImmutableArray < TfvcItem > currentItems )
0 commit comments