Gitversion: Sequence Contains No Matching Elements

Created on 4 May 2019  ·  18Comments  ·  Source: GitTools/GitVersion

I get the following message when running GitVersion against my repo, the repo is currently git, however it has been converted from cvs to svn to hg before git.

INFO [05/04/19 8:49:53:53] Working directory: C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:54] IsDynamicGitRepository: False
INFO [05/04/19 8:49:53:56] Returning Project Root from DotGitDirectory: C:\github\axiom3d\axiom\.git - C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:56] Running on Windows.
INFO [05/04/19 8:49:53:57] IsDynamicGitRepository: False
INFO [05/04/19 8:49:53:57] Returning Project Root from DotGitDirectory: C:\github\axiom3d\axiom\.git - C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:57] Project root is: C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:57] DotGit directory is: C:\github\axiom3d\axiom\.git
INFO [05/04/19 8:49:53:58] IsDynamicGitRepository: False
INFO [05/04/19 8:49:53:58] Returning Project Root from DotGitDirectory: C:\github\axiom3d\axiom\.git - C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:61] Begin: Loading version variables from disk cache
  INFO [05/04/19 8:49:53:61] Cache file C:\github\axiom3d\axiom\.git\gitversion_cache\A4BFA58BA7D9A0DD82E47CA1096478A4938DEE97.yml not found.
INFO [05/04/19 8:49:53:62] End: Loading version variables from disk cache (Took: 1.96ms)
INFO [05/04/19 8:49:53:62] IsDynamicGitRepository: False
INFO [05/04/19 8:49:53:62] Returning Project Root from DotGitDirectory: C:\github\axiom3d\axiom\.git - C:\github\axiom3d\axiom
INFO [05/04/19 8:49:53:73] Using latest commit on specified branch
INFO [05/04/19 8:49:53:74] No branch configuration found for branch v0.8.0.0, falling back to default configuration
INFO [05/04/19 8:49:53:75] Begin: Attempting to inherit branch configuration from parent branch
  INFO [05/04/19 8:49:53:77] Begin: Finding branch source of 'v0.8.0.0'
    INFO [05/04/19 8:49:53:80] Begin: Finding merge base between 'v0.8.0.0' and 'develop'.
      INFO [05/04/19 8:49:53:83] Found merge base of 4bae1c05591012d220d58c03531f5fdf32d9daf5
      INFO [05/04/19 8:49:53:85] Merge base of v0.8.0.0' and 'develop is 4bae1c05591012d220d58c03531f5fdf32d9daf5
    INFO [05/04/19 8:49:53:85] End: Finding merge base between 'v0.8.0.0' and 'develop'. (Took: 47.00ms)
    INFO [05/04/19 8:49:53:85] Begin: Finding merge base between 'v0.8.0.0' and 'master'.
      INFO [05/04/19 8:49:53:86] Merge base of v0.8.0.0' and 'master is
    INFO [05/04/19 8:49:53:86] End: Finding merge base between 'v0.8.0.0' and 'master'. (Took: 14.00ms)
    INFO [05/04/19 8:49:53:86] Begin: Finding merge base between 'v0.8.0.0' and 'origin/develop'.
      INFO [05/04/19 8:49:53:88] Found merge base of 4bae1c05591012d220d58c03531f5fdf32d9daf5
      INFO [05/04/19 8:49:53:91] Merge base of v0.8.0.0' and 'origin/develop is 4bae1c05591012d220d58c03531f5fdf32d9daf5
    INFO [05/04/19 8:49:53:91] End: Finding merge base between 'v0.8.0.0' and 'origin/develop'. (Took: 48.00ms)
    INFO [05/04/19 8:49:53:91] Begin: Finding merge base between 'v0.8.0.0' and 'origin/master'.
      INFO [05/04/19 8:49:53:91] Merge base of v0.8.0.0' and 'origin/master is
    INFO [05/04/19 8:49:53:91] End: Finding merge base between 'v0.8.0.0' and 'origin/master'. (Took: 2.00ms)
    INFO [05/04/19 8:49:53:93] Multiple source branches have been found, picking the first one (develop).
This may result in incorrect commit counting.
Options were:
develop, origin/develop
  INFO [05/04/19 8:49:53:93] End: Finding branch source of 'v0.8.0.0' (Took: 157.00ms)
  INFO [05/04/19 8:49:53:93] Begin: Getting branches containing the commit '4bae1c05591012d220d58c03531f5fdf32d9daf5'.
    INFO [05/04/19 8:49:53:93] Trying to find direct branches.
    INFO [05/04/19 8:49:53:93] No direct branches found, searching through tracked branches.
    INFO [05/04/19 8:49:53:94] Searching for commits reachable from 'origin/develop'.
    INFO [05/04/19 8:49:53:97] The branch 'origin/develop' has a matching commit.
    INFO [05/04/19 8:49:53:97] Searching for commits reachable from 'origin/master'.
    INFO [05/04/19 8:49:53:97] The branch 'origin/master' has no matching commits.
  INFO [05/04/19 8:49:53:97] End: Getting branches containing the commit '4bae1c05591012d220d58c03531f5fdf32d9daf5'. (Took: 39.01ms)
  INFO [05/04/19 8:49:53:97] Found possible parent branches: origin/develop
INFO [05/04/19 8:49:53:97] End: Attempting to inherit branch configuration from parent branch (Took: 227.05ms)
INFO [05/04/19 8:49:53:99] Running against branch: v0.8.0.0 (d916c5fd44d1c1f96b6a3543c70416d2a769d3d7)
INFO [05/04/19 8:49:54:00] Begin: Calculating base versions
  INFO [05/04/19 8:49:54:03] Fallback base version: 0.1.0 with commit count source af4e68e39330a1b65f42035668cff977f6512592 (Incremented: None)
  INFO [05/04/19 8:49:54:10] NextVersion in GitVersion configuration file: 0.9.0 with commit count source External Source (Incremented: None)
  INFO [05/04/19 8:49:54:15] Git tag 'v0.8.3376.12322': 0.8.3376+12322 with commit count source a607690d514416d025ff0b8474ffaeedfb0d4984 (Incremented: 0.9.0)
  INFO [05/04/19 8:49:54:17] Git tag 'v0.8.3101.12095': 0.8.3101+12095 with commit count source 88819d35c5ce02eb23b7082a4bfd0bbccb0226ee (Incremented: 0.9.0)
  INFO [05/04/19 8:49:54:23] Begin: Finding branch source of 'v0.8.0.0'
    INFO [05/04/19 8:49:54:23] Multiple source branches have been found, picking the first one (develop).
This may result in incorrect commit counting.
Options were:
develop, origin/develop
  INFO [05/04/19 8:49:54:23] End: Finding branch source of 'v0.8.0.0' (Took: 0.00ms)
  INFO [05/04/19 8:49:54:23] Version in branch name: 0.8.0+0 with commit count source 4bae1c05591012d220d58c03531f5fdf32d9daf5 (Incremented: None)
  INFO [05/04/19 8:49:54:26] Found multiple base versions which will produce the same SemVer (0.9.0), taking oldest source for commit counting (Git tag 'v0.8.3101.12095')
  INFO [05/04/19 8:49:54:27] Base version used: Git tag 'v0.8.3101.12095': 0.8.3101+12095 with commit count source 88819d35c5ce02eb23b7082a4bfd0bbccb0226ee (Incremented: 0.9.0)
INFO [05/04/19 8:49:54:27] End: Calculating base versions (Took: 272.94ms)
INFO [05/04/19 8:49:54:28] Begin: Using mainline development mode to calculate current version
  INFO [05/04/19 8:49:54:31] Multiple possible mainlines pointing at the same commit, dropping origin/master
  INFO [05/04/19 8:49:54:31] Found possible mainline branches:
INFO [05/04/19 8:49:54:35] End: Using mainline development mode to calculate current version (Took: 69.97ms)
ERROR [05/04/19 8:49:54:36] An unexpected error occurred:
System.InvalidOperationException: Sequence contains no matching element
  at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
  at GitVersion.VersionCalculation.MainlineVersionCalculator.GetMainlineTip(GitVersionContext context)
  at GitVersion.VersionCalculation.MainlineVersionCalculator.FindMainlineModeVersion(BaseVersion baseVersion, GitVersionContext context)
  at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
  at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
  at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
  at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
  at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
  at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
  at GitVersion.Program.VerifyArgumentsAndRun()
INFO [05/04/19 8:49:54:36]
INFO [05/04/19 8:49:54:36] Attempting to show the current git graph (please include in issue):
INFO [05/04/19 8:49:54:36] Showing max of 100 commits
INFO [05/04/19 8:49:54:65] *   1d261cd90 7 days ago  (origin/develop, develop)
|\
| * d44cf7867 7 days ago  (origin/UpgradeToLatest, UpgradeToLatest)
| * 6d38b3503 7 days ago
| * e64d9906b 3 weeks ago
| * e94a5bb17 3 weeks ago
| * 821980450 4 weeks ago
| * c3c3a67b9 4 weeks ago
| * b2ffad98a 4 weeks ago
| * 6bdd21902 4 weeks ago
| * 80750bc34 4 weeks ago
| * aaa27e753 4 weeks ago
| * 37a75f42a 4 weeks ago
| * 2aeb37794 4 weeks ago
| * 4e85c1a40 4 weeks ago
| * 522fd8e3f 4 weeks ago
| * 7fb211136 7 weeks ago
| * 4b245fa5d 7 weeks ago
| * 2c77788bc 7 weeks ago
| * dc131d87d 7 weeks ago
| * 36872f495 7 weeks ago
| * b22b00a19 7 weeks ago
| * 9e69f409f 7 weeks ago
| * 2fbcce393 7 weeks ago
| * 127c75194 7 weeks ago
| * 39c78e35a 7 weeks ago
| * 163b0636a 7 weeks ago
| * 58711c1c9 7 weeks ago
| * e06277197 7 weeks ago
| * f520bc97d 7 weeks ago
| * 221c6b574 7 weeks ago
| * 2834dde16 7 weeks ago
| * 0ae0aff6f 7 weeks ago
| * b85842a4f 7 weeks ago
| * a634b45e0 7 weeks ago
| * 9b548a08d 7 weeks ago
| * ace554d37 8 weeks ago
| * 538e11597 9 weeks ago
| * bef32d1e1 9 weeks ago
| * 4315dc7fb 9 weeks ago
| * b30c6c8e5 9 weeks ago
| | *   19bbcc121 5 months ago  (refs/stash)
| | |\
| | | * 0d9227eca 5 months ago
| | |/
| | * 145744d00 5 months ago  (DotNetStandard2)
| |/
| * 2b4d8ee17 6 months ago
|/
*   588567ebe 2 years, 10 months ago
|\
| *   bf6f0c9a0 2 years, 11 months ago
| |\
| * | d49a6b61f 2 years, 11 months ago
| * | 0500ce07a 2 years, 11 months ago
| * | 6d735658f 2 years, 11 months ago
| * | 0b656d94f 2 years, 11 months ago
| * | de22e1170 2 years, 11 months ago
| * | 204f077a9 2 years, 11 months ago
| * | 371bfb472 2 years, 11 months ago
| * | 937d2cb9b 2 years, 11 months ago
| * | fa1e82570 2 years, 11 months ago
| * | 8d5e30f6e 2 years, 11 months ago
| * | 0681132fd 2 years, 11 months ago
| * | 69493e50e 2 years, 11 months ago
| * | 3b2c09e7a 2 years, 11 months ago
| * | 11cb786c7 2 years, 11 months ago
| * | 14e5fca8e 2 years, 11 months ago
| * | 30ca26640 2 years, 11 months ago
| * | 48e58b07e 2 years, 11 months ago
| * | 4202f3db4 2 years, 11 months ago
| * | 08efe4b06 5 years ago
| * | a8dea04a2 5 years ago
| * | 1281c4030 5 years ago
|  /
* | cfe3d27c1 2 years, 11 months ago  (origin/master, origin/HEAD, master)
* | 1b26c63ca 2 years, 11 months ago
* |   76994381e 2 years, 11 months ago
|\ \
| * | 2925c491e 2 years, 11 months ago
| |\ \
| | * | 64661e024 2 years, 11 months ago
| | * | a4f874828 2 years, 11 months ago
| | * |   53208f08e 2 years, 11 months ago
| | |\ \
| | | * | fdee05a9d 2 years, 11 months ago
| | | * | 246ac9a96 2 years, 11 months ago
| | | * | 4ec6fee10 2 years, 11 months ago
| | | * | dad09ee82 2 years, 11 months ago
| | | * | f6e8f78b1 2 years, 11 months ago
| | | * | c911353fd 2 years, 11 months ago
| | |  /
| | * | 562b937a1 2 years, 11 months ago
| | * | 9d4340b6b 2 years, 11 months ago
| |  /
| * | 36938f9de 2 years, 11 months ago
| * | 32b6d2774 2 years, 11 months ago
|  /
* | 55a90b221 2 years, 11 months ago
* | 0ee380505 2 years, 11 months ago  (origin/opentk)
/
| * ea5d5230d 6 months ago  (origin/mono.simd)
| * 5eaeb50aa 6 years ago
| * b75e9eeba 10 years ago
| * f8b4fd18d 10 years ago
| * 2c1c0704d 10 years ago
| * bc46eb35b 10 years ago
| * 6171eb2f5 10 years ago
| * 2a90cb8fa 10 years ago
| | * 1339b33c3 5 years ago  (origin/WinRT, WinRT)
| | * 85fc2dc26 5 years ago
| | * 569afda98 6 years ago
bug

Most helpful comment

I had the same issue when using mode Mainline on Jenkins. What I did that solved my issue was adding this regex to master:

master:
    regex: (^master$|^origin\/master$)
    tag: ''
    increment: minor

GitVersion will now look at origin/master also, instead of just looking at master.

All 18 comments

I was able to get past this by changing from Mainline to ContinuousDelivery

Since the problem is solved, I'll close. Please reopen if you are able to reproduce this in a public repository we can investigate.

I had this issue as well. For me, the issue was that the build server (TFS) did not have master or the branch checked out, rather it was operating in detached head state. Normally, GitVersion is smart enough to detect this condition, but it is powerless to do so in a Docker container.

I was able to work around the issue using a bash script like this (please note that the $(...) looking variables are TFS specific variables):

branchName="$(Build.SourceBranchName)"

if [ -n "$(System.PullRequest.PullRequestId)" ]
then
  branchName="PullRequest$(System.PullRequest.PullRequestId)"
fi

# Checkout branch
git checkout -B $branchName
# Checkout master for mainline calculation
git checkout master
# Checkout branch again
git checkout $branchName

I had this issue as well. For me, the issue was that the build server (TFS) did not have master or the branch checked out, rather it was operating in detached head state. Normally, GitVersion is smart enough to detect this condition, but it is powerless to do so in a Docker container.

I was able to work around the issue using a bash script like this (please note that the $(...) looking variables are TFS specific variables):

branchName="$(Build.SourceBranchName)"

if [ -n "$(System.PullRequest.PullRequestId)" ]
then
  branchName="PullRequest$(System.PullRequest.PullRequestId)"
fi

# Checkout branch
git checkout -B $branchName
# Checkout master for mainline calculation
git checkout master
# Checkout branch again
git checkout $branchName

this saved some of our time, thanks!

I know it's not exactly the way one should do it but this error can easily be reproduced by a edgy configuration in an almost empty repo.

Since gitversion could give a more helpful error message here I think this issue should be reopened even if there is a workaround.

I did this on a pretty empty repository

git init .
<add .gitignore>

Then I add this gitversion.yml

mode: Mainline
branches:
  master:
    regex: ^master$
    tag: beta
    is-mainline: true
  release:
    tag: ''
    regex: ^release/
    is-mainline: false

and then..

git add -A
git commit -m "Initial commit"
git checkout -b "feature/new-feature"
"hello" > hello.txt
git add -A
git commit -m "add hello"
git checkout master

gitversion works, then I swap the is-mainline flags of release and mainline like this. (I really don't know why one would like to do this but...)

mode: Mainline
branches:
  master:
    regex: ^master$
    tag: beta
    is-mainline: false
  release:
    tag: ''
    regex: ^release/
    is-mainline: true

and calling gitversion gives an exception:

...
  INFO [10/07/19 8:02:06:58] End: Using mainline development mode to calculate current version (Took: 10.00ms)
  ERROR [10/07/19 8:02:06:63] An unexpected error occurred:
System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source, Func`2 predicate)
   at GitVersion.VersionCalculation.MainlineVersionCalculator.GetMainline(GitVersionContext context, Commit baseVersionSource)
   at GitVersion.VersionCalculation.MainlineVersionCalculator.FindMainlineModeVersion(BaseVersion baseVersion, GitVersionContext context)
   at GitVersion.VersionCalculation.NextVersionCalculator.FindVersion(GitVersionContext context)
   at GitVersion.GitVersionFinder.FindVersion(GitVersionContext context)
   at GitVersion.ExecuteCore.<>c__DisplayClass8_0.<ExecuteInternal>b__0(IRepository repo)
   at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache, Boolean noNormalize)
   at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem, IEnvironment environment)
   at GitVersion.Program.VerifyArgumentsAndRun()
...

Are you able to reproduce this in a RepositoryFixture test akin to the following, @da9l?

https://github.com/GitTools/GitVersion/blob/84b4af965855ab5c8d503521c075518af943659f/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs#L15-L40

If we could get a failing test in place, it would be much easier to output a better error message.

I'd love to. When I create a branch for this failing test in my fork, does
it matter what I call it?
Would it be ok to name it failingtest\
Regards, Daniel

On Mon, Oct 7, 2019 at 10:47 AM Asbjørn Ulsberg notifications@github.com
wrote:

Are you able to reproduce this in a RepositoryFixture test akin to the
following, @da9l https://github.com/da9l?

https://github.com/GitTools/GitVersion/blob/84b4af965855ab5c8d503521c075518af943659f/src/GitVersionCore.Tests/IntegrationTests/FeatureBranchScenarios.cs#L15-L40

If we could get a failing test in place, it would be much easier to output
a better error message.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/GitTools/GitVersion/issues/1671?email_source=notifications&email_token=AABD23P3LSM7ZKNBOS6QS2TQNLZP7A5CNFSM4HKY3FAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPPN7A#issuecomment-538900220,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABD23IBISVWZ4Z4Q2ZZ7PLQNLZP7ANCNFSM4HKY3FAA
.

--
mail & MSN:[email protected]
twitter.com/8DH

Thanks, that's awesome! The name of the branch is irrelevant, but a descriptive name is of course preferable. 😃👍

Ok, I've created a very simple but failing test for this. It does probably
not cover all possible cases.

Thanks for nudging me into the right direction.
/Daniel

On Mon, Oct 7, 2019 at 11:04 AM Asbjørn Ulsberg notifications@github.com
wrote:

Thanks, that's awesome! The name of the branch is irrelevant, but a
descriptive name is of course preferable. 😃👍


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/GitTools/GitVersion/issues/1671?email_source=notifications&email_token=AABD23L3O2L7Z3F5LR56WKTQNL3Q3A5CNFSM4HKY3FAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPRBTI#issuecomment-538906829,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AABD23ORK2QKZHN3WIAA24DQNL3Q3ANCNFSM4HKY3FAA
.

--
mail & MSN:[email protected]
twitter.com/8DH

Excellent! If you have ideas for what the error message should say, feel free to change that in the PR and then do var exception = Assert.Throws<CustomExceptionType>(() => ...) to assert that the correct exception is thrown and that it contains the expected stuff inside .Message.

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

This issue has been automatically marked as stale because it has not had recent activity. After 30 days from now, it will be closed if no further activity occurs. Thank you for your contributions.

just ran into this today in mainline strategy i use

@xalikoutis, that's unfortunate. We still haven't received pull requests fixing the problem, though, so it remains.

In my case, I think the issue was that there was no master branch, after the new default branch name became 'main'.
I just had this and the build passed

mode: Mainline
increment: Minor
branches: 
  main: 
    regex: ^main$
    is-mainline: true
    source-branches: ['main']
next-version: 1.0.0

I had the same issue when using mode Mainline on Jenkins. What I did that solved my issue was adding this regex to master:

master:
    regex: (^master$|^origin\/master$)
    tag: ''
    increment: minor

GitVersion will now look at origin/master also, instead of just looking at master.

That's great, @eduardojdreis! A PR that changes the default regex would be welcome.

i am still gertting this error when i clone the main branch and run gitversion

mode: Mainline
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
patch-version-bump-message: '\+semver:\s?(fix|patch)'
legacy-semver-padding: 4
build-metadata-padding: 4
commits-since-version-source-padding: 4
commit-message-incrementing: Enabled
no-bump-message: '\+semver:\s?(none|skip)'
branches:
  master:
    regex: (^main$|^origin\/main$)
    increment: none
    is-mainline: false
  develop:
    regex: ^new_app$
    tag: "beta"
    increment: Inherit
    is-mainline: true
    is-source-branch-for: ['feature', 'hotfix']
  feature:
    regex: ^features?[/-]
    tag: feature
    increment: Minor
    source-branches: ['develop']
  hotfix:
    regex: ^hotfix(es)?[/-]
    tag: hotfix
    increment: Patch
    source-branches: ['develop']
ignore:
  sha: []
merge-message-formats: {}
Was this page helpful?
0 / 5 - 0 ratings