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

GitVersionTask fails when building from a tag #2301

Closed
TrentScholl opened this issue May 31, 2020 · 30 comments · Fixed by #2411 or #3033
Closed

GitVersionTask fails when building from a tag #2301

TrentScholl opened this issue May 31, 2020 · 30 comments · Fixed by #2411 or #3033
Labels
Milestone

Comments

@TrentScholl
Copy link

TrentScholl commented May 31, 2020

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: []
@asbjornu
Copy link
Member

asbjornu commented Jun 2, 2020

GitVersion standalone works fine when checking out the tag.

How are you running GitVersion standalone? Locally or as a step within the same GitHub Actions? Are you doing git fetch --prune --unshallow as per the documentation?

In any case, it may be that you have stumbled upon the bug #2074. We don't have a fix for it yet, but any new eyes on the problem is appreciated.

@jogivanknobi
Copy link

I'm having the same problem.
Up to v5.1.3 everything worked fine, any subsequent version produces the same error when the repository is in detached head state.

@TrentScholl
Copy link
Author

TrentScholl commented Jun 8, 2020

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

@jogivanknobi
Copy link

jogivanknobi commented Jun 8, 2020

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.
```

@asbjornu
Copy link
Member

asbjornu commented Jun 8, 2020

@TrentScholl, that's interesting. It would be great if other people experiencing the same problem could try the same fix and report back whether it helps or not.

@asbjornu
Copy link
Member

asbjornu commented Jun 8, 2020

@jogivanknobi, thanks for providing a reproduction! That should make this issue much easier to identify and fix.

Can you please also verify that GitVersion < version 5.1.3 works with your reproduction repository? What's the log output from GitVersion i.e. version 5.1.2 from the same repository?

@jogivanknobi
Copy link

Interesting, I know I could fix the problem in Azure Pipelines by switching back to 5.1.3,
any later version failed. But this reproduction somehow seems to make it fail always.
I tested any version down to 4.0.0, none worked.

@asbjornu
Copy link
Member

asbjornu commented Jun 9, 2020

@jogivanknobi, then I suspect the reproduction just leads to the same problem, but from another code-path that has never and perhaps is even supposed to never work. Also, it seems like the Git_Branch environment variable seems to be missing from both your build and @TrentScholl's. What happens if you add it?

@jogivanknobi
Copy link

@asbjornu, I wasn't aware of this environment variable. Is there any documentation about it?
But whether I set it to develop or master, it doesn't change anything, the logs are exactly the same.

@asbjornu
Copy link
Member

Git_Branch is mentioned in the documentation on TeamCity and should be set dynamically to the branch being built.

@TrentScholl
Copy link
Author

TrentScholl commented Jun 25, 2020

Turns out my fix was unrelated.

This is my workflow:

  • Commit to master - build 1.1.0.ci.99
  • Create release branch (release/v1.1) - build 1.1.0-beta.0
  • Tag head commit on release/v1.1 with v1.1.0 - build fails

At this point, the commit hash on master and release/v1.1 are the same and checking out the tag results in a detached head.

❯ git branch -a --contains  v1.1.0
* (HEAD detached at v1.1.0)
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/master
  remotes/origin/release/v1.1

If I make a commit to release/v1.1, build 1.1.0-beta.1 is created. If I delete my v1.1.0 tag and then retag the new head commit of release/v1.1, the build works and creates build 1.1.0 fine.

In every situation, GitVersion stand-alone works fine and creates the correct SemVer. The issue only occurs with GitVersionTask.

@gerwinjansen
Copy link
Contributor

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.

@gerwinjansen
Copy link
Contributor

@asbjornu: can you reply to my above comment?

@asbjornu
Copy link
Member

@gerwinjansen, thanks for the provided information. Are you able to reproduce the problem in a RepositoryFixture test as well? If not, we should look into creating a test case repository from your reproduction so it can be used for debugging this issue.

@gerwinjansen
Copy link
Contributor

gerwinjansen commented Sep 25, 2020

@asbjornu: here is the failing testcase (remove the BranchTo to make it pass)

[TestFixture]
public class TagCheckoutScenarios
{
    [Test]
    public void GivenARepositoryWithSingleCommitAndSingleBranch()
    {
        using var fixture = new EmptyRepositoryFixture();
        const string taggedVersion = "1.0.3";
        fixture.Repository.MakeATaggedCommit(taggedVersion);
        fixture.BranchTo("task1");
        fixture.Checkout(taggedVersion);

        fixture.AssertFullSemver(taggedVersion);
    }
}

The result is:

GitVersionCore.Tests.IntegrationTests.TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranch

GitVersion.WarningException : It looks like the branch being examined is a detached Head pointing to commit '59e6bf4'. Without a proper branch name Gi...

GitVersion.WarningException : It looks like the branch being examined is a detached Head pointing to commit '59e6bf4'. Without a proper branch name GitVersion cannot determine the build version.
   at GitVersion.VersionCalculation.NextVersionCalculator.EnsureHeadIsNotDetached(GitVersionContext context) in C:\workspace\GitVersion\src\GitVersionCore\VersionCalculation\NextVersionCalculator.cs:line 138
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion() in C:\workspace\GitVersion\src\GitVersionCore\VersionCalculation\NextVersionCalculator.cs:line 38
   at GitVersionCore.Tests.GitToolsTestingExtensions.GetVersion(RepositoryFixtureBase fixture, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String branch) in C:\workspace\GitVersion\src\GitVersionCore.Tests\Extensions\GitToolsTestingExtensions.cs:line 55
   at GitVersionCore.Tests.GitToolsTestingExtensions.AssertFullSemver(RepositoryFixtureBase fixture, String fullSemver, Config configuration, IRepository repository, String commitId, Boolean onlyTrackedBranches, String targetBranch) in C:\workspace\GitVersion\src\GitVersionCore.Tests\Extensions\GitToolsTestingExtensions.cs:line 76
   at GitVersionCore.Tests.IntegrationTests.TagCheckoutScenarios.GivenARepositoryWithSingleCommitAndSingleBranch() in C:\workspace\GitVersion\src\GitVersionCore.Tests\IntegrationTests\TagCheckoutScenarios.cs:line 29



Created git repository at 'C:\Users\XXXXXXXX\AppData\Local\Temp\TestRepositories\c2cda1a9-980c-4697-a34c-5fd92aea56d5'
---------
Test failing, dumping repository graph
* 59e6bf4 58 minutes ago  (HEAD, tag: 1.0.3, task1, master)
* 59e6bf4 58 minutes ago  (HEAD, tag: 1.0.3, task1, master)

@asbjornu
Copy link
Member

Yeah, in the case of a missing branch, GitVersion doesn't know what to increment. But with the presence of a tag it shouldn't have to increment anything, so I think it should default to just using the tag in this case. A PR changing this behaviour is welcome.

@arturcic
Copy link
Member

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

Your GitReleaseManager bot 📦🚀

@fedebn
Copy link

fedebn commented Oct 27, 2020

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

Your GitReleaseManager bot 📦🚀

I have try to build a tag right now with the new version 5.5:
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion".

@asbjornu
Copy link
Member

That's interesting, @fedebn. Thanks for reporting. Are you able to reproduce the problem in a test and submit it as a pull request?

@fedebn
Copy link

fedebn commented Oct 28, 2020

That's interesting, @fedebn. Thanks for reporting. Are you able to reproduce the problem in a test and submit it as a pull request?
I'm sorry, but i'm not on focus on this type of unit test, but I can write what i have do:

  1. Create a repository on my bitbucket server
  2. Check out it on my pc
  3. Create a Vs solution (.net 4.5 VS2017)
  4. Install git version task 5.5.0
  5. Commit and Push all
  6. Create a tag "1.0.0"
  7. From git console "git checkout 1.0.0"
  8. Build the solution from VS 2017

@fedebn
Copy link

fedebn commented Oct 28, 2020

I have created another repository and everithing work fine. Strage.

@asbjornu
Copy link
Member

Given your description, I would think the following tests should cover it, @fedebn:

[Test]
public void GivenARepositoryWithSingleCommit()
{
using var fixture = new EmptyRepositoryFixture();
const string taggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
fixture.Checkout(taggedVersion);
fixture.AssertFullSemver(taggedVersion);
}

[Test]
public void GivenARepositoryWithSingleCommitAndSingleBranch()
{
using var fixture = new EmptyRepositoryFixture();
const string taggedVersion = "1.0.3";
fixture.Repository.MakeATaggedCommit(taggedVersion);
fixture.BranchTo("task1");
fixture.Checkout(taggedVersion);
fixture.AssertFullSemver(taggedVersion);
}

So something else seems to be going on here. Without a test that reproduces the issue, it is going to be really hard to fix.

@asbjornu asbjornu reopened this Oct 28, 2020
@asbjornu
Copy link
Member

Some digging makes me think that it must be RepositoryMetadataProvider.GetCurrentCommitTaggedVersion() that returns null;

public SemanticVersion GetCurrentCommitTaggedVersion(GitObject commit, EffectiveConfiguration config)
{
return repository.Tags
.SelectMany(t =>
{
if (t.PeeledTarget() == commit && SemanticVersion.TryParse(t.FriendlyName, config.GitTagPrefix, out var version))
return new[] {
version
};
return new SemanticVersion[0];
})
.Max();
}

…leading to GitVersionContext.IsCurrentCommitTagged returning false;

public bool IsCurrentCommitTagged => CurrentCommitTaggedVersion != null;

…making the check for a tagged commit in NextVersionCalculator.FindVersion() fail, performing EnsureHeadIsNotDetached() instead:

if (context.IsCurrentCommitTagged)
{
log.Info($"Current commit is tagged with version {context.CurrentCommitTaggedVersion}, " +
"version calculation is for metadata only.");
}
else
{
EnsureHeadIsNotDetached(context);
}

I don't have an idea why RepositoryMetadataProvider.GetCurrentCommitTaggedVersion() may be returning null, but if we got a test that reproduced this error, changing the logic of GetCurrentCommitTaggedVersion() would probably fix the problem.

@dagophil
Copy link

dagophil commented Nov 23, 2020

@asbjornu I think I found tests that reproduce the issue.

This test passes:

[Test]
public void GivenARepositoryWithNonVersionTagAndNoFollowingCommits()
{
    using var fixture = new EmptyRepositoryFixture();
    fixture.MakeACommit("init");
    fixture.MakeATaggedCommit("0.2.0");
    fixture.MakeATaggedCommit("foo-tag");
    fixture.Checkout("foo-tag");

    fixture.AssertFullSemver("0.2.1+1");
}

This test fails with GitVersion.WarningException : It looks like the branch being examined is a detached Head pointing to commit 'c1d35d0'. Without a proper branch name GitVersion cannot determine the build version.:

[Test]
public void GivenARepositoryWithNonVersionTagAndOneFollowingCommit()
{
    using var fixture = new EmptyRepositoryFixture();
    fixture.MakeACommit("init");
    fixture.MakeATaggedCommit("0.2.0");
    fixture.MakeATaggedCommit("foo-tag");
    fixture.MakeACommit("new feature");
    fixture.Checkout("foo-tag");

    fixture.AssertFullSemver("0.2.1+1");
}

This means that GitVersion fails on checkout of a non-version tag if there is a subsequent commit.

The same error occurs if you create a branch instead of a commit. This test fails with the same message:

[Test]
public void GivenARepositoryWithNonVersionTagAndBranch()
{
    using var fixture = new EmptyRepositoryFixture();
    fixture.MakeACommit("init");
    fixture.MakeATaggedCommit("0.2.0");
    fixture.MakeATaggedCommit("foo-tag");
    fixture.BranchTo("develop");
    fixture.Checkout("foo-tag");

    fixture.AssertFullSemver("0.2.1+1");
}

The checkout of non-version related tags might seem like a rare use case. However, the situation occurs frequently if you have a mono-repo with per-folder GitVersion configuration with different tag prefixes.

@asbjornu
Copy link
Member

I agree non-version tags should not cause GitVersion to fail, @dagophil. But from @fedebn's description in #2301 (comment), version tags seem to still cause problems as well. While the tests you provide shouldn't fail, we also need a way to reproduce the version tag problem that still seems to be existent too.

@dagophil
Copy link

@asbjornu Okay I missed that this is about version tags only.

@sergey-chanaev
Copy link

sergey-chanaev commented Nov 27, 2020

Got same issue as @fedebn on Azure DevOps:

Steps to reproduce on Azure:

  1. All branches have no issues during build before tag 1.0.0 was introduced
  2. master branch has now tag 1.0.0 and has no issues during build.
  3. Create branch hotfix/1.0.1 (using git flow)
  4. Execute pipeline against this branch on Azure DevOps
    5.1 If you will try to build app using global dotnet tool installed before - it works fine.
    5.2 If you will try to build app using GitVersionTask nuget package only will fail:
/root/.nuget/packages/gitversiontask/5.5.1/build/GitVersionTask.targets(46,9): warning : It looks like the branch being examined is a detached Head pointing to commit 'e3d0707'. Without a proper branch name GitVersion cannot determine the build version. [/src/XXXXX.csproj]
/root/.nuget/packages/gitversiontask/5.5.1/build/GitVersionTask.targets(10,9): warning : It looks like the branch being examined is a detached Head pointing to commit 'e3d0707'. Without a proper branch name GitVersion cannot determine the build version. [/src/XXXXX.csproj]
/root/.nuget/packages/gitversiontask/5.5.1/build/GitVersionTask.targets(71,9): warning : It looks like the branch being examined is a detached Head pointing to commit 'e3d0707'. Without a proper branch name GitVersion cannot determine the build version. [/src/XXXXX.csproj]
/usr/share/dotnet/sdk/3.1.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.GenerateAssemblyInfo.targets(163,5): error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion". [/src/XXXXX.csproj]

I have try to build a tag right now with the new version 5.5:
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
warning : It looks like the branch being examined is a detached Head pointing to commit '8d94865'. Without a proper branch name GitVersion cannot determine the build version.
error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion".

@ismaelhamed
Copy link

GitVersion 5.8.1
We're having problems too but, AFAICT, only for tags in support/ braches, both in TFS and locally via command-line.

For some it picks the wrong source branch:

> git checkout v3.5.5
HEAD is now at 30cd0a099 Merge branch 'hotfix/...' into support/3.5
> GitVersion /diag

{
  "Major": 3,
  "Minor": 14,
  "Patch": 0,
  ...
}

INFO [02/03/22 9:34:42:56] Multiple source branches have been found, picking the first one (develop).
This may result in incorrect commit counting.
Options were:
develop, master, release/3.13.0, support/3.11, support/3.10, support/3.6, support/3.5, support/3.4, support/3.3

In others it just throws:

> git checkout v3.12.70
HEAD is now at f6805e808 Merge branch 'hotfix/...' into support/3.12
> GitVersion /diag

System.InvalidOperationException: Gitversion could not determine which branch to treat as the development branch (default is 'develop') nor releaseable branch (default is 'main' or 'master'), either locally or remotely. Ensure the local clone and checkout match the requirements or considering using 'GitVersion Dynamic Repositories'
   at GitVersion.Configuration.BranchConfigurationCalculator.InheritBranchConfiguration(IBranch targetBranch, BranchConfig branchConfiguration, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 134
   at GitVersion.Configuration.BranchConfigurationCalculator.GetBranchConfiguration(IBranch targetBranch, ICommit currentCommit, Config configuration, IList`1 excludedInheritBranches) in D:\a\GitVersion\GitVersion\src\GitVersion.Core\Configuration\BranchConfigurationCalculator.cs:line 44
...
INFO [02/03/22 8:35:24:14] Attempting to show the current git graph (please include in issue):
INFO [02/03/22 8:35:24:14] Showing max of 100 commits
INFO [02/03/22 8:35:24:36] *   f6805e808 16 hours ago  (HEAD, tag: v3.12.70, support/3.12, origin/support/3.12)

@asbjornu
Copy link
Member

@ismaelhamed, the latter error is probably due to the local repository not being complete (i.e. develop is missing). Which mode are you using? The former error would be interesting to see reproduced in a test. Are you able to submit one in a PR?

@ismaelhamed
Copy link

ismaelhamed commented Mar 2, 2022

@asbjornu this is the GitVersion.yml we're using in this repo:

mode: ContinuousDelivery
assembly-file-versioning-format: '{MajorMinorPatch}.{CommitsSinceVersionSource}'
assembly-informational-format: '{FullSemVer}.SHA.{ShortSha}'
branches:
  develop:
    tag: develop
  release:
    tag: rc

Not sure how to reproduce it out of this repo. And it's only happening for some support/ branches, not all.

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