From 8620b39090ecef207a7780f89f16bec0b3b66826 Mon Sep 17 00:00:00 2001 From: Daniel Cazzulino Date: Tue, 18 Feb 2025 04:39:56 -0300 Subject: [PATCH] Improve detection of git root by leveraging SourceLink The built-in .NET SDKs incorporate source control information already. If we find that, we don't really need to read from the file system the HEAD branch. --- src/ThisAssembly.Git/ThisAssembly.Git.targets | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/ThisAssembly.Git/ThisAssembly.Git.targets b/src/ThisAssembly.Git/ThisAssembly.Git.targets index 31d5b3cc..588c1549 100644 --- a/src/ThisAssembly.Git/ThisAssembly.Git.targets +++ b/src/ThisAssembly.Git/ThisAssembly.Git.targets @@ -45,6 +45,7 @@ @@ -71,10 +72,12 @@ - - $(RepositoryRoot).git/HEAD - $([System.IO.File]::ReadAllText($(RepositoryHead)).Trim()) - $(RepositoryBranch.TrimStart("ref:").Trim().TrimStart("refs").Trim("/").TrimStart("heads").Trim("/").Trim()) + + <_ThisAssemblyGitBranchName>@(_ThisAssemblyGitSourceRoot -> '%(BranchName)') + + + <_ThisAssemblyGitBranchName Condition="'$(_ThisAssemblyGitBranchName)' == ''">$([System.IO.File]::ReadAllText('$(RepositoryRoot).git/HEAD').Trim()) + $(_ThisAssemblyGitBranchName.TrimStart("ref:").Trim().Replace('refs/heads/', '').Replace('refs/tags/', ''))