ThisAssembly icon indicating copy to clipboard operation
ThisAssembly copied to clipboard

ThisAssembly.Git exception when project has Git submodule

Open TibbsTerry opened this issue 1 year ago • 3 comments

Describe the Bug

ThisAssembly.Git produces a build error when solution has Git submodules

ThisAssembly.Git.targets(71,7): error MSB4184: The expression "[System.IO.File]::ReadAllText(/path/;/path/anotherpath/.git/HEAD)" cannot be evaluated. Could not find a part of the path '/path/;/path/anotherpath/.git/HEAD'

Issue is in ThisAssembly.Git.targets line 71 $([System.IO.File]::ReadAllText

<PropertyGroup Condition="'$(RepositoryBranch)' == '' and '$(RepositoryRoot)' != ''">
  <!-- We may not be in CI at all. If we got a git repo root, we can directly read HEAD -->
  <RepositoryHead>$(RepositoryRoot).git/HEAD</RepositoryHead>
  <RepositoryBranch Condition="Exists($(RepositoryHead))">$([System.IO.File]::ReadAllText($(RepositoryHead)).Trim())</RepositoryBranch>
  <RepositoryBranch Condition="$(RepositoryBranch) != ''">$(RepositoryBranch.TrimStart("ref:").Trim().TrimStart("refs").Trim("/").TrimStart("heads").Trim("/").Trim())</RepositoryBranch>
</PropertyGroup>

I believe because @(SourceRoot) will also return submodule information

TibbsTerry avatar May 22 '24 01:05 TibbsTerry

Hm. I wonder how come Exists($(RepositoryHead)) would return true and then File.ReadAllText fail? 🤔

kzu avatar May 30 '24 03:05 kzu

Fix in ThisAssembly.Git.targets

<ItemGroup>
  <_ThisAssemblyGitSourceRoot Include="@(SourceRoot -> WithMetadataValue('SourceControl', 'git'))" 
                              Exclude="@(SourceRoot -> HasMetadata('NestedRoot'))" />
</ItemGroup>

TibbsTerry avatar Jun 06 '24 04:06 TibbsTerry

Also think the build failure may be just a Linux issue. Anyway needs the change above, so that the Branch constant is set.

TibbsTerry avatar Jun 06 '24 04:06 TibbsTerry

I believe this is fixed by your PR #334

kzu avatar Jul 08 '24 06:07 kzu

BTW, just shipped it as 1.5.0-beta.

kzu avatar Jul 08 '24 06:07 kzu