Skip to content

Commit

Permalink
Merge pull request #10 from Cysharp/hotfix/AdjustSolutionItem
Browse files Browse the repository at this point in the history
Adjust the path of SolutionItem at merge
  • Loading branch information
mayuki authored Jul 14, 2020
2 parents 25c3fd4 + d6be67c commit 3c9fef5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/Editor/SlnMerge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,21 @@ private static void MergeProjects(SlnMergeMergeContext ctx)
}
}

if (!project.Value.IsFolder)
if (project.Value.IsFolder)
{
// If the project is a folder and it contains solution items, we adjust the path of solution items.
if (project.Value.Sections.TryGetValue(("SolutionItems", "preProject"), out var solutionItems))
{
foreach (var solutionItem in solutionItems.Values.ToArray())
{
solutionItems.Values.Remove(solutionItem.Key);
var solutionItemPathAbsolute = NormalizePath(Path.Combine(Path.GetDirectoryName(ctx.OverlaySolutionFile.Path), solutionItem.Key));
var solutionItemPathRelative = MakeRelative(ctx.MergedSolutionFile.Path, solutionItemPathAbsolute);
solutionItems.Values[solutionItemPathRelative] = solutionItemPathRelative;
}
}
}
else
{
var overlayProjectPathAbsolute = NormalizePath(Path.Combine(Path.GetDirectoryName(ctx.OverlaySolutionFile.Path), project.Value.Path));
project.Value.Path = MakeRelative(ctx.MergedSolutionFile.Path, overlayProjectPathAbsolute);
Expand Down
42 changes: 42 additions & 0 deletions test/SlnMerge.Tests/SlnMergeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,48 @@ public void Merge_SolutionFolder_ExistedFolder_SectionExists()
".Trim(), content.Trim());
}

[Fact]
public void Merge_SolutionItems()
{
var baseSln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Unity.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Global
EndGlobal
".Trim());
var overlaySln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Server\Nantoka.Server.sln", @"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29509.3
MinimumVisualStudioVersion = 10.0.40219.1
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Project Settings"", ""Project Settings"", ""{34006C71-946B-49BF-BBCB-BB091E5A3AE7}""
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
EndProjectSection
EndProject
Global
EndGlobal
".Trim());

var mergedSolutionFile = SlnMerge.Merge(
baseSln,
overlaySln,
new SlnMergeSettings(),
SlnMergeNullLogger.Instance);
var content = mergedSolutionFile.ToFileContent();
Assert.Equal((@"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 16
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Project Settings"", ""Project Settings"", ""{34006C71-946B-49BF-BBCB-BB091E5A3AE7}""
ProjectSection(SolutionItems) = preProject
..\Nantoka.Server\.gitignore = ..\Nantoka.Server\.gitignore
EndProjectSection
EndProject
Global
EndGlobal
").Trim(), content.Trim());
}

[Fact]
public void TestMerge()
{
Expand Down

0 comments on commit 3c9fef5

Please sign in to comment.