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

[Improvement] Add HEAD support #3233

Closed
simonetognolo opened this issue Oct 17, 2022 · 5 comments · Fixed by #3338
Closed

[Improvement] Add HEAD support #3233

simonetognolo opened this issue Oct 17, 2022 · 5 comments · Fixed by #3338
Milestone

Comments

@simonetognolo
Copy link

Actually this project doesn't support to get version from HEAD commit. GetVersionTask v5.3.7 supports it, and I'm stuck with it because I've submodules in my project.

Detailed Description

  • Add an option to allow detached branches (default is false);
  • Handle the initial check EnsureHeadIsNotDetached according to previous option;
  • Get the closest tag to current commit (according to previous option).

Context

  • It'll be possible to get version from HEAD commit;
  • Compile of git project at HEAD commit wouldn't end with error;
  • Actual Gitversion already supports subversion;
  • Fix when a commit is detached but has a tag (actually doesn't work because EnsureHeadIsNotDetached check prevent to look for commit info).

Possible Implementation

In RepositoryStore.GetCurrentCommitSemanticVersions you can check if current commit is tagged, or get the closest tag to the current commit.

RepositoryStore.cs

private IEnumerable<SemanticVersion> GetCurrentCommitSemanticVersions(ICommit? commit, string? tagPrefix, ITag tag, bool getClosestTag = false)
{
    var targetCommit = tag.PeeledTargetCommit();
    if (targetCommit == null)
        return Array.Empty<SemanticVersion>();

    var commitToCompare = getClosestTag ? FindMergeBase(commit, targetCommit) : commit;

    var tagName = tag.Name.Friendly;

    return Equals(targetCommit, commitToCompare) && SemanticVersion.TryParse(tagName, tagPrefix, out var version)
        ? new[] { version }
        : Array.Empty<SemanticVersion>();
}
@asbjornu
Copy link
Member

Can you please submit a PR with this change so we can get a grasp of whether it's breaking any tests, and if so, how many?

@simonetognolo
Copy link
Author

Can you please submit a PR with this change so we can get a grasp of whether it's breaking any tests, and if so, how many?

I've created the branch locally, but I've no rights to push & create pull request.

@gep13
Copy link
Member

gep13 commented Oct 17, 2022

@simonetognolo said...
I've created the branch locally, but I've no rights to push & create pull request.

Have you created a fork of the repository on GitHub? If not, do that, and push your branch to your fork. Once that is done, you should be able to create a Pull Request.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request

@asbjornu
Copy link
Member

asbjornu commented Jan 20, 2023

Resolved by #3338.

@arturcic arturcic modified the milestones: 5.x, 5.12.0 Jan 20, 2023
@arturcic
Copy link
Member

🎉 This issue has been resolved in version 5.12.0 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants