Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ThisAssembly.Git exception when project has Git submodule #303

Closed
TibbsTerry opened this issue May 22, 2024 · 5 comments
Closed

ThisAssembly.Git exception when project has Git submodule #303

TibbsTerry opened this issue May 22, 2024 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@TibbsTerry
Copy link

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 TibbsTerry added the bug Something isn't working label May 22, 2024
@kzu kzu added help wanted Extra attention is needed good first issue Good for newcomers labels May 30, 2024
@kzu
Copy link
Member

kzu commented May 30, 2024

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

@TibbsTerry
Copy link
Author

Fix in
ThisAssembly.Git.targets

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

@TibbsTerry
Copy link
Author

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

@kzu
Copy link
Member

kzu commented Jul 8, 2024

I believe this is fixed by your PR #334

@kzu kzu closed this as completed Jul 8, 2024
@kzu
Copy link
Member

kzu commented Jul 8, 2024

BTW, just shipped it as 1.5.0-beta.

@devlooped devlooped locked and limited conversation to collaborators Sep 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants