Skip to content

Commit 3c9fef5

Browse files
authored
Merge pull request #10 from Cysharp/hotfix/AdjustSolutionItem
Adjust the path of SolutionItem at merge
2 parents 25c3fd4 + d6be67c commit 3c9fef5

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

src/Editor/SlnMerge.cs

+15-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,21 @@ private static void MergeProjects(SlnMergeMergeContext ctx)
320320
}
321321
}
322322

323-
if (!project.Value.IsFolder)
323+
if (project.Value.IsFolder)
324+
{
325+
// If the project is a folder and it contains solution items, we adjust the path of solution items.
326+
if (project.Value.Sections.TryGetValue(("SolutionItems", "preProject"), out var solutionItems))
327+
{
328+
foreach (var solutionItem in solutionItems.Values.ToArray())
329+
{
330+
solutionItems.Values.Remove(solutionItem.Key);
331+
var solutionItemPathAbsolute = NormalizePath(Path.Combine(Path.GetDirectoryName(ctx.OverlaySolutionFile.Path), solutionItem.Key));
332+
var solutionItemPathRelative = MakeRelative(ctx.MergedSolutionFile.Path, solutionItemPathAbsolute);
333+
solutionItems.Values[solutionItemPathRelative] = solutionItemPathRelative;
334+
}
335+
}
336+
}
337+
else
324338
{
325339
var overlayProjectPathAbsolute = NormalizePath(Path.Combine(Path.GetDirectoryName(ctx.OverlaySolutionFile.Path), project.Value.Path));
326340
project.Value.Path = MakeRelative(ctx.MergedSolutionFile.Path, overlayProjectPathAbsolute);

test/SlnMerge.Tests/SlnMergeTest.cs

+42
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,48 @@ public void Merge_SolutionFolder_ExistedFolder_SectionExists()
443443
".Trim(), content.Trim());
444444
}
445445

446+
[Fact]
447+
public void Merge_SolutionItems()
448+
{
449+
var baseSln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Unity\Nantoka.Unity.sln", @"
450+
Microsoft Visual Studio Solution File, Format Version 12.00
451+
# Visual Studio 16
452+
Global
453+
EndGlobal
454+
".Trim());
455+
var overlaySln = SolutionFile.Parse(@"C:\Path\To\Nantoka\Nantoka.Server\Nantoka.Server.sln", @"
456+
Microsoft Visual Studio Solution File, Format Version 12.00
457+
# Visual Studio Version 16
458+
VisualStudioVersion = 16.0.29509.3
459+
MinimumVisualStudioVersion = 10.0.40219.1
460+
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Project Settings"", ""Project Settings"", ""{34006C71-946B-49BF-BBCB-BB091E5A3AE7}""
461+
ProjectSection(SolutionItems) = preProject
462+
.gitignore = .gitignore
463+
EndProjectSection
464+
EndProject
465+
Global
466+
EndGlobal
467+
".Trim());
468+
469+
var mergedSolutionFile = SlnMerge.Merge(
470+
baseSln,
471+
overlaySln,
472+
new SlnMergeSettings(),
473+
SlnMergeNullLogger.Instance);
474+
var content = mergedSolutionFile.ToFileContent();
475+
Assert.Equal((@"
476+
Microsoft Visual Studio Solution File, Format Version 12.00
477+
# Visual Studio 16
478+
Project(""{2150E333-8FDC-42A3-9474-1A3956D46DE8}"") = ""Project Settings"", ""Project Settings"", ""{34006C71-946B-49BF-BBCB-BB091E5A3AE7}""
479+
ProjectSection(SolutionItems) = preProject
480+
..\Nantoka.Server\.gitignore = ..\Nantoka.Server\.gitignore
481+
EndProjectSection
482+
EndProject
483+
Global
484+
EndGlobal
485+
").Trim(), content.Trim());
486+
}
487+
446488
[Fact]
447489
public void TestMerge()
448490
{

0 commit comments

Comments
 (0)