Skip to content

nofetch not respected for PR builds #1199

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

Closed
Trass3r opened this issue Apr 7, 2017 · 8 comments
Closed

nofetch not respected for PR builds #1199

Trass3r opened this issue Apr 7, 2017 · 8 comments

Comments

@Trass3r
Copy link

Trass3r commented Apr 7, 2017

One remote found (origin -> ...
Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
HEAD is detached and points at commit '1df...'.
Local Refs: refs/pull/1/merge (1df...)
No local branch pointing at the commit '1df...'. Fake branch needs to be created.
Fetching remote refs to see if there is a pull request ref
End: Normalizing git directory for branch '' (Took: 629.06ms)
An unexpected error occurred:
LibGit2Sharp.LibGit2SharpException: this remote has never connected
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in c:\Git\LibGit2Sharp-2\LibGit2Sharp\Core\Ensure.cs:line 154
   at LibGit2Sharp.Core.Proxy.git_remote_ls(Repository repository, RemoteHandle remote) in c:\Git\LibGit2Sharp-2\LibGit2Sharp\Core\Proxy.cs:line 2313
   at LibGit2Sharp.Network.ListReferencesInternal(String url, CredentialsHandler credentialsProvider) in c:\Git\LibGit2Sharp-2\LibGit2Sharp\Network.cs:line 130
   at GitTools.Git.GitRepositoryHelper.GetRemoteTipsForAnonymousUser(Repository repo, Remote remote)
   at GitTools.Git.GitRepositoryHelper.CreateFakeBranchPointingAtThePullRequestTip(Repository repo, AuthenticationInfo authentication)
   at GitTools.Git.GitRepositoryHelper.NormalizeGitDirectory(String gitDirectory, AuthenticationInfo authentication, Boolean noFetch, String currentBranch)
   at GitVersion.GitPreparer.Initialise(Boolean normaliseGitDirectory, String currentBranch)
   at GitVersion.ExecuteCore.ExecuteGitVersion
@asbjornu
Copy link
Member

asbjornu commented Apr 19, 2017

  1. Which version of GitVersion are you using?
  2. Are you using GitVersionTask, gitversion.exe or something else?
  3. What build server is this?
  4. How have you configured or passed nofetch to GitVersion?
  5. Is your build server doing a shallow checkout? Can you try to do git fetch --unshallow as a step before executing GitVersion to ensure that the entire repository is available to GitVersion?

@Trass3r
Copy link
Author

Trass3r commented Apr 19, 2017

  1. 4.0.0-beta.11+1258.Branch.master.Sha.cc28b2dbff86
  2. Executing: packages/Tools/GitVersion.CommandLine/tools/GitVersion.exe" -updateassemblyinfo "src/GlobalAssemblyInfo.cs" -nofetch
  3. TeamCity agent checkout. git.exe could only fetch with the access token. I'd like gitversion to work "offline" without another fetch, after all it seems to have a "name" for the build: Local Refs: refs/pull/1/merge.
  4. cmdline
  5. no

@asbjornu
Copy link
Member

asbjornu commented Apr 19, 2017

@Trass3r: Thanks for the information. Have you tried git fetch --unshallow?

@Trass3r
Copy link
Author

Trass3r commented Jun 8, 2017

Maybe it's related to TC's use mirrors setting: "When this option is enabled, TeamCity clones the repository under the agent's system\git directory and uses the mirror as an alternate repository when updating the checkout directory for the build. As a result, this speeds-up clean checkout (because only the working directory is cleaned), and saves disk space (as there is only one clone of the given git repository on an agent)."

But still, it does find the local ref but doesn't use it:

HEAD is detached and points at commit '8fb46da'.
Local Refs:
refs/pull/1/merge (8fb46da)
No local branch pointing at the commit '8fb46da'. Fake branch needs to be created.
Fetching remote refs to see if there is a pull request ref

@Trass3r
Copy link
Author

Trass3r commented Jun 8, 2017

Though there is a .git folder and fatal: fetch --unshallow on a complete repository does not make sense

@asbjornu
Copy link
Member

Can you please take a look at #912 (comment) and see if setting teamcity.git.fetchAllHeads to true fixes your problem? Please reopen the issue if the problem persists.

@xero-jackieweng
Copy link

xero-jackieweng commented Apr 8, 2021

I'm getting this exact problem, and teamcity.git.fetchAllHeads doesn't not actually help.

Setup:

  • TC: 2020.2.2
  • Repo: GitHub enterprise (brand new)
  • GitVersion image: gittools/gitversion:5.6.9-alpine.3.12-x64-5.0

Error without param("teamcity.git.fetchAllHeads", "true")

INFO [04/08/21 22:28:32:75] Begin: Normalizing git directory for branch ''
  INFO [04/08/21 22:28:32:78] One remote found (origin -> 'https://github.dev.xero.com/Xero/teamcity-dsl-test').
  INFO [04/08/21 22:28:32:78] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/08/21 22:28:32:79] HEAD is detached and points at commit 'af85385b578d3b4246548eca555cdfd9b4461ba3'.
  INFO [04/08/21 22:28:32:79] Local Refs:
refs/pull/1/head (af85385b578d3b4246548eca555cdfd9b4461ba3)
  INFO [04/08/21 22:28:32:79] No local branch pointing at the commit 'af85385b578d3b4246548eca555cdfd9b4461ba3'. Fake branch needs to be created.
  INFO [04/08/21 22:28:32:79] Fetching remote refs to see if there is a pull request ref
  INFO [04/08/21 22:28:33:01] End: Normalizing git directory for branch '' (Took: 253.80ms)
  INFO [04/08/21 22:28:33:02] Attempting to show the current git graph (please include in issue): 
  INFO [04/08/21 22:28:33:02] Showing max of 100 commits
  ERROR [04/08/21 22:28:33:02] An unexpected error occurred:
LibGit2Sharp.LibGit2SharpException: this remote has never connected
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_ls(Repository repository, RemoteHandle remote)
   at LibGit2Sharp.Network.ListReferencesInternal(String url, CredentialsHandler credentialsProvider)
   at LibGit2Sharp.Network.ListReferences(Remote remote)
   at GitVersion.Extensions.RepositoryExtensions.GetRemoteTipsForAnonymousUser(IRepository repository, Remote remote) in D:\a\1\s\src\GitVersionCore\Extensions\RepositoryExtensions.cs:line 223
   at GitVersion.Extensions.RepositoryExtensions.CreateFakeBranchPointingAtThePullRequestTip(IGitRepository repo, ILog log, AuthenticationInfo authentication) in D:\a\1\s\src\GitVersionCore\Extensions\RepositoryExtensions.cs:line 106
   at GitVersion.GitPreparer.NormalizeGitDirectory(String gitDirectory, Boolean noFetch, String currentBranch, Boolean isDynamicRepository) in D:\a\1\s\src\GitVersionCore\Core\GitPreparer.cs:line 297
   at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, String gitDirectory, Boolean isDynamicRepository) in D:\a\1\s\src\GitVersionCore\Core\GitPreparer.cs:line 141
   at GitVersion.GitPreparer.PrepareInternal(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) in D:\a\1\s\src\GitVersionCore\Core\GitPreparer.cs:line 66
   at GitVersion.GitPreparer.Prepare() in D:\a\1\s\src\GitVersionCore\Core\GitPreparer.cs:line 47
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\1\s\src\GitVersionCore\Core\GitVersionCalculateTool.cs:line 43
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\1\s\src\GitVersionExe\GitVersionExecutor.cs:line 59
  INFO [04/08/21 22:28:33:04] * af85385 7 minutes ago  (HEAD, refs/pull/1/head)
* 83ae817 25 minutes ago 
* 56496d0 25 minutes ago 
* 01ea255 76 minutes ago 
* aeadf63 2 hours ago 
* 8ecbef0 2 hours ago 

Error with param("teamcity.git.fetchAllHeads", "true")

INFO [04/08/21 22:59:32:75] Begin: Normalizing git directory for branch ''
  INFO [04/08/21 22:59:32:78] One remote found (origin -> 'https://github.dev.xero.com/Xero/teamcity-dsl-test').
  INFO [04/08/21 22:59:32:78] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
  INFO [04/08/21 22:59:32:79] Skipping update of 'refs/remotes/origin/master' as it already matches the remote ref.
  INFO [04/08/21 22:59:32:80] HEAD is detached and points at commit '73813e3ce36b7e835b1897bf629913bc5159167d'.
  INFO [04/08/21 22:59:32:80] Local Refs:
refs/heads/master (52a0ddb55b89b47987be13569c9ec32fe792b6b8)
refs/pull/1/head (73813e3ce36b7e835b1897bf629913bc5159167d)
refs/remotes/origin/master (52a0ddb55b89b47987be13569c9ec32fe792b6b8)
  INFO [04/08/21 22:59:32:80] No local branch pointing at the commit '73813e3ce36b7e835b1897bf629913bc5159167d'. Fake branch needs to be created.
  INFO [04/08/21 22:59:32:80] Fetching remote refs to see if there is a pull request ref
  INFO [04/08/21 22:59:33:01] End: Normalizing git directory for branch '' (Took: 261.15ms)
  ERROR [04/08/21 22:59:33:03] An unexpected error occurred:
LibGit2Sharp.LibGit2SharpException: this remote has never connected
   at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_ls(Repository repository, RemoteHandle remote)
   at LibGit2Sharp.Network.ListReferencesInternal(String url, CredentialsHandler credentialsProvider)
   at LibGit2Sharp.Network.ListReferences(Remote remote)
   at GitVersion.GitRepository.<>c__DisplayClass30_0.<CreateBranchForPullRequestBranch>b__0() in D:\a\1\s\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 107
   at GitVersion.RepositoryExtensions.RunSafe(Action operation) in D:\a\1\s\src\GitVersion.LibGit2Sharp\RepositoryExtensions.cs:line 16
   at GitVersion.GitRepository.CreateBranchForPullRequestBranch(AuthenticationInfo auth) in D:\a\1\s\src\GitVersion.LibGit2Sharp\Git\GitRepository.cs:line 100
   at GitVersion.GitPreparer.<>c__DisplayClass17_0.<NormalizeGitDirectory>b__3() in D:\a\1\s\src\GitVersion.Core\Core\GitPreparer.cs:line 260
   at GitVersion.Helpers.RetryAction`1.<>c__DisplayClass1_0.<Execute>b__0() in D:\a\1\s\src\GitVersion.Core\Helpers\RetryAction.cs:line 20
   at Polly.Policy`1.<>c__DisplayClass11_0.<Execute>b__0(Context ctx, CancellationToken ct)
   at Polly.Retry.RetryEngine.Implementation[TResult](Func`3 action, Context context, CancellationToken cancellationToken, ExceptionPredicates shouldRetryExceptionPredicates, ResultPredicates`1 shouldRetryResultPredicates, Action`4 onRetry, Int32 permittedRetryCount, IEnumerable`1 sleepDurationsEnumerable, Func`4 sleepDurationProvider)
   at Polly.Retry.RetryPolicy`1.Implementation(Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy`1.Execute(Func`3 action, Context context, CancellationToken cancellationToken)
   at Polly.Policy`1.Execute(Func`1 action)
   at GitVersion.Helpers.RetryAction`2.Execute(Func`1 operation) in D:\a\1\s\src\GitVersion.Core\Helpers\RetryAction.cs:line 42
   at GitVersion.Helpers.RetryAction`1.Execute(Action operation) in D:\a\1\s\src\GitVersion.Core\Helpers\RetryAction.cs:line 18
   at GitVersion.GitPreparer.NormalizeGitDirectory(Boolean noFetch, String currentBranchName, Boolean isDynamicRepository) in D:\a\1\s\src\GitVersion.Core\Core\GitPreparer.cs:line 260
   at GitVersion.GitPreparer.NormalizeGitDirectory(String targetBranch, Boolean isDynamicRepository) in D:\a\1\s\src\GitVersion.Core\Core\GitPreparer.cs:line 147
   at GitVersion.GitPreparer.PrepareInternal(Boolean normalizeGitDirectory, String currentBranch, Boolean shouldCleanUpRemotes) in D:\a\1\s\src\GitVersion.Core\Core\GitPreparer.cs:line 77
   at GitVersion.GitPreparer.Prepare() in D:\a\1\s\src\GitVersion.Core\Core\GitPreparer.cs:line 59
   at GitVersion.GitVersionCalculateTool.CalculateVersionVariables() in D:\a\1\s\src\GitVersion.Core\Core\GitVersionCalculateTool.cs:line 43
   at GitVersion.GitVersionExecutor.RunGitVersionTool(GitVersionOptions gitVersionOptions) in D:\a\1\s\src\GitVersion.App\GitVersionExecutor.cs:line 61
  INFO [04/08/21 22:59:33:03] Attempting to show the current git graph (please include in issue): 
  INFO [04/08/21 22:59:33:03] Showing max of 100 commits
  INFO [04/08/21 22:59:33:04] * 73813e3 2 minutes ago  (HEAD, refs/pull/1/head)
* 5bf0e66 14 minutes ago 
* 52a0ddb 14 minutes ago  (origin/master, master)
* 83ae817 56 minutes ago 
* 56496d0 56 minutes ago 
* 01ea255 2 hours ago 
* aeadf63 2 hours ago 
* 8ecbef0 2 hours ago 

@xero-jackieweng
Copy link

xero-jackieweng commented Apr 9, 2021

Fixed by supplying username and password to GitVersion command, i.e.

/tools/dotnet-gitversion /output buildserver /nofetch /u %github.user% /p %github.token%

param("teamcity.git.fetchAllHeads", "true") is actually not required

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

No branches or pull requests

3 participants