c - Visualstudio.com 认为最新的 libgit2 已过时

标签 c libgit2

当从 Visualstudio.com 克隆或获取时,我收到一条边带消息:“您正在使用旧版本的 Git”。

这发生在 libgit2 提交 f1323d9 上那是从 1 月 10 日开始。

对此我能做些什么吗?这是我应该担心的事情吗?

它可以用类似的东西复制

#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, "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5f3a323e36331f3e3b3b2d3a2c2c713c3032" rel="noreferrer noopener nofollow">[email protected]</a>", "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;
}

最佳答案

不 - 这里没有什么可担心的。 VSTS 试图通过查看您正在运行的 Git 版本来提供帮助,并建议您在运行过时的版本时进行升级。

libgit2 has to send a Git version string as part of its user agent ,假装是 Git 本身,因为一些托管提供商[1]对查看用户代理“过于热情”[2],并且如果他们在开头没有看到 git/ 前缀,会假设您是网络浏览器并将您重定向到他们的主页。

这与每个图形 Web 浏览器都声称是 Mozilla 的方式大致相同。 😢

但在这种情况下,VSTS 需要足够聪明,能够识别基于 libgit2 的客户端不应遵循与 Git 本身相同的匹配规则。

您无法改变客户端的这种行为。您可以更改与您的请求一起发送的用户代理字符串,但 libgit2 始终会在其前面添加 git/2.0 前缀(以使您免受上述托管提供商的影响。)例如,如果您:

git_libgit2_opts(GIT_OPT_SET_USER_AGENT, "MyAwesomeGitClient/32.14");

然后实际的用户代理将发送为:

git/2.0 MyAwesomeGitClient/32.14

但我不建议这样做,因为不需要进行任何更改。很明显,VSTS 在这里是不正确的,我将要求 VSTS Git Server 团队进行调查。


[1] 不是 Visual Studio Team Services。

[2] 我说这个托管提供商“过于热情”,但这是相当礼貌的。 Git 在获取和推送时会遇到特定的端点,并且它们不需要受到用户代理匹配的保护。这种行为会给我们带来无尽的黑客攻击,就像所有 libgit2 客户端假装是 git/2.0 和 Safari 假装是 Mozilla 一样。

我们应该做得更好。

关于c - Visualstudio.com 认为最新的 libgit2 已过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48296823/

相关文章:

c - Flex 和 Bison 计算器(如果出现问题)

git - libgit2 引发了错误。类别 = Os(错误)

c# - GIT 智能 HTTP 协议(protocol)的服务端和客户端有哪些细节区别

c - 功能参数差异 : double pointer VS 2D array

c - 将字符串转换为代码?

c - C中双向链表的初始化,指针

git - 原始 Git 和 libgit2 之间共享哪些代码?

c - 不重复的排列 C

c - 使用 libgit2 进行 Git checkout

Git2go - pull && merge