diff --git a/.editorconfig b/.editorconfig index dd0e093..7637b18 100644 --- a/.editorconfig +++ b/.editorconfig @@ -90,3 +90,6 @@ dotnet_diagnostic.SA1641.severity = none dotnet_diagnostic.SA1642.severity = none dotnet_diagnostic.SA1643.severity = none dotnet_diagnostic.SA1649.severity = none + +# Workaround for https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3503 +dotnet_diagnostic.SA1010.severity = none diff --git a/src/TfvcMigrator/Program.cs b/src/TfvcMigrator/Program.cs index 849cb90..4676ddd 100644 --- a/src/TfvcMigrator/Program.cs +++ b/src/TfvcMigrator/Program.cs @@ -74,17 +74,12 @@ private static RootPathChange ParseRootPathChange(string token) new[] { outDir, PathUtils.GetLeaf(rootPath), projectCollectionUrl.Segments.LastOrDefault() } .First(name => !string.IsNullOrEmpty(name))!); - Directory.CreateDirectory(outputDirectory); - if (Directory.GetFileSystemEntries(outputDirectory).Any()) - { - Console.WriteLine($"Cannot create Git repository at {outputDirectory} because the directory is not empty."); + using var repo = InitRepository(outputDirectory); + if (repo is null) return 1; - } var authorsLookup = LoadAuthors(authors); - using var repo = new Repository(Repository.Init(outputDirectory)); - Console.WriteLine("Connecting..."); using var connection = new VssConnection( @@ -339,6 +334,32 @@ private static RootPathChange ParseRootPathChange(string token) return 0; } + private static Repository? InitRepository(string outputDirectory) + { + Directory.CreateDirectory(outputDirectory); + + var existingFileSystemEntries = Directory.GetFileSystemEntries(outputDirectory); + if (!existingFileSystemEntries.Any()) + return new Repository(Repository.Init(outputDirectory)); + + if (existingFileSystemEntries is not [var singleFileSystemEntry] + || !".git".Equals(Path.GetFileName(singleFileSystemEntry), StringComparison.OrdinalIgnoreCase)) + { + Console.WriteLine($"Cannot create Git repository at {outputDirectory} because the directory is not empty."); + return null; + } + + var repository = new Repository(singleFileSystemEntry); + if (repository.ObjectDatabase.Any()) + { + repository.Dispose(); + Console.WriteLine($"A Git repository at {outputDirectory} already exists and is not empty."); + return null; + } + + return repository; + } + private static ImmutableDictionary> MapItemsToDownloadSources( ImmutableArray<(BranchIdentity Branch, RepositoryBranchMapping Mapping)> branchMappingsInDependentOperationOrder, ImmutableArray currentItems) diff --git a/src/TfvcMigrator/TfvcMigrator.csproj b/src/TfvcMigrator/TfvcMigrator.csproj index be4a577..d90c439 100644 --- a/src/TfvcMigrator/TfvcMigrator.csproj +++ b/src/TfvcMigrator/TfvcMigrator.csproj @@ -3,6 +3,7 @@ Exe net6.0 + 11 enable true