@@ -12,7 +12,7 @@ namespace TfvcMigrator;
12
12
13
13
public static class Program
14
14
{
15
- public static Task Main ( string [ ] args )
15
+ public static Task < int > Main ( string [ ] args )
16
16
{
17
17
var command = new RootCommand ( "Migrates TFVC source history to idiomatic Git history while preserving branch topology." )
18
18
{
@@ -58,7 +58,7 @@ private static RootPathChange ParseRootPathChange(string token)
58
58
return new RootPathChange ( changeset , token [ ( colonIndex + 1 ) ..] ) ;
59
59
}
60
60
61
- public static async Task MigrateAsync (
61
+ public static async Task < int > MigrateAsync (
62
62
Uri projectCollectionUrl ,
63
63
string rootPath ,
64
64
string authors ,
@@ -74,17 +74,12 @@ public static async Task 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.") ;
81
- return ;
82
- }
77
+ using var repo = InitRepository ( outputDirectory ) ;
78
+ if ( repo is null )
79
+ return 1 ;
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 (
@@ -131,7 +126,7 @@ pat is not null
131
126
Console . WriteLine ( "An entry must be added to the authors file for each of the following TFVC users:" ) ;
132
127
foreach ( var user in unmappedAuthors )
133
128
Console . WriteLine ( user ) ;
134
- return ;
129
+ return 1 ;
135
130
}
136
131
137
132
Console . WriteLine ( "Downloading changesets and converting to commits..." ) ;
@@ -336,6 +331,33 @@ pat is not null
336
331
}
337
332
338
333
Console . WriteLine ( $ "\r All { changesets . Count } changesets migrated successfully.") ;
334
+ return 0 ;
335
+ }
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 ;
339
361
}
340
362
341
363
private static ImmutableDictionary < BranchIdentity , ImmutableArray < ( string GitRepositoryPath , TfvcItem DownloadSource ) > > MapItemsToDownloadSources (
0 commit comments