Skip to content

[Improvement] Add HEAD support #3233

@simonetognolo

Description

@simonetognolo

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>();
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions