I am seeing this about 1 out 5 builds - pulled code about 3 days ago.
09:55:04 INFO [04/07/17 13:55:04:00] No local branch pointing at the commit '2b1dc29648bd4225b34a281cd0626df2f70ff596'. Fake branch needs to be created.
09:55:04 INFO [04/07/17 13:55:04:00] Fetching remote refs to see if there is a pull request ref
09:55:04 INFO [04/07/17 13:55:04:13] End: Normalizing git directory for branch '' (Took: 2,791.89ms)
09:55:04 ERROR [04/07/17 13:55:04:17] An unexpected error occurred:
09:55:04 LibGit2Sharp.LibGit2SharpException: this remote has never connected
09:55:04 at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
09:55:04 at LibGit2Sharp.Core.Proxy.git_remote_ls(Repository repository, RemoteHandle remote)
09:55:04 at LibGit2Sharp.Network.ListReferencesInternal(String url, CredentialsHandler credentialsProvider)
09:55:04 at GitTools.Git.GitRepositoryHelper.GetRemoteTipsForAnonymousUser(Repository repo, Remote remote)
09:55:04 at GitTools.Git.GitRepositoryHelper.CreateFakeBranchPointingAtThePullRequestTip(Repository repo, AuthenticationInfo authentication)
09:55:04 at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
09:55:04 at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
09:55:04 at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache)
09:55:04 at GitVersion.SpecifiedArgumentRunner.Run(Arguments arguments, IFileSystem fileSystem)
09:55:04 at GitVersion.Program.VerifyArgumentsAndRun()
I tracked down the cause to a detached head. This case was random for some reason - In Jenkins, the Bitbucket plugin would sometimes in into this state. I now added code to check for detached head and force a full clone.
Hm. If this is something we can detect in GitVersion, it would be good to give a better error message than what LibGit2Sharp is giving here. I'm glad you figured it out, though.
Most helpful comment
Hm. If this is something we can detect in GitVersion, it would be good to give a better error message than what LibGit2Sharp is giving here. I'm glad you figured it out, though.