标签: libgit2sharp

使用VS 2015 Update 3克隆远程存储库时遇到错误(TFS 2015 Update 3)

我最近在客户端升级到VS 2015(更新3),在服务器端升级到TFS 2015(更新3).Git操作工作了一段时间,然后我在尝试克隆git repo时开始出现以下错误:

Error encountered while cloning the remote repository: An error occurred while sending the request.

Inner Exception:
    The remote server returned an error: (401) Unauthorized.

    Inner Exception:
        No credentials are available in the security package
Run Code Online (Sandbox Code Playgroud)

但是我可以在浏览器中导航到repo而没有任何问题.然后,我想这可能是由于我的客户端设置.我尝试删除VS缓存以及TFS缓存.没有任何效果.当我使用Fiddler时,它应该遵循以下信息:

它揭示了以下信息:

Request 1:
GET https://myhost/tfs/transact/Transact/_git/MY-REPO/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.0 (libgit2) Team Foundation (devenv.exe, 14.102.25521.0, Enterprise, SKU:37)
Host: myhost
Accept-Encoding: gzip
Connection: Keep-Alive

Response 1:
HTTP/1.1 401 Unauthorized
...
Request 2:
GET https://myhost/tfs/transact/Transact/_git/MY-REPO/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.0 (libgit2) Team Foundation (devenv.exe, 14.102.25521.0, Enterprise, SKU:37) …
Run Code Online (Sandbox Code Playgroud)

git tfs libgit2 libgit2sharp azure-devops

5
推荐指数
1
解决办法
9515
查看次数

无法加载DLL'git2.dll'找不到指定的模块

我正在尝试在web项目中使用libgit2sharp.问题是libgit2sharp的解决方案适用于VS2010而我正在使用VS2008.所以我不得不创建一个新的解决方案并修改代码而不使用默认参数.这不是问题,除了我尝试使用已编译的libgit2sharp DLL时,我在标题中列出了异常.

我已尝试在git2.dll中链接,但这没有帮助.将git2.dll复制到Web项目中也没有帮助.

编辑:问题是在LibGit2Sharp问题跟踪器上处理的:https://github.com/libgit2/libgit2sharp/issues/39

c# git visual-studio-2008 libgit2 libgit2sharp

4
推荐指数
1
解决办法
3573
查看次数

在LibGit2Sharp中找出提交所属的分支?

我正在循环提交LibGit2Sharp:

Repository repo = new Repository("Z:/www/gg");

foreach (LibGit2Sharp.Commit commit in repo.Commits)
{
    ...
}
Run Code Online (Sandbox Code Playgroud)

我可以检索像Author和的属性Message,但我没有看到它属于哪个分支?理想情况下,我希望有一个指向分支对象的指针,但在这种情况下,即使名称也没问题.

这是调试器显示的内容:

在此输入图像描述

这就是我要找的东西:

在此输入图像描述

TortoiseGit显示最相关分支名称的行为:

在此输入图像描述

示例存储库:https://docs.google.com/open?id = 0B-3-X85VysdNcmZIaGVTSDZSenVGbTJxYlI2SUlsZw

c# git libgit2 libgit2sharp

4
推荐指数
1
解决办法
2906
查看次数

4
推荐指数
1
解决办法
2143
查看次数

如何使用libgit2sharp忽略合并提交?

我需要在没有Git完成的自动合并提交的情况下获取提交列表.如何使用libgit2sharp包完成?

libgit2 libgit2sharp

4
推荐指数
1
解决办法
461
查看次数

使用 LibGit2Sharp 克隆给定分支

我想使用 LibGit2Sharp 将给定分支克隆到本地存储库。

 var repoPath = LibGit2Sharp.Repository.Clone("https://something", localpath, cloneOptions);

 using (var repo = new LibGit2Sharp.Repository(repoPath))
 {
     var branches = repo.Branches.GetEnumerator();
 }
Run Code Online (Sandbox Code Playgroud)

使用 repo.Branches.GetEnumerator() 我可以看到每个远程分支,但是使用 Clone 命令我只能从 GitHub 克隆 master 分支?我如何克隆“testBranch”或其他东西?

实际上,默认情况下,Clone()它负责在本地检索所有分支的所有提交。默认情况下,只有远程 HEAD 分支(通常origin/master)会获取自动创建的本地分支副本,然后将其检出。

因此,一旦执行克隆,您所要做的就是从您想要执行此操作的远程分支创建一个本地分支,并检查这个新创建的分支。

例如,假设您对分支感兴趣my-feature-branch并且您的远程名称为origin

Branch remoteBranch = repo.Branches["origin/my-feature-branch"];

Branch newLocalBranch = repo.CreateBranch("my-feature-branch");

// Make the local branch track the upstream one
repo.Branches.Update(newLocalBranch ,
     b => b.TrackedBranch = remoteBranch.CanonicalName);

Branch trackingBranch = repo.Branches["my-feature-branch"];

repo.Checkout(trackingBranch);
Run Code Online (Sandbox Code Playgroud)

FWIW,有一个待处理的拉取请求,允许用户明确指定希望查看签出的分支。

编辑

我根据您的建议更新了我的代码,但它仍然无法正常工作。我的本地存储库的内容与trackingBranch不相等,它仍然代表master分支的内容。

var remoteBranch = …
Run Code Online (Sandbox Code Playgroud)

git libgit2sharp

4
推荐指数
1
解决办法
4529
查看次数

LibGit2Sharp获取自{Hash}以来的所有提交

是否可以使用LibGit2Sharp获取指定提交后的所有提交?

我试过以下......但它不起作用:

using ( var repo = new Repository( repositoryDirectory ) )
{
    //Create commit filter.
    var filter = new CommitFilter
    {
        SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse,
        Since = repo.Refs
    };

    /*Not Working
    if (shaHashOfCommit.IsNotEmpty())
        filter.Since = shaHashOfCommit;
    */

    var commits = repo.Commits.QueryBy( filter );
}
Run Code Online (Sandbox Code Playgroud)

c# git logging commit libgit2sharp

4
推荐指数
1
解决办法
1654
查看次数

Visual Studio可扩展性:从团队资源管理器的Git Commit Details页面获取Git存储库的路径

我正在将Git集成添加到我的Visual Studio扩展程序Diff All Files,它允许快速区分(即比较)Team Explorer窗口中的所有文件与先前版本.我使用Git Changes页面(在团队资源管理器中),因为当我获得Microsoft.TeamFoundation.Git.Controls.Extensibility.IChangesExt服务时,其IncludedChanges属性中的文件包含磁盘上的完整文件路径.但是,在使用Git Commit Details页面时,我得到了Microsoft.TeamFoundation.Git.Controls.Extensibility.ICommitDetailsExt服务,其Changes属性仅包含相对于git分支的文件路径.

我正在使用LibGit2Sharp库与Git存储进行交互,并且能够访问git存储库LibGit2Sharp需要存储库中文件的路径.由于ICommitDetailsExt Changes属性仅包含相对于git repo的文件路径,因此我不知道如何获取Git repo的路径(因此我可以检索要比较的文件的先前版本).

起初我以为我可以使用DTE对象访问解决方案文件的路径,但是意识到可以在没有解决方案本身打开的情况下查看挂起的更改以及之前对团队资源管理器的Git仓库的提交,以便赢得不行.

那么我如何知道Git Commit Details页面显示的提交来自哪些?ICommitDetailsExt服务上的其他任何属性似乎都没有我所拥有的存储库信息(即repo中文件的完整文件路径).是否有一种不同的服务可以为Git提供商提供信息?

我也在MSDN论坛上发布了这个问题,希望微软可以提供答案.

提前致谢.

git visual-studio-extensions libgit2sharp

4
推荐指数
1
解决办法
425
查看次数

LibGit2Sharp - 暂存和提交文件的最佳方式

我正在尝试编写一个基本的 C# GIT 函数,用于提交本地工作目录并将其推送到其主存储库。这是我第一次尝试使用 GIT,我仍在尝试了解一些基础知识。

这是我的代码。它不是很复杂,它需要做的就是确保存储库随我的工作目录中的任何更改进行更新。它有效,但有一个警告,如下所述

public void Sync()
{
    using (var repo = new Repository(@"C:\Temp\Git\test"))
    {
        repo.Stage("*");
        repo.Commit("This is my comment");

        Remote remote = repo.Network.Remotes["origin"];
        var options = new PushOptions();

        options.CredentialsProvider = new CredentialsHandler(
        (url, usernameFromUrl, types) =>
            new UsernamePasswordCredentials()
            {
                Username = "myusername",
                Password = "mypassword"
            });

        var pushRefSpec = @"refs/heads/master";
        repo.Network.Push(remote, pushRefSpec, options, null, "push done...");

    }
}
Run Code Online (Sandbox Code Playgroud)

我面临的问题是这样的。如果我添加或修改任何文件,那么它们会在存储库中相应更新。但是,如果没有需要提交的文件,则会引发以下异常:

No changes; nothing to commit
Run Code Online (Sandbox Code Playgroud)

我希望能够做的是在尝试提交操作之前确定是否需要提交文件,因此如果不需要执行任何操作,则能够正常退出。IE 的内容大致如下:

if (there are files to commit)
{
    repo.Commit("This is my comment"); …
Run Code Online (Sandbox Code Playgroud)

c# git libgit2sharp

4
推荐指数
1
解决办法
3599
查看次数

使用 LibGit2Sharp 查找 sha 提交的正确方法

存储库有几种类型的提交:

  1. 作为分支头的提交
  2. 作为标签引用的提交
  3. 第 1、2 和 3 点提交的父级。

如何正确查找 SHA 编号的提交?

我当前的解决方案:

return (Commit)repo.ObjectDatabase
  .First(o =>
    o.GetType() == typeof(Commit) &&
    o.Sha.Equals(shortSha, StringComparison.InvariantCultureIgnoreCase));
Run Code Online (Sandbox Code Playgroud)

我当前的解决方案迭代所有 git 对象,并且搜索需要一段时间。

我想这里一定有更好的方法。

c# git libgit2sharp

4
推荐指数
1
解决办法
968
查看次数