Skip to content

Commit 91d0f11

Browse files
committed
Enable using an existing empty repository created in a previous try
1 parent 0753830 commit 91d0f11

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,6 @@ dotnet_diagnostic.SA1641.severity = none
9090
dotnet_diagnostic.SA1642.severity = none
9191
dotnet_diagnostic.SA1643.severity = none
9292
dotnet_diagnostic.SA1649.severity = none
93+
94+
# Workaround for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3503
95+
dotnet_diagnostic.SA1010.severity = none

src/TfvcMigrator/Program.cs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,12 @@ public static async Task<int> MigrateAsync(
7474
new[] { outDir, PathUtils.GetLeaf(rootPath), projectCollectionUrl.Segments.LastOrDefault() }
7575
.First(name => !string.IsNullOrEmpty(name))!);
7676

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)
8179
return 1;
82-
}
8380

8481
var authorsLookup = LoadAuthors(authors);
8582

86-
using var repo = new Repository(Repository.Init(outputDirectory));
87-
8883
Console.WriteLine("Connecting...");
8984

9085
using var connection = new VssConnection(
@@ -339,6 +334,32 @@ pat is not null
339334
return 0;
340335
}
341336

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+
342363
private static ImmutableDictionary<BranchIdentity, ImmutableArray<(string GitRepositoryPath, TfvcItem DownloadSource)>> MapItemsToDownloadSources(
343364
ImmutableArray<(BranchIdentity Branch, RepositoryBranchMapping Mapping)> branchMappingsInDependentOperationOrder,
344365
ImmutableArray<TfvcItem> currentItems)

src/TfvcMigrator/TfvcMigrator.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net6.0</TargetFramework>
6+
<LangVersion>11</LangVersion>
67
<Nullable>enable</Nullable>
78
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
89

0 commit comments

Comments
 (0)