GitVersion: An unexpected error occurred: Could not find a 'develop' or 'master' branch, neither locally nor remotely. branches are -> pull request branches

I get a random issue with GitVersion sometimes and it just crashes. It seems to fix it self somehow and I’m not sure what the problem is. Seems to only occur with pull requests.

[Step 1/1] PowerShell Executable: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe
[16:57:45][Step 1/1] Working directory: D:\Agents\Stuart\BuildAgent\work\468fca067adfe73b
[16:57:45][Step 1/1] PowerShell arguments: [-NoProfile, -NonInteractive, -ExecutionPolicy, ByPass, -File, D:\Agents\Stuart\BuildAgent\temp\buildTmp\powershell3691463211772820837.ps1]
[16:57:46][Step 1/1] Chocolatey already installed
[16:57:46][Step 1/1] GitVersion already installed
[16:57:46][Step 1/1] GitVersion will not be updated
[16:57:46][Step 1/1] Running: C:\ProgramData\chocolatey\bin\gitversion.exe "D:\Agents\Stuart\BuildAgent\work\468fca067adfe73b" /u 'TeamCity' /p '*****' /output 'buildserver' /UpdateAssemblyInfo
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:27] Working directory: D:\Agents\Stuart\BuildAgent\work\468fca067adfe73b
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:28] Running on Windows.
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:28] Applicable build agent found: 'TeamCity'.
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:34] Project root is: D:\Agents\Stuart\BuildAgent\work\468fca067adfe73b
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:47] Begin: Loading version variables from disk cache
[16:57:46][Step 1/1]   INFO [06/23/16 16:57:46:51] Cache file D:\Agents\Stuart\BuildAgent\work\468fca067adfe73b\.git\gitversion_cache\E574FC60B3C269AF25C1BD6BE16A4B76066E5F64.yml not found.
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:51] End: Loading version variables from disk cache (Took: 39.04ms)
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:51] Branch from build environment: refs/pull-requests/11/from
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:94] Using latest commit on specified branch
[16:57:46][Step 1/1] INFO [06/23/16 16:57:46:96] Begin: Attempting to inherit branch configuration from parent branch
[16:57:46][Step 1/1]   INFO [06/23/16 16:57:46:98] Begin: Finding branch source
[16:57:46][Step 1/1]   INFO [06/23/16 16:57:46:99] End: Finding branch source (Took: 3.00ms)
[16:57:47][Step 1/1]   INFO [06/23/16 16:57:47:00] Found possible parent branches: 
[16:57:47][Step 1/1] INFO [06/23/16 16:57:47:00] End: Attempting to inherit branch configuration from parent branch (Took: 36.94ms)
[16:57:47][Step 1/1] ERROR [06/23/16 16:57:47:00] An unexpected error occurred:
[16:57:47][Step 1/1] System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
[16:57:47][Step 1/1]    at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(Boolean onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair`2 keyValuePair, BranchConfig branchConfiguration, Config config, IList`1 excludedInheritBranches)
[16:57:47][Step 1/1]    at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(Commit currentCommit, IRepository repository, Boolean onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList`1 excludedInheritBranches)
[16:57:47][Step 1/1]    at GitVersion.GitVersionContext.CalculateEffectiveConfiguration()
[16:57:47][Step 1/1]    at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId)
[16:57:47][Step 1/1]    at GitVersion.GitVersionContext..ctor(IRepository repository, Config configuration, Boolean isForTrackingBranchOnly, String commitId)
[16:57:47][Step 1/1]    at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, IRepository repo, GitPreparer gitPreparer, String projectRoot, IBuildServer buildServer, Config overrideConfig)
[16:57:47][Step 1/1]    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig)
[16:57:47][Step 1/1]    at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
[16:57:47][Step 1/1]    at GitVersion.Program.VerifyArgumentsAndRun()
[16:57:47][Step 1/1] INFO [06/23/16 16:57:47:00] 
[16:57:47][Step 1/1] INFO [06/23/16 16:57:47:00] Here is the current git graph (please include in issue): 
[16:57:47][Step 1/1] INFO [06/23/16 16:57:47:00] Showing max of 100 commits
[16:57:47][Step 1/1] INFO [06/23/16 16:57:47:10] * 69659a1 26 minutes ago  (refs/pull-requests/9/from)
[16:57:47][Step 1/1] * b049f54 51 minutes ago 
[16:57:47][Step 1/1] * dcd8d10 66 minutes ago 
[16:57:47][Step 1/1] * 31fc353 3 hours ago 
[16:57:47][Step 1/1] | * 6e59dde 47 minutes ago  (HEAD -> pull-requests/11/from, refs/pull-requests/11/from)
[16:57:47][Step 1/1] | * 1b0502a 50 minutes ago 
[16:57:47][Step 1/1] | * 12211e8 52 minutes ago 
[16:57:47][Step 1/1] | * 78401ab 60 minutes ago 
[16:57:47][Step 1/1] | * 11a9ea9 62 minutes ago 
[16:57:47][Step 1/1] | * 2f4fa7f 80 minutes ago 
[16:57:47][Step 1/1] | * 59b8fa0 86 minutes ago 
[16:57:47][Step 1/1] | * 9fb7e81 89 minutes ago 
[16:57:47][Step 1/1] | * a4e4517 2 hours ago 
[16:57:47][Step 1/1] | * c63f7af 2 hours ago 
[16:57:47][Step 1/1] | * 5c4b7c8 2 hours ago 
[16:57:47][Step 1/1] | * 352eae3 2 hours ago 
[16:57:47][Step 1/1] | * 0710514 2 hours ago 
[16:57:47][Step 1/1] | *   e4f2797 3 hours ago 
[16:57:47][Step 1/1] | |\  
[16:57:47][Step 1/1] | | *   5eb6d4b 3 hours ago 
[16:57:47][Step 1/1] | | |\  
[16:57:47][Step 1/1] | | |/  
[16:57:47][Step 1/1] | |/|   
[16:57:47][Step 1/1] | * |   71b62ed 4 hours ago 
[16:57:47][Step 1/1] | |\ \  
[16:57:47][Step 1/1] | |/ /  
[16:57:47][Step 1/1] |/| |   
[16:57:47][Step 1/1] * | | 4a84a71 7 hours ago 
[16:57:47][Step 1/1] | * |   090c09e 8 hours ago 
[16:57:47][Step 1/1] | |\ \  
[16:57:47][Step 1/1] | |/ /  
[16:57:47][Step 1/1] |/| |   
[16:57:47][Step 1/1] * | |   77e9d76 25 hours ago 
[16:57:47][Step 1/1] |\ \ \  
[16:57:47][Step 1/1] | |/ /  
[16:57:47][Step 1/1] * | | 8ab3093 25 hours ago 
[16:57:47][Step 1/1] | | * 5bd5f44 24 hours ago 
[16:57:47][Step 1/1] | | * 7924822 24 hours ago 
[16:57:47][Step 1/1] | | * 8121c7d 24 hours ago 
[16:57:47][Step 1/1] | | * 3df36a2 25 hours ago 
[16:57:47][Step 1/1] | | * 264495e 25 hours ago 
[16:57:47][Step 1/1] | | * 6ddaa97 25 hours ago 
[16:57:47][Step 1/1] | | * 275357c 25 hours ago 
[16:57:47][Step 1/1] | | * 3e2766e 25 hours ago 
[16:57:47][Step 1/1] | | * 2a36e8e 25 hours ago 
[16:57:47][Step 1/1] | | * 0b8d1ce 25 hours ago 
[16:57:47][Step 1/1] | | * 730344c 25 hours ago 
[16:57:47][Step 1/1] | | * c8a6f8b 26 hours ago 
[16:57:47][Step 1/1] | | * 531040f 26 hours ago 
[16:57:47][Step 1/1] | | * ac7b2c2 28 hours ago 
[16:57:47][Step 1/1] | | * 614abb2 29 hours ago 
[16:57:47][Step 1/1] | | * b294fea 30 hours ago 
[16:57:47][Step 1/1] | | * 0dabea1 30 hours ago 
[16:57:47][Step 1/1] | | * 90488c5 30 hours ago 
[16:57:47][Step 1/1] | | *   8a078ce 30 hours ago 
[16:57:47][Step 1/1] | | |\  
[16:57:47][Step 1/1] | | |/  
[16:57:47][Step 1/1] | |/|   
[16:57:47][Step 1/1] | * |   e8ae422 8 days ago 
[16:57:47][Step 1/1] | |\ \  
[16:57:47][Step 1/1] | | | * cf983be 3 days ago 
[16:57:47][Step 1/1] | | | * 23dfbf1 7 days ago 
[16:57:47][Step 1/1] | | | * b414f30 7 days ago 
[16:57:47][Step 1/1] | | |/  
[16:57:47][Step 1/1] | | * 7194ed4 8 days ago 
[16:57:47][Step 1/1] | | * bc06fe0 8 days ago 
[16:57:47][Step 1/1] | | * 27f8f0d 8 days ago 
[16:57:47][Step 1/1] | | * 267554d 8 days ago 
[16:57:47][Step 1/1] | |/  
[16:57:47][Step 1/1] | *   a38d309 8 days ago 
[16:57:47][Step 1/1] | |\  
[16:57:47][Step 1/1] | |/  
[16:57:47][Step 1/1] |/|   
[16:57:47][Step 1/1] * | 4b31eba 8 days ago 
[16:57:47][Step 1/1] * | 3142f1a 8 days ago 
[16:57:47][Step 1/1] |/  
[16:57:47][Step 1/1] * 505db56 8 days ago 
[16:57:47][Step 1/1] * 9c57077 9 days ago 
[16:57:47][Step 1/1] * 8db7e59 9 days ago 
[16:57:47][Step 1/1] * dbf7fe5 9 days ago 
[16:57:47][Step 1/1] * a951291 9 days ago 
[16:57:47][Step 1/1] * 61e7bd9 9 days ago 
[16:57:47][Step 1/1] * bc06c7d 9 days ago 
[16:57:47][Step 1/1] * b64c766 9 days ago 
[16:57:47][Step 1/1] * 63a4497 9 days ago 
[16:57:47][Step 1/1] * acf8134 9 days ago 
[16:57:47][Step 1/1] * ca51f91 10 days ago 
[16:57:47][Step 1/1] * 3106e785 2 weeks ago 
[16:57:47][Step 1/1] * 390c334 3 weeks ago 
[16:57:47][Step 1/1] * 75ea6ef 3 weeks ago 
[16:57:47][Step 1/1] * c2ded33 3 weeks ago 
[16:57:47][Step 1/1] * 7fe6a40 3 weeks ago 
[16:57:47][Step 1/1] *   a982c02 5 weeks ago 
[16:57:47][Step 1/1] |\  
[16:57:47][Step 1/1] | * 931800d 7 weeks ago 
[16:57:47][Step 1/1] | * 146d43a 7 weeks ago 
[16:57:47][Step 1/1] | *   b67e115 7 weeks ago 
[16:57:47][Step 1/1] | |\  
[16:57:47][Step 1/1] | | * ce7a48f 7 weeks ago 
[16:57:47][Step 1/1] | | * 2010dc9 7 weeks ago 
[16:57:47][Step 1/1] | | * dd75cce 7 weeks ago 
[16:57:47][Step 1/1] | | * f33c571 7 weeks ago 
[16:57:47][Step 1/1] | | * 317edd6 7 weeks ago 
[16:57:47][Step 1/1] | | * 0627c12 7 weeks ago 
[16:57:47][Step 1/1] | | * c8fa8ba 8 weeks ago 
[16:57:47][Step 1/1] | * | d00df38 8 weeks ago 
[16:57:47][Step 1/1] | * | e77b9be 8 weeks ago 
[16:57:47][Step 1/1] | |/  
[16:57:47][Step 1/1] | * 971bde9 9 weeks ago 
[16:57:47][Step 1/1] | * a9298ff 9 weeks ago 
[16:57:47][Step 1/1] | * 7883cde 9 weeks ago 
[16:57:47][Step 1/1] | * 22cd9f2 9 weeks ago 
[16:57:47][Step 1/1] | * 25c9667 9 weeks ago 
[16:57:47][Step 1/1] | * bf0745f 2 months ago 
[16:57:47][Step 1/1] | * 2c46bc7 3 months ago 
[16:57:47][Step 1/1] | * 0deb1aa 3 months ago 
[16:57:47][Step 1/1] | * 2906eab 3 months ago 
[16:57:47][Step 1/1] | * 15d5534 3 months ago 
[16:57:47][Step 1/1] | * 963e44d 3 months ago 
[16:57:47][Step 1/1] | * cd30a1a 3 months ago 
[16:57:47][Step 1/1] | * 7f49dc2 3 months ago 
[16:57:47][Step 1/1] | * ab2a9bd 3 months ago 
[16:57:47][Step 1/1] | * 4d2b370 3 months ago 
[16:57:47][Step 1/1] * | 2034ded 3 months ago 
[16:57:47][Step 1/1] * | b9d27ed 4 months ago 

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 46 (23 by maintainers)

Commits related to this issue

Most upvoted comments

I’m slow and just noticed this on my end after updating TeamCity. When the branch is not master or develop this happens (probably because of the shallow clone). Wonder if there is a toggle in TC for non-shallow clone.

FOUND IT! This is how you do it:

Since TeamCity 10.0.4 you can make git-plugin to fetch all heads by adding a build configuration parameter ‘teamcity.git.fetchAllHeads=true’.

If you do it in Root you won’t have to keep writing the same parameter.

Is there any further update on this issue? We’re using GitVersion with TeamCity and have encountered this issue. I can’t see any permanent workaround or fix in this thread?

Might TeamCity bug TW-24878 be the issue at hand here? With version 10.0.4 of TeamCity, the configuration parameter teamcity.git.fetchAllHeads can be added to a project and when set to true, TeamCity should fetch all branches and not just the current.

I’m not sure it’s related, but since it yields the same exception, I’ve found git branch --all revealing something interesting:

* (detached from 90b9dee)
  feature/travis-matrix
  remotes/origin/feature/travis-matrix

Even after doing git fetch --unshallow and git fetch --all, we’re in a detached state with two weird looking branches. Perhaps other build servers are doing similar things? We at least need to figure out how to get the Git repository from this messed up state into something GitVersion is able to work with.

@JakeGinnivan Ideas?

I hit the same problem and git fetch -all solved it

teamcity.git.fetchAllHeads: true fixed for me

This workaround fixed the issue for us: https://youtrack.jetbrains.com/issue/TW-24878

@asbjornu exactly, but it doesn’t fetch the PR at all - the feature is just broken. I’ve managed to get this all to work by using ssh vcs roots, the sshAgent feature and uploaded keys. I can now do a git fetch --all as the first step my build process.

@FunnyFry This is because the VSTS agent doesn’t fetch master or develop branches. See #993 for a workaround.

@JakeGinnivan sure. It looks like it fetches only the feature branch.

{15:28:52] : [VCS Root: Calamari] The .git directory is missing in ‘Z:\BuildAgent\work\14ffc968155e4956’. Running ‘git init’… [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” init [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” remote add origin https://USERNAME@github.com/OctopusDeploy/Calamari.git [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” config core.sparseCheckout true [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” show-ref [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” show-ref refs/remotes/origin/feature-dawops [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” log -n1 --pretty=format:%H%x20%s dbefc7e15a5d7d1912f859fd4f8d19aeafde625c – [15:28:52] : [VCS Root: Calamari] fatal: bad object dbefc7e15a5d7d1912f859fd4f8d19aeafde625c [15:28:52] : [VCS Root: Calamari] Commit ‘dbefc7e15a5d7d1912f859fd4f8d19aeafde625c’ is not found in repository. Running ‘git fetch’… [15:28:52] : [VCS Root: Calamari] [Z:\BuildAgent\work\14ffc968155e4956]: “C:\Program Files (x86)\Git\bin\git.exe” -c core.askpass=Z:\BuildAgent\temp\buildTmp\pass540415618131226675.bat fetch --progress origin +refs/heads/feature-dawops:refs/remotes/origin/feature-dawops (5s)

@JakeGinnivan Doing git fetch origin +refs/heads/*:refs/remotes/origin/* --unshallow, it still fails, but with a new exception:

LibGit2Sharp.LibGit2SharpException: ref 'refs/remotes/origin/feature/mkdocs-build' doesn't match the destination
  at LibGit2Sharp.Core.Ensure.HandleError (Int32 result) <0x409cc4f0 + 0x00127> in <filename unknown>:0 
  at LibGit2Sharp.Core.Ensure.ZeroResult (Int32 result) <0x409347c0 + 0x0001f> in <filename unknown>:0 
  at LibGit2Sharp.Core.Proxy.git_refspec_rtransform (IntPtr refSpecPtr, System.String name) <0x409cc230 + 0x00062> in <filename unknown>:0 
  at LibGit2Sharp.Remote.FetchSpecTransformToSource (System.String reference) <0x409cc160 + 0x00080> in <filename unknown>:0 
  at LibGit2Sharp.BranchUpdater.GetUpstreamInformation (System.String canonicalName, System.String& remoteName, System.String& mergeBranchName) <0x409cbb90 + 0x0019a> in <filename unknown>:0 
  at LibGit2Sharp.BranchUpdater.SetUpstream (System.String upstreamBranchName) <0x409cba20 + 0x00058> in <filename unknown>:0 
  at LibGit2Sharp.BranchUpdater.set_TrackedBranch (System.String value) <0x409cb980 + 0x00064> in <filename unknown>:0 
  at GitTools.Git.GitRepositoryHelper+<>c__DisplayClass8_1.<CreateOrUpdateLocalBranchesFromRemoteTrackingOnes>b__2 (LibGit2Sharp.BranchUpdater b) <0x409cb950 + 0x0001f> in <filename unknown>:0 
  at LibGit2Sharp.BranchCollection.Update (LibGit2Sharp.Branch branch, System.Action`1[] actions) <0x409cb710 + 0x0009d> in <filename unknown>:0 
  at GitTools.Git.GitRepositoryHelper.CreateOrUpdateLocalBranchesFromRemoteTrackingOnes (LibGit2Sharp.Repository repo, System.String remoteName) <0x409c8aa0 + 0x007cc> in <filename unknown>:0 
  at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory (System.String gitDirectory, GitTools.Git.AuthenticationInfo authentication, Boolean noFetch, System.String currentBranch) <0x40984430 + 0x0021e> in <filename unknown>:0 
  at GitVersion.GitPreparer.Initialise (Boolean normaliseGitDirectory, System.String currentBranch) <0x40938560 + 0x00069> in <filename unknown>:0 
  at GitVersion.ExecuteCore.ExecuteGitVersion (System.String targetUrl, System.String dynamicRepositoryLocation, GitVersion.Authentication authentication, System.String targetBranch, Boolean noFetch, System.String workingDirectory, System.String commitId, GitVersion.Config overrideConfig, Boolean noCache) <0x409358e0 + 0x0018b> in <filename unknown>:0 
  at GitVersion.SpecifiedArgumentRunner.Run (GitVersion.Arguments arguments, IFileSystem fileSystem) <0x40935220 + 0x001c4> in <filename unknown>:0 
  at GitVersion.Program.VerifyArgumentsAndRun () <0x408fd1e0 + 0x00442> in <filename unknown>:0 

From my message in gitter:

Yep, after running git clone --depth=50 --branch=feature/travis-matrix https://github.com/asbjornu/GitVersion.git. The config for that repo is:

[remote "origin"]
    url = https://github.com/asbjornu/GitVersion.git
    fetch = +refs/heads/feature/travis-matrix:refs/remotes/origin/feature/travis-matrix

So the fix is run git fetch origin +refs/heads/*:refs/remotes/origin/* --unshallow

It looks like an issue with TeamCity and they way it pulls down the repo to the build agent. it doesn’t do a full fetch. I’ve fixed this for us by adding an extra PowerShell build step that simply calls ‘git fetch’.