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

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

Closed
Ashtonian opened this Issue Jun 23, 2016 · 41 comments

Comments

Projects
None yet
@Ashtonian
Copy link

Ashtonian commented Jun 23, 2016

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 

@Ashtonian Ashtonian changed the title An unexpected error occurred An unexpected error occurred: Could not find a 'develop' or 'master' branch, neither locally nor remotely. Jun 24, 2016

@Ashtonian Ashtonian changed the title An unexpected error occurred: Could not find a 'develop' or 'master' branch, neither locally nor remotely. An unexpected error occurred: Could not find a 'develop' or 'master' branch, neither locally nor remotely. branches are -> pull request branches Jun 24, 2016

@Ashtonian

This comment has been minimized.

Copy link
Author

Ashtonian commented Jun 24, 2016

I'm using teamcity and the git plugin, I logged into the cloned repository and ran git branch and it returns:

(pull-requests/1/from)

as thats the bitbucket remote. Makes sense that gitversion can't find master then. It's odd though because this only happens occasionally.

Not sure what to do to fix it.

@msnelling

This comment has been minimized.

Copy link

msnelling commented Jul 1, 2016

I'm getting the same issue here. We're porting our projects from Bamboo into TeamCity and use GitVersion with GitFlow

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Jul 4, 2016

Are you able to figure out how the pull request branches are checked out by git? What GitVersion configuration do you have (are you using nofetch, for instance)? What variant of GitVersion are you using? The MSBuild task, executable or something else? What version of GitVersion are you using? Is TeamCity configured to checkout on the server or on the agent?

@msnelling

This comment has been minimized.

Copy link

msnelling commented Jul 4, 2016

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

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Jul 4, 2016

@msnelling Sounds like a sneaky work-around, but I'm glad it works. I wish we could find a way for GitVersion to circumvent this so users of it didn't have to circumvent it themselves, though. Ideas, @GitTools/developers?

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Jul 10, 2016

Interesting..

The issue is https://github.com/GitTools/GitVersion/blob/master/src/GitVersionCore/BuildServers/TeamCity.cs#L44

If you setup GitVersion according to docs this will happen. Looks like we can't skip the fetch, so that override has to be removed unfortunately :(

@roryprimrose

This comment has been minimized.

Copy link

roryprimrose commented Aug 31, 2016

I have the same issue with VSTS with two separate scenarios.

  1. A VS solution that produces nuget packages with versioning via GitVersionTask.
  2. A plain repository with files and a nuspec using GitVersion build step to push the version into the nuget pack step

We seem to be hitting this using either the GitVersion build step or GitVersionTask package in a proj. Is there any workaround that we should apply to fix this?

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Aug 31, 2016

@roryprimrose workaround for VSTS is at #993

@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 2, 2016

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

@urig

This comment has been minimized.

Copy link
Contributor

urig commented Sep 2, 2016

My 2 cents: As the comment in the code states, this error needs a much more meaningful error message with suggestions for action to resolve. (I'd create a PR myself but I don't really understand the issue or its resolution.)

I think we're seeing more and more people bump into this issue - Who knows how many others give up on GitVersion before resolving through this page? :|

@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 2, 2016

Actually it is also intermittent in my case. It did not work.

[WriteVersionInfoToBuildLog] WARN [09/02/16 5:36:51:85] Could not determine assembly version: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely.
   at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(Boolean onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair`2 keyValuePair, BranchConfig branchConfiguration, Config config, IList`1 excludedInheritBranches)
   at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(Commit currentCommit, IRepository repository, Boolean onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList`1 excludedInheritBranches)
   at GitVersion.GitVersionContext.CalculateEffectiveConfiguration()
   at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId)
   at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo)
   at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action)
   at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, GitPreparer gitPreparer, IBuildServer buildServer, Config overrideConfig)
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
   at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication)
[15:36:51]W:                                             [source\Calamari\Calamari.csproj] UpdateAssemblyInfo
[15:36:51]W:                                                 [UpdateAssemblyInfo] UpdateAssemblyInfo

Then I added git fetch -all and it worked. Once. Then it failed twice.

     [WriteVersionInfoToBuildLog]   INFO [09/02/16 8:14:58:84] Merge message 'Merge branch 'release/3.3.0' of https://github.com/octopusdeploy/calamari into release/3.3.0': 3.3.0 with commit count source b37c695558fe836cbea39ced558f9b9d52161950
[18:14:58] :                                                     [WriteVersionInfoToBuildLog]   INFO [09/02/16 8:14:58:84] Found multiple base versions which will produce the same SemVer (3.4.33-dawops.21), taking oldest source for commit counting (Git tag '3.4.33-dawops.20')
[18:14:58] :                                                     [WriteVersionInfoToBuildLog]   INFO [09/02/16 8:14:58:85] Base version used: Git tag '3.4.33-dawops.20': 3.4.33-dawops.20 with commit count source dbefc7e15a5d7d1912f859fd4f8d19aeafde625c
[18:14:58] :                                                     [WriteVersionInfoToBuildLog] INFO [09/02/16 8:14:58:85] End: Calculating base versions (Took: 2,332.00ms)
[18:14:58]W:                                                     [WriteVersionInfoToBuildLog] WARN [09/02/16 8:14:58:85] Could not determine assembly version: System.NotSupportedException: Mainline development mode doesn't yet support pre-release tags on master
   at GitVersion.VersionCalculation.NextVersionCalculator.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.ExecuteInternal(String targetBranch, String commitId, GitPreparer gitPreparer, IBuildServer buildServer, Config overrideConfig)
   at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
   at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication)
[18:14:58]W:                                             [source\Calamari\Calamari.csproj] UpdateAssemblyInfo (2s)

image

@roryprimrose

This comment has been minimized.

Copy link

roryprimrose commented Sep 2, 2016

The workaround suggested in #993 worked for one build but other builds failed wanting a username. I updated the build workflow to be surrounded by the ioz build steps and they were all good. See https://marketplace.visualstudio.com/items?itemName=ioz.vsts-git-build-tasks

@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 2, 2016

Hmmm, there was a 3.4.33-dawops.20 tag in the source control. I can imagine GitVersion added it and this is why the build worked once. I've removed it and the build works fine now but the version is 3.4.6-dawops.22. Not sure why but this is a problem for Monday :)

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 2, 2016

I haven't used mainline mode with release branches yet.

It seems that the issue has just started happening on TeamCity, can someone let me know: Version of teamcity and agent or server checkout, also the GitVersion.yml config and what your fetch refspec for your build is?

In VSTS this happens because the build agent initialises and fetches the git repo with a refspec of +refs/pulls//merge:refs/pulls//merge, which means that only the PR ref is pulled down, not master or develop, so not branch config can be inherited.

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 2, 2016

there was a 3.4.33-dawops.20 tag in the source control. I can imagine GitVersion added it and this is why the build worked once

GitVersion never tags, maybe was the build server?

@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 4, 2016

@JakeGinnivan thanks for having a look. These are our details:
TC Server: 10.0 (build 42002)
GitVersion.yaml, just one line: mode: Mainline

From what you are saying fetching develop and master is the way it needs to be done ?

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 4, 2016

Yeah, just do a fetch.

Make sure you upgrade to v4-beta.7, it fixes a nasty bug where if you do a second fetch to work around this issue and the branch you are building moves on it can checkout the remote HEAD, so you build a different commit =/

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 4, 2016

I will try and put some time into fixing properly, but lots on at the moment.

@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 4, 2016

Thanks

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Sep 5, 2016

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?

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 6, 2016

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

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Sep 6, 2016

@pawelpabich can you figure out what git command TeamCity is running in your case, each build server will require different treatment.

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Sep 6, 2016

@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 
@pawelpabich

This comment has been minimized.

Copy link

pawelpabich commented Sep 6, 2016

@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)

@mikeblakeuk

This comment has been minimized.

Copy link

mikeblakeuk commented Sep 6, 2016

We are also seeing this with
TeamCity 9.1 (Agent side checkout)
GitHub
GitVersionTask.3.6.3 and 4.0.0-beta7

[14:23:49] : Updating sources: agent side checkout (19s)
[14:23:49] :     [Updating sources] Will perform clean checkout. Reason: "Clean all files before build" turned on (running for 57s)
[14:23:49] :     [Updating sources] Cleaning D:\BuildAgent\work\5012345
[14:23:54] :     [Updating sources] VCS Root: MIKEBLAKE (14s)
[14:23:54] :         [VCS Root: MIKEBLAKE] revision: 4d12345
[14:23:54] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" show-ref
[14:23:54] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" ls-remote origin
[14:23:57] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" show-ref refs/heads/develop
[14:23:57] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" show-ref refs/heads/feature/FEET1
[14:23:57] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" fetch --progress origin +refs/heads/feature/FEET1n:refs/heads/feature/FEET1 (2s)
[14:24:00] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" log -n1 --pretty=format:%H%x20%s 4d12345 --
[14:24:00] :         [VCS Root: MIKEBLAKE] Cleaning D:\BuildAgent\work\5012345
[14:24:00] :         [VCS Root: MIKEBLAKE] The .git directory is missing in 'D:\BuildAgent\work\5012345'. Running 'git init'...
[14:24:00] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" init
[14:24:00] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" remote add origin git@github.com:GITROOT/MIKEBLAKE.git
[14:24:00] :         [VCS Root: MIKEBLAKE] [C:\BuildAgent\system\git\git-CAC8AEB6.git]: "C:\Program Files\Git\bin\git.exe" pack-refs
[14:24:00] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" show-ref
[14:24:00] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" ls-remote origin
[14:24:04] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" show-ref refs/remotes/origin/feature/FEET1
[14:24:04] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" log -n1 --pretty=format:%H%x20%s 4d12345 --
[14:24:04] :         [VCS Root: MIKEBLAKE] Commit '4d12345' is not found in repository. Running 'git fetch'...
[14:24:04] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" fetch --progress origin +refs/heads/feature/FEET1:refs/remotes/origin/feature/FEET1 (4s)
[14:24:08] :             [[D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" fetch --progress origin +refs/heads/feature/FEET1:refs/remotes/origin/feature/FEET1] From github.com:GITROOT/MIKEBLAKE
[14:24:08] :             [[D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" fetch --progress origin +refs/heads/feature/FEET1:refs/remotes/origin/feature/FEET1]  * [new branch]      feature/FEET1 -> origin/feature/FEET1
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" log -n1 --pretty=format:%H%x20%s 4d12345 --
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" config core.autocrlf
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" branch
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" branch -l --track feature/FEET1 refs/remotes/origin/feature/FEET1
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" update-ref refs/heads/feature/FEET1 4d12345
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" checkout -q -f feature/FEET1
[14:24:08] :         [VCS Root: MIKEBLAKE] Cleaning MIKEBLAKE in D:\BuildAgent\work\5012345 the file set ALL_UNTRACKED
[14:24:08] :         [VCS Root: MIKEBLAKE] [D:\BuildAgent\work\5012345]: "C:\Program Files\Git\bin\git.exe" clean -f -d -x
[14:24:08]i: ##teamcity[buildStatisticValue key='buildStageDuration:sourcesUpdate' value='19794.0']
[14:24:08] : Build preparation done
[14:24:17] :     [Step 2/2] MSBUILD : warning : WARN [09/06/16 14:24:17:68] Could not determine assembly version: System.InvalidOperationException: Could not find a 'develop' or 'master' branch, neither locally nor remotely. [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.BranchConfigurationCalculator.InheritBranchConfiguration(Boolean onlyEvaluateTrackedBranches, IRepository repository, Commit currentCommit, Branch currentBranch, KeyValuePair`2 keyValuePair, BranchConfig branchConfiguration, Config config, IList`1 excludedInheritBranches) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.BranchConfigurationCalculator.GetBranchConfiguration(Commit currentCommit, IRepository repository, Boolean onlyEvaluateTrackedBranches, Config config, Branch currentBranch, IList`1 excludedInheritBranches) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.GitVersionContext.CalculateEffectiveConfiguration() [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.GitVersionContext..ctor(IRepository repository, Branch currentBranch, Config configuration, Boolean onlyEvaluateTrackedBranches, String commitId) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.ExecuteCore.<>c__DisplayClass6_0.<ExecuteInternal>b__0(IRepository repo) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.GitPreparer.WithRepository[TResult](Func`2 action) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteInternal(String targetBranch, String commitId, GitPreparer gitPreparer, IBuildServer buildServer, Config overrideConfig) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig) [D:\BuildAgent\work\5012345\src\Project.csproj]
[14:24:17] :     [Step 2/2] MSBUILD : warning :    at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication) [D:\BuildAgent\work\5012345\src\Project.csproj]

Would https://gitversion.readthedocs.io/en/latest/more-info/dynamic-repositories/ help? they feel expensive if the agent is clean each time.

@mikeblakeuk

This comment has been minimized.

Copy link

mikeblakeuk commented Sep 6, 2016

Note;
Using agent side checkout then adding a Step 1 command line to get the root branch i think is working...

"%env.TEAMCITY_GIT_PATH%" fetch --progress origin %vcsroot.branch%
@FunnyFry

This comment has been minimized.

Copy link
Contributor

FunnyFry commented Nov 3, 2016

We are getting this error in VSTS 100% repro for Pull Request builds after upgrading our VSTS build agents to v2+.

The git commands being executed by VSTS agent are:
> git remote add origin https://[account].visualstudio.com/[project]/_git/[repo]
> git config gc.auto 0
> git config --get-all http.https://[account].visualstudio.com/[project]/_git/[repo].extraheader
> git -c http.extraheader="AUTHORIZATION: bearer ********" fetch --tags --prune --progress origin +refs/pull/11970/merge:refs/remotes/pull/11970/merge
> git checkout --progress --force refs/remotes/pull/11970/merge

Let me know if there is any other information I can provide to help.

@pascalberger

This comment has been minimized.

Copy link
Member

pascalberger commented Nov 3, 2016

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

@andreasnilsen

This comment has been minimized.

Copy link

andreasnilsen commented Jan 2, 2017

Anyone got a workaround for when using (uploaded) SSH key for authentication in TeamCity?
If I add a command build step with

git fetch --all,

it fails on authentication/permissions, so I have to change the VCS roots back to username/password authentication to get this working.

I haven't observed this behaviour before upgrading from TC 9.1.7 -> 10.0.4, but that may be coincidental.
Btw, this seems to happen when building feature branches as well as PR's.

@mattsalmon

This comment has been minimized.

Copy link

mattsalmon commented Feb 26, 2017

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?

@JakeGinnivan

This comment has been minimized.

Copy link
Contributor

JakeGinnivan commented Feb 26, 2017

This is a recurring issue, the fix is to fetch all the remote changes before invoking gitversion, and if it's a shallow clone using --unshallow.

The action for me, or anyone who wants to jump in is to detect this issue proactively in GitVersion, try to resolve automatically and if it fails give a good error message which explains the issue and how to resolve.

It is also becoming more of an issue as more build systems do shallow clones and other git optimisations to speed up the builds.

@tofutim

This comment has been minimized.

Copy link
Contributor

tofutim commented May 4, 2017

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.

binarymash added a commit to binarymash/responses that referenced this issue May 12, 2017

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented May 15, 2017

@tofutim: Awesome find! It would be good to have this documented. Would you like to submit a PR that adds this note to the TeamCity build server documentation? An added bonus would be to somehow detect this within GitVersion and as @JakeGinnivan suggests, provide a good error description on what to do to fix the problem.

@Alxandr Alxandr referenced this issue May 26, 2017

Closed

Use GitVersion for version information #6

0 of 1 task complete
@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Jul 11, 2017

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.

@jonnii

This comment has been minimized.

Copy link

jonnii commented Dec 5, 2017

@asbjornu one issue with this setting in teamcity is that it doesn't work with github pull requests as they are not under refs/ but under merge/. =(

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Dec 8, 2017

@jonnii: So TeamCity does not fetch all heads beneath merge/? It will have to fetch the head of the PR being built anyway (regardless of where it is, as long as it matches the VCS branch spec), so I'm not sure all other PR heads are necessary. Why would they be?

@jonnii

This comment has been minimized.

Copy link

jonnii commented Dec 9, 2017

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

@mcwienczek

This comment has been minimized.

Copy link

mcwienczek commented Apr 12, 2018

@asbjornu I don't think it's teamcity 10 issue. We started having issues once we upgraded to 2017. Before, in TC 10 we did not have any problems with running gitversion. The upgrade was definitely the cause.

@brianlocke

This comment has been minimized.

Copy link

brianlocke commented May 22, 2018

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

@ankitvijay

This comment has been minimized.

Copy link

ankitvijay commented Dec 19, 2018

@tofutim you have been a life saver. Can't thank you enough.

@asbjornu

This comment has been minimized.

Copy link
Member

asbjornu commented Dec 19, 2018

As I mentioned teamcity.git.fetchAllHeads back in july 2017 (#912 (comment)) which should fix the issue and no new information has been provided since, I'm closing this.

@asbjornu asbjornu closed this Dec 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.