【问题标题】:Unable to push to GitLab endpoint LibGit2Sharp无法推送到 GitLab 端点 LibGit2Sharp
【发布时间】:2015-07-16 15:59:41
【问题描述】:

我正在尝试使用 LibGit2Sharp 初始化并将初始提交推送到 GitLab 存储库。

if (!Directory.Exists("D:\\GitRepos\\" + repositoryName))
        {
            Directory.CreateDirectory("D:\\GitRepos\\" + repositoryName);
            File.Create("D:\\GitRepos\\" + repositoryName + "\\README.md").Close();
        }

        Repository.Init("D:\\GitRepos\\" + repositoryName);

        using (var repo = new Repository("D:\\GitRepos\\" + repositoryName))
        {
            repo.Index.Add("README.md");
            Signature author = new Signature("user", "user@user.com", DateTime.Now);
            Signature committer = author;
            repo.Commit("Initial Commit", author, committer);
            repo.Network.Remotes.Add("origin", validRepoHttpsUrl);
            Remote remote = repo.Network.Remotes["origin"];

            var options = new PushOptions
            {
                CredentialsProvider = (_url, _user, _cred) =>
                    new UsernamePasswordCredentials {Username = "validuser", Password = "validpassword"}
            };

            string pushRefSpec = @"refs/heads/master";
            repo.Network.Push(remote, pushRefSpec, options);

        }

}

存储库是在本地创建和初始化的,没有问题。 README 文件被创建并添加到 repo 索引并且提交成功。当我尝试将提交推送到远程端点时,我收到一条错误消息:

"Request failed with status code: 411" 

如果我在推送之前放置一个断点并使用以下命令为 repo 设置 http.postBuffer:

git config http.postBuffer 524288000

推送执行时我收到一个新错误:

Failed to write chunk footer: The connection with the server was terminated abnormally

我能够快速建立一个bitbucket git repo并毫无问题地推送它,似乎这可能是gitlab的问题。

【问题讨论】:

  • 411 是“需要长度”。 GitLab 不支持分块编码吗?您确定 URL 是正确的吗?如果您克隆存储库,您可以推送吗?而不是尝试推送到全新的存储库?
  • (我不太确定如何回答第一个问题。Paging GitLab CEO...)
  • 我们自托管 gitlab 并且工作正常,但我刚刚尝试了 git:gitlab.com 和 gitlab.com 都失败了。发现这个与 http 错误 411 相关的未解决问题:使用凭据 #905 通过 HTTPS 将更改推送到 GitLab 存储库:github.com/libgit2/libgit2sharp/issues/905
  • 不确定你的网络/服务器/nginx配置,但我会wireshark libgit2 vs git。还要查看您的 nginx 日志以了解来自 libgit2 连接的错误。
  • 我唯一要添加的另一件事是,我假设您正在运行更新的 ngnix,而不是出现 chunkin 模块问题(1.3.? google it)。在这些版本中有 .conf 更改来解决这个问题,但我会更新到 1.9.x 版本是可能的

标签: c# git gitlab libgit2sharp


【解决方案1】:

根据 RobertN 的评论,这似乎是 libgit2sharp 的一个已知问题。 https://github.com/libgit2/libgit2sharp/issues/905

我可以通过使用 git CLI 调用处理推送来临时解决这个问题。

        Process p = new Process();
        // Redirect the output stream of the child process.
        p.StartInfo.UseShellExecute = false;
        p.StartInfo.RedirectStandardOutput = true;
        p.StartInfo.WorkingDirectory = "D:\\GitRepos\\" + repositoryName;
        p.StartInfo.FileName = "git.exe";
        p.StartInfo.Arguments = "push -u origin master";
        p.Start();

        string output = p.StandardOutput.ReadToEnd();
        p.WaitForExit();

需要注意的是,当它作为本地系统作为 Windows 服务运行时,调用需要 2-3 分钟才能推送一个小的提交。当我将服务切换为以域用户身份运行时,它是立即的。此外,这仅适用于我在主机上设置了 ssh 和正确的密钥,否则 git 会提示输入用户名和密码。如原始问题所述,我必须使用 SSH URL 而不是 HTTP。

【讨论】:

  • :-) 由于 libgit2/libgit2sharp 和官方 git 版本之间的性能问题,我一直在 Linux 上这样做(瓷器一直保存我的培根)
  • 如果我只需要使用官方 git 版本来推送我仍然会很高兴,在 libgit2sharp 中做其他所有事情都值得我记住。
  • 完全同意,以这种方式处理更容易......但在我的情况下,处理有一个自定义 libgit2 版本硬连线到 EMC VNX 虚拟文件系统,但由于无法重新分配它上面有 GPL,所以我有时必须解决它。在他们编写一个新的基于 San 的 VFS git lib 时,我只是维护它的一个子任务,该库实际上可以出售/发送给客户(他们从未计划过这样做,因为它是仅供内部使用的系统)。
  • @RobertN 这太令人惊讶了。您能否在 github.com/libgit2/libgit2 的问题中写下您在 libgit2 中遇到的问题,以便我们进行调查?
猜你喜欢
  • 1970-01-01
  • 2015-12-25
  • 1970-01-01
  • 2014-05-01
  • 1970-01-01
  • 2013-12-04
  • 2018-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多