Skip to content

Commit

Permalink
Merge branch 'idempotency-fix' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
timabell committed Dec 22, 2023
2 parents cae1f8c + b16a4ec commit 08ac96f
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CLI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private void SyncFolder(SolutionFolder parentFolder, DirectoryInfo directory, st
var solutionFolder = FindOrCreateSolutionFolder(parentFolder.Projects, directory.Name, directory.Name);
foreach (var file in directory.EnumerateFiles())
{
if (solutionFolder.Files.All(f => f != file.Name))
if (solutionFolder.Files.All(f => f.Split('\\').Last() != file.Name))
{
solutionFolder.Files.Add($"{path}{file.Name}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/sln-items-sync.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="SlnEditor" Version="2.2.1" />
<PackageReference Include="SlnEditor" Version="2.2.2" />
</ItemGroup>
</Project>
85 changes: 85 additions & 0 deletions tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,91 @@ public void AddsToBlankSln()
ModifiedSln().Should().Be(expected);
}

[Fact]
public void IgnoresExistingItems()
{
// Arrange
SetupSln(@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""SolutionItems"", ""SolutionItems"", ""{17591C35-3F90-4F4A-AA13-45CF8D824066}""
ProjectSection(SolutionItems) = preProject
rootfile.txt = rootfile.txt
EndProjectSection
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""subfolder"", ""subfolder"", ""{CF942CDD-19AC-4E52-9C6E-B1381E0406D9}""
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""nested_folder"", ""nested_folder"", ""{F5636E74-888A-4FBD-A8E2-9718A05D90BD}""
ProjectSection(SolutionItems) = preProject
subfolder\nested_folder\nested_file.txt = subfolder\nested_folder\nested_file.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CF942CDD-19AC-4E52-9C6E-B1381E0406D9} = {17591C35-3F90-4F4A-AA13-45CF8D824066}
{F5636E74-888A-4FBD-A8E2-9718A05D90BD} = {CF942CDD-19AC-4E52-9C6E-B1381E0406D9}
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
");

SetupFilesystem(new[]
{
"rootfile.txt",
"subfolder/nested_folder/nested_file.txt",
});

// Act
_cli.Run(new[] { "-s", TargetSlnFile, "rootfile.txt", "subfolder" });

// Assert
const string expected = @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""SolutionItems"", ""SolutionItems"", ""{17591C35-3F90-4F4A-AA13-45CF8D824066}""
ProjectSection(SolutionItems) = preProject
rootfile.txt = rootfile.txt
EndProjectSection
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""subfolder"", ""subfolder"", ""{CF942CDD-19AC-4E52-9C6E-B1381E0406D9}""
EndProject
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""nested_folder"", ""nested_folder"", ""{F5636E74-888A-4FBD-A8E2-9718A05D90BD}""
ProjectSection(SolutionItems) = preProject
subfolder\nested_folder\nested_file.txt = subfolder\nested_folder\nested_file.txt
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{CF942CDD-19AC-4E52-9C6E-B1381E0406D9} = {17591C35-3F90-4F4A-AA13-45CF8D824066}
{F5636E74-888A-4FBD-A8E2-9718A05D90BD} = {CF942CDD-19AC-4E52-9C6E-B1381E0406D9}
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
";

ModifiedSln().Should().Be(expected);
}

private string ModifiedSln() => File.ReadAllText(Path.Combine(_testFolder, TargetSlnFile));

private void SetupFilesystem(IEnumerable<string> paths)
Expand Down

0 comments on commit 08ac96f

Please sign in to comment.