GitVersion: GitVersionTask fails when building from a tag

Describe the bug I’m using GitHub actions to create a new build of a project that is using GitVersionTask.

When the build runs on a branch, everything works fine. When it runs for a tag, the following error is outputted.

/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(46,9): warning : 2020-05-31 05:47:23                WARN [05/31/20 5:47:23:62] Failed to inherit 
Increment branch configuration, no branches found. [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(46,9): warning : Falling back to master branch config [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(46,9): warning :  [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(46,9): warning : It looks like the branch being examined is a detached Head pointing to commit '87436ac'. Without a proper branch name GitVersion cannot determine the build version. [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(10,9): warning : 2020-05-31 05:47:24                WARN [05/31/20 5:47:24:60] Failed to inherit 
Increment branch configuration, no branches found. [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(10,9): warning : Falling back to master branch config [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(10,9): warning :  [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(10,9): warning : It looks like the branch being examined is a detached Head pointing to commit '87436ac'. Without a proper branch name GitVersion cannot determine the build version. [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(71,9): warning : 2020-05-31 05:47:24                WARN [05/31/20 5:47:24:68] Failed to inherit 
Increment branch configuration, no branches found. [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(71,9): warning : Falling back to master branch config [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(71,9): warning :  [/src/Core/Core.csproj]
/root/.nuget/packages/gitversiontask/5.3.5/build/GitVersionTask.targets(71,9): warning : It looks like the branch being examined is a detached Head pointing to commit '87436ac'. Without a proper branch name GitVersion cannot determine the build version. [/src/Core/Core.csproj]
/usr/share/dotnet/sdk/2.2.207/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssemblyInfo.targets(161,5): error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion". [/src/Core/Core.csproj]
/usr/share/dotnet/sdk/2.2.207/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssem

GitVersion standalone works fine when checking out the tag.

Expected Behavior

The build completes with the correct version as per the tag

Actual Behavior

GitVersionTask fails with the above error

Steps to Reproduce

Run a build of a .NET Core 2.2 project in Docker using GitVersionTask 3.3.5

Context

Unable to complete build

Your Environment

GitVersionTask 5.3.5 Build running in a Docker container using mcr.microsoft.com/dotnet/core/sdk:2.2

GitVersion.yml

assembly-versioning-scheme: MajorMinorPatchTag
assembly-file-versioning-scheme: MajorMinorPatchTag
mode: ContinuousDeployment
continuous-delivery-fallback-tag: ""
branches:
  master:
    mode: ContinuousDeployment
    tag: "ci"
    increment: Minor
    track-merge-target: true
    tracks-release-branches: true
    is-release-branch: false
    prevent-increment-of-merged-branch-version: false
  release:
    regex: release?[/]
    mode: ContinuousDeployment
    increment: Patch
    is-release-branch: true
    prevent-increment-of-merged-branch-version: true
ignore:
  sha: []

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 4
  • Comments: 30 (16 by maintainers)

Most upvoted comments

In my case I can reproduce the error like this:

git init
git flow init
git commit --allow-empty -m"Init"
git flow feature start myfeature
git commit --allow-empty -m"Work"
git flow feature finish
git flow release start 1.0.0
git flow release finish
git checkout 1.0.0

Now run GitVersion and it will fail:

INFO [06/08/20 10:40:27:46] Working directory: C:\Temp\test
INFO [06/08/20 10:40:27:49] Project root is: C:\Temp\test\
INFO [06/08/20 10:40:27:49] DotGit directory is: C:\Temp\test\.git
INFO [06/08/20 10:40:27:54] Begin: Loading version variables from disk cache
  INFO [06/08/20 10:40:27:55] Cache file C:\Temp\test\.git\gitversion_cache\F4C9ACACE1A2F5D09D4F04936A7E810AD30EF888.yml not found.
  INFO [06/08/20 10:40:27:55] End: Loading version variables from disk cache (Took: 4.03ms)
  INFO [06/08/20 10:40:27:56] Using latest commit on specified branch
  INFO [06/08/20 10:40:27:56] Begin: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'.
    INFO [06/08/20 10:40:27:56] Trying to find direct branches.
    INFO [06/08/20 10:40:27:57] No direct branches found, searching through all branches.
    INFO [06/08/20 10:40:27:57] Searching for commits reachable from 'develop'.
    INFO [06/08/20 10:40:27:58] The branch 'develop' has a matching commit.
    INFO [06/08/20 10:40:27:58] Searching for commits reachable from 'master'.
    INFO [06/08/20 10:40:27:58] The branch 'master' has a matching commit.
  INFO [06/08/20 10:40:27:58] End: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'. (Took: 19.00ms)
  INFO [06/08/20 10:40:27:61] No branch configuration found for branch (no branch), falling back to default configuration
  INFO [06/08/20 10:40:27:61] Begin: Attempting to inherit branch configuration from parent branch
    INFO [06/08/20 10:40:27:62] HEAD is merge commit, this is likely a pull request using (no branch) as base
    INFO [06/08/20 10:40:27:62] Begin: Finding branch source of '(no branch)'
      INFO [06/08/20 10:40:27:64] Begin: Finding merge base between '(no branch)' and 'develop'.
        INFO [06/08/20 10:40:27:64] Found merge base of 0141c75914bf9258d64e669a532c4a81d05bcdc1
        INFO [06/08/20 10:40:27:64] Merge base of (no branch)' and 'develop is 0141c75914bf9258d64e669a532c4a81d05bcdc1
      INFO [06/08/20 10:40:27:64] End: Finding merge base between '(no branch)' and 'develop'. (Took: 5.34ms)
      INFO [06/08/20 10:40:27:64] Begin: Finding merge base between '(no branch)' and 'master'.
        INFO [06/08/20 10:40:27:64] Found merge base of 6c580b40d103bca22229210400f9ab7922a0bbf2
        INFO [06/08/20 10:40:27:64] Merge base of (no branch)' and 'master is 6c580b40d103bca22229210400f9ab7922a0bbf2
      INFO [06/08/20 10:40:27:64] End: Finding merge base between '(no branch)' and 'master'. (Took: 0.39ms)
      INFO [06/08/20 10:40:27:65] Multiple source branches have been found, picking the first one (master).
This may result in incorrect commit counting.
Options were:
master, develop
    INFO [06/08/20 10:40:27:65] End: Finding branch source of '(no branch)' (Took: 24.80ms)
    INFO [06/08/20 10:40:27:65] Begin: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'.
      INFO [06/08/20 10:40:27:65] Trying to find direct branches.
      INFO [06/08/20 10:40:27:65] No direct branches found, searching through all branches.
      INFO [06/08/20 10:40:27:65] Searching for commits reachable from 'develop'.
      INFO [06/08/20 10:40:27:65] The branch 'develop' has a matching commit.
      INFO [06/08/20 10:40:27:65] Searching for commits reachable from 'master'.
      INFO [06/08/20 10:40:27:65] The branch 'master' has a matching commit.
    INFO [06/08/20 10:40:27:65] End: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'. (Took: 0.96ms)
    INFO [06/08/20 10:40:27:65] Begin: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'.
      INFO [06/08/20 10:40:27:65] Trying to find direct branches.
      INFO [06/08/20 10:40:27:65] No direct branches found, searching through all branches.
      INFO [06/08/20 10:40:27:65] Searching for commits reachable from 'develop'.
      INFO [06/08/20 10:40:27:65] The branch 'develop' has a matching commit.
      INFO [06/08/20 10:40:27:65] Searching for commits reachable from 'master'.
      INFO [06/08/20 10:40:27:65] The branch 'master' has a matching commit.
    INFO [06/08/20 10:40:27:65] End: Getting branches containing the commit '6c580b40d103bca22229210400f9ab7922a0bbf2'. (Took: 0.85ms)
    INFO [06/08/20 10:40:27:65] Found possible parent branches:
    WARN [06/08/20 10:40:27:66] Failed to inherit Increment branch configuration, no branches found.
Falling back to develop branch config
  INFO [06/08/20 10:40:27:66] End: Attempting to inherit branch configuration from parent branch (Took: 43.57ms)
  INFO [06/08/20 10:40:27:69] Running against branch: (no branch) (6c580b40d103bca22229210400f9ab7922a0bbf2)
  INFO [06/08/20 10:40:27:69] Current commit is tagged with version 1.0.0, version calculation is for metadata only.
  WARN [06/08/20 10:40:27:69] An error occurred:
It looks like the branch being examined is a detached Head pointing to commit '6c580b4'. Without a proper branch name GitVersion cannot determine the build version.
```

I’m facing the same issue as @jogivanknobi. The smallest steps to reproduce I could find are:

git init
git commit --allow-empty -m "init"
git branch task1
git tag v0.2
git checkout v0.2
gitversion

Tested on 3.0.0, 3.6.2, 4.0.0, 5.0.1 and 5.3.7. They all result in an error. (Showing output of 5.3.7 here)

C:\workspace\tagtest [(v0.2)]> git init
Initialized empty Git repository in C:/workspace/tagtest/.git/
C:\workspace\tagtest [master]> git commit --allow-empty -m "init"
[master (root-commit) 142e169] init
C:\workspace\tagtest [master]> git branch task1
C:\workspace\tagtest [master]> git tag v0.2
C:\workspace\tagtest [master]> git checkout v0.2
Note: switching to 'v0.2'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 142e169 init
C:\workspace\tagtest [(v0.2)]> gitversion
INFO [08/29/20 20:43:55:18] Working directory: C:\workspace\tagtest
INFO [08/29/20 20:43:55:22] Project root is: C:\workspace\tagtest\
INFO [08/29/20 20:43:55:22] DotGit directory is: C:\workspace\tagtest\.git
INFO [08/29/20 20:43:55:27] Begin: Loading version variables from disk cache
  INFO [08/29/20 20:43:55:27] Cache file C:\workspace\tagtest\.git\gitversion_cache\9A6A402CE9558B93FE90AFA89EE17F87033490AD.yml not found.
  INFO [08/29/20 20:43:55:27] End: Loading version variables from disk cache (Took: 1.97ms)
  INFO [08/29/20 20:43:55:28] Using latest commit on specified branch
  INFO [08/29/20 20:43:55:29] Begin: Getting branches containing the commit '142e169bc8d7d8260e954ae16f4614daf71960ca'.
    INFO [08/29/20 20:43:55:29] Trying to find direct branches.
    INFO [08/29/20 20:43:55:29] No direct branches found, searching through all branches.
    INFO [08/29/20 20:43:55:29] Searching for commits reachable from 'master'.
    INFO [08/29/20 20:43:55:29] The branch 'master' has a matching commit.
    INFO [08/29/20 20:43:55:29] Searching for commits reachable from 'task1'.
    INFO [08/29/20 20:43:55:29] The branch 'task1' has a matching commit.
  INFO [08/29/20 20:43:55:30] End: Getting branches containing the commit '142e169bc8d7d8260e954ae16f4614daf71960ca'. (Took: 7.34ms)
  INFO [08/29/20 20:43:55:31] No branch configuration found for branch (no branch), falling back to default configuration
  INFO [08/29/20 20:43:55:32] Begin: Attempting to inherit branch configuration from parent branch
    INFO [08/29/20 20:43:55:33] Begin: Finding branch source of '(no branch)'
      INFO [08/29/20 20:43:55:33] Begin: Finding merge base between '(no branch)' and 'master'.
        INFO [08/29/20 20:43:55:34] Found merge base of 142e169bc8d7d8260e954ae16f4614daf71960ca
        INFO [08/29/20 20:43:55:34] Merge base of (no branch)' and 'master is 142e169bc8d7d8260e954ae16f4614daf71960ca
      INFO [08/29/20 20:43:55:34] End: Finding merge base between '(no branch)' and 'master'. (Took: 4.60ms)
    INFO [08/29/20 20:43:55:34] End: Finding branch source of '(no branch)' (Took: 17.37ms)
    INFO [08/29/20 20:43:55:34] Begin: Getting branches containing the commit '142e169bc8d7d8260e954ae16f4614daf71960ca'.
      INFO [08/29/20 20:43:55:34] Trying to find direct branches.
      INFO [08/29/20 20:43:55:34] No direct branches found, searching through all branches.
      INFO [08/29/20 20:43:55:34] Searching for commits reachable from 'master'.
      INFO [08/29/20 20:43:55:34] The branch 'master' has a matching commit.
    INFO [08/29/20 20:43:55:34] End: Getting branches containing the commit '142e169bc8d7d8260e954ae16f4614daf71960ca'. (Took: 0.56ms)
    INFO [08/29/20 20:43:55:34] Found possible parent branches: master
  INFO [08/29/20 20:43:55:34] End: Attempting to inherit branch configuration from parent branch (Took: 26.12ms)
  INFO [08/29/20 20:43:55:37] Running against branch: (no branch) (142e169bc8d7d8260e954ae16f4614daf71960ca)
  INFO [08/29/20 20:43:55:37] Current commit is tagged with version 0.2.0, version calculation is for metadata only.
  WARN [08/29/20 20:43:55:37] An error occurred:
It looks like the branch being examined is a detached Head pointing to commit '142e169'. Without a proper branch name GitVersion cannot determine the build version.

Note that I’m not using an upstream repo, nor a CI server. When you leave the git branch task1 out, it works fine.

After setting the Git_Branch environment variable to (fake) value %teamcity.build.vcs.branch.1%, I’m getting the same error. Let me know if you want me to log this as a separate issue.

I was using the GitVersion GitHub action and doing a git fetch --prune --unshallow as per the GitVersion GitHub actions step documentation.

Running the standalone .exe locally also worked fine on the tag.

To fix the issue, I have since changed the checkout step to the following:

- uses: actions/checkout@v2
  with:
    fetch-depth: 0