Skip to content

Commit 0753830

Browse files
committed
Return proper exit code for errors
1 parent d36251a commit 0753830

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/TfvcMigrator/InterceptableCommandHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public static Delegate Intercept(Delegate @delegate)
8686
{
8787
generator.Emit(OpCodes.Call, typeof(Task).GetProperty(nameof(Task.CompletedTask), BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)!.GetMethod!);
8888
}
89+
else if (@delegate.Method.ReturnType == typeof(Task<int>))
90+
{
91+
generator.Emit(OpCodes.Ldc_I4_0);
92+
generator.Emit(OpCodes.Call, typeof(Task).GetMethod(nameof(Task.FromResult), BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly)!.MakeGenericMethod(typeof(int)));
93+
}
8994
else
9095
{
9196
throw new NotImplementedException();

src/TfvcMigrator/Program.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace TfvcMigrator;
1212

1313
public static class Program
1414
{
15-
public static Task Main(string[] args)
15+
public static Task<int> Main(string[] args)
1616
{
1717
var command = new RootCommand("Migrates TFVC source history to idiomatic Git history while preserving branch topology.")
1818
{
@@ -58,7 +58,7 @@ private static RootPathChange ParseRootPathChange(string token)
5858
return new RootPathChange(changeset, token[(colonIndex + 1)..]);
5959
}
6060

61-
public static async Task MigrateAsync(
61+
public static async Task<int> MigrateAsync(
6262
Uri projectCollectionUrl,
6363
string rootPath,
6464
string authors,
@@ -78,7 +78,7 @@ public static async Task MigrateAsync(
7878
if (Directory.GetFileSystemEntries(outputDirectory).Any())
7979
{
8080
Console.WriteLine($"Cannot create Git repository at {outputDirectory} because the directory is not empty.");
81-
return;
81+
return 1;
8282
}
8383

8484
var authorsLookup = LoadAuthors(authors);
@@ -131,7 +131,7 @@ pat is not null
131131
Console.WriteLine("An entry must be added to the authors file for each of the following TFVC users:");
132132
foreach (var user in unmappedAuthors)
133133
Console.WriteLine(user);
134-
return;
134+
return 1;
135135
}
136136

137137
Console.WriteLine("Downloading changesets and converting to commits...");
@@ -336,6 +336,7 @@ pat is not null
336336
}
337337

338338
Console.WriteLine($"\rAll {changesets.Count} changesets migrated successfully.");
339+
return 0;
339340
}
340341

341342
private static ImmutableDictionary<BranchIdentity, ImmutableArray<(string GitRepositoryPath, TfvcItem DownloadSource)>> MapItemsToDownloadSources(

0 commit comments

Comments
 (0)