From 28765d901e4422818f522831c2a4c19496bad37a Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Mon, 27 May 2019 17:11:32 +0200 Subject: [PATCH] fix UseSourceLink bug --- src/coverlet.core/Coverage.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/coverlet.core/Coverage.cs b/src/coverlet.core/Coverage.cs index 663550e..562cbb8 100644 --- a/src/coverlet.core/Coverage.cs +++ b/src/coverlet.core/Coverage.cs @@ -339,10 +339,18 @@ namespace Coverlet.Core string key = sourceLinkDocument.Key; if (Path.GetFileName(key) != "*") continue; - if (!Path.GetDirectoryName(document).StartsWith(Path.GetDirectoryName(key) + Path.DirectorySeparatorChar)) - continue; + string directoryDocument = Path.GetDirectoryName(document); + string sourceLinkRoot = Path.GetDirectoryName(key); + string relativePath = ""; - var relativePath = Path.GetDirectoryName(document).Substring(Path.GetDirectoryName(key).Length + 1); + // if document is on repo root we skip relative path calculation + if (directoryDocument != sourceLinkRoot) + { + if (!directoryDocument.StartsWith(sourceLinkRoot + Path.DirectorySeparatorChar)) + continue; + + relativePath = directoryDocument.Substring(sourceLinkRoot.Length + 1); + } if (relativePathOfBestMatch.Length == 0) {