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

Git.Branch always gives [HEAD] for detached HEAD commit. #333

Closed
ArkaHnat opened this issue Feb 22, 2024 · 3 comments
Closed

Git.Branch always gives [HEAD] for detached HEAD commit. #333

ArkaHnat opened this issue Feb 22, 2024 · 3 comments
Labels

Comments

@ArkaHnat
Copy link

When I'm trying to use ThisAssembly.Git.Branch on detached head it always returns me [HEAD].
I didn't change any options.
When I run command git name-rev --refs=refs/heads/* --no-undefined --always SHA1 which is a default it gives correct result.
If my branch isn't detached ThisAssembly.Git.Branch also gives me correct result

@ArkaHnat ArkaHnat added the bug label Feb 22, 2024
@kzu
Copy link
Member

kzu commented Apr 4, 2024

And what would constitute "the correct result" for a Branch property where there's no branch checked out? (Unless I misunderstood the question).

@ArkaHnat
Copy link
Author

ArkaHnat commented Apr 4, 2024

@kzu correct result would be in this case the branch to which the commit belongs

@kzu
Copy link
Member

kzu commented Apr 4, 2024

A commit can belong to any number of branches.

The code that currently determines the branch can be seen at GitInfo.targets.

You can run your own target after that to detect your specific scenario with:

<Target Name="MyBranch" AfterTargets="_GitBranch" Condition="$(GitBranch) == '[HEAD]'">
   <Exec ... />
</Target>

Alternatively, consider testing this scenario and providing a PR that updates the git commands we issue to determine the branch.

@kzu kzu closed this as not planned Won't fix, can't repro, duplicate, stale Apr 30, 2024
@devlooped devlooped locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants