visualstudio.com thinks latest libgit2 is old

邮差的信 提交于 2019-12-12 19:08:14

问题


When cloning or fetching from visualstudio.com I get a sideband message that "you're using an older version of Git".

This happens with libgit2 commit f1323d9 that is from January 10.

Is there anything I can do about this and is this anything I should worry about?

It can be replicated with something like

#include <stdio.h>
#include <git2.h>

static int cred_acquire_cb(git_cred **cred, const char *url, 
                           const char *username_from_url,
                           unsigned int allowed_types, void *payload) {
  return git_cred_userpass_plaintext_new(cred, "email@address.com", "token");
}

static int sideband_progress_cb(const char *str, int len, void *payload) {
   printf("%s", str);
   return 0;
}

int main() {
   git_libgit2_init();

   git_clone_options clone_options = GIT_CLONE_OPTIONS_INIT;
   clone_options.fetch_opts.callbacks.credentials = cred_acquire_cb;
   clone_options.fetch_opts.callbacks.sideband_progress = sideband_progress_cb;

   git_repository *repo = NULL;
   const char *url = "https://account.visualstudio.com/project/_git/repo";
   const char *path = "repo";
   int error = git_clone(&repo, url, path, &clone_options);
   if(error < 0) {
      fprintf(stderr, "error = %d, %s\n", error, giterr_last()->message);       
   }

   return 0;
}

回答1:


No - there's nothing to worry about here. VSTS is trying to be helpful by looking at the version of Git that you're running and suggesting that you upgrade if you're running something outdated.

libgit2 has to send a Git version string as part of its user agent, pretending to be Git itself, because some hosting providers[1] are "over enthusiastic" about looking at the user agent[2] and if they don't see a git/ prefix at the start, will assume that you're a web browser and redirect you to their home page.

This is much the same way that every graphical web browser claims to be Mozilla. 😢

In this case, though, VSTS needs to be smart enough to recognize that libgit2-based clients should not follow the same matching rules as Git itself.

There's nothing that you can do to change this behavior in your client. You can change the user agent string that's sent with your requests, but libgit2 will always prefix it with git/2.0 (to save you from those aforementioned hosting providers.) For example, if you:

git_libgit2_opts(GIT_OPT_SET_USER_AGENT, "MyAwesomeGitClient/32.14");

Then the actual user-agent will be sent as:

git/2.0 MyAwesomeGitClient/32.14

But I don't recommend this, since there's no need to make any changes. It's clear that VSTS is incorrect here, and I'll ask the VSTS Git Server team to investigate.


[1] Not Visual Studio Team Services.

[2] I say that this hosting provider is "over enthusiastic", but that's rather polite. There are specific endpoints that Git hits when it fetches and pushes, and they shouldn't need to be protected by a user agent match. This sort of behavior is the kind of thing that gives us endless hack upon endless hack, like all libgit2 clients pretending to be git/2.0 and Safari pretending to be Mozilla.

We should do better.



来源:https://stackoverflow.com/questions/48296823/visualstudio-com-thinks-latest-libgit2-is-old

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!