标签: libgit2

libgit2不会获取更改,但始终是一切

我正在尝试使用libgit2来首先克隆一个裸存储库,然后使用来自github源的更改来更新它.克隆工作正常:

git_repository *_repository
git_clone_bare(&_repository, REPOSITORY_URL, path, &transferProgressCallback, NULL);
git_repository_free(_repository);
Run Code Online (Sandbox Code Playgroud)

但是当我尝试从源libgit2更新存储库时,总是再次下载整个存储库.它只是不提取更改.我正在使用此代码:

git_remote *remote;
git_repository *_repository;

git_repository_open(&_repository, path);
git_remote_load(&remote, _repository, "origin");
git_remote_connect(remote, GIT_DIR_FETCH);
git_remote_download(remote, &transferProgressCallback, NULL);

git_remote_disconnect(remote);
git_remote_update_tips(remote);
git_remote_free(remote);
Run Code Online (Sandbox Code Playgroud)

(我删除了错误处理.)我使用这样的回调来报告进度:

void transferProgressCallback(const git_transfer_progress *stats, void *payload) {
    float receivedMegaBytes = (float)stats->received_bytes/(1024*1024.0);
    float progress = ((float)stats->received_objects / (float)stats->total_objects) * 100.0;
    printf("Loading: %.1f (%.1f)\n", progress, receivedMegaBytes);
}
Run Code Online (Sandbox Code Playgroud)

根据回调,下载了所有内容(与git_clone_bare相同的字节数).我一定是错过了什么或做错了什么,对吧?但我没有看到哪里.我想要的只是代码仅提取更改(即本地不存在的内容).但相反,它不断获取整个存储库.

拜托,这可能是什么问题?非常感谢你提前!

libgit2

2
推荐指数
1
解决办法
901
查看次数

如何在gitattributes中应用语言的diff规则

例如,该行的.gitattributes文件.代码的输出lg2s*.cs diff=csharp

using (var repo = new Repository(@"path\to\lg2s"))
{
    var tree1 = repo.Lookup<Commit>("a845db9").Tree;
    var tree2 = repo.Lookup<Commit>("d677741").Tree;
    var patches = repo.Diff.Compare<Patch>(tree1, tree2);
    foreach (var patch in patches)
    {
        Console.WriteLine(patch.Patch);
    }
}
Run Code Online (Sandbox Code Playgroud)

是(不久)

diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs
@@ -59,8 +59,8 @@ namespace LibGit2Sharp
Run Code Online (Sandbox Code Playgroud)

但输出git bash是(很快)

diff --git a/LibGit2Sharp/RepositoryStatus.cs b/LibGit2Sharp/RepositoryStatus.cs
@@ -59,8 +59,8 @@ internal RepositoryStatus(Repository repo, StatusOptions optio
Run Code Online (Sandbox Code Playgroud)

第二行不一样.

看起来有一个深入的讨论Add .gitattributes support libgit2 /#508,但PR Add APIs for git attributes libgit2 /#516是否合并?

现在支持多少种语言? …

libgit2 libgit2sharp

2
推荐指数
1
解决办法
998
查看次数

使用libgit2连接到私有github存储库

我正在尝试使用libgit2获取私有github存储库.repo属于一个组织,我有读/写权限.该程序是用Objective-C++编写的.我有这个:

- (int)fetchBranches
{
    git_remote *remote = NULL;
    int result = 0;
    if (!(result = git_remote_load(&remote, repo, "origin"))) {
        git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT;
        callbacks.credentials = cred_acquire_cb;
        git_remote_set_callbacks(remote, &callbacks);
        result = git_remote_fetch(remote);
    }
    return result;
}

int cred_acquire_cb(git_cred **out,
                    const char * url,
                    const char * username_from_url,
                    unsigned int allowed_types,
                    void * payload)
{
    return git_cred_ssh_key_new(out, "GITHUBUSERNAME", "/Users/admin/.ssh/id_rsa.pub", "/Users/admin/.ssh/id_rsa", "PASSPHRASE");
}
Run Code Online (Sandbox Code Playgroud)

这会创建凭据,但是当我执行提取时,尝试使用libssh2对会话进行身份验证时会失败.(libgit2/SRC /运输/ ssh.c:302):

rc = libssh2_userauth_publickey_fromfile(
      session, c->username, c->publickey,
      c->privatekey, c->passphrase);
Run Code Online (Sandbox Code Playgroud)

错误是-18,LIBSSH2_ERROR_AUTHENTICATION_FAILED.我已经确认公钥已添加到Github并尝试将其更改为新的公钥.密码也是正确的,用户名是我的github用户名.我也可以通过控制台进行提取.远程配置是:

[remote "origin"]
    url = git@github.com:ORGNAME/REPONAME.git
    fetch = +refs/heads/*:refs/remotes/origin/* …
Run Code Online (Sandbox Code Playgroud)

authentication macos ssh github libgit2

2
推荐指数
1
解决办法
1224
查看次数

如何在d中使用libgit的git_repository_open

我正在尝试在 d 中使用libgit2库。我总是在程序退出时遇到分段错误。当我打开和关闭存储库时,在退出之前不会发生错误。这似乎是垃圾收集器的问题,但手动禁用垃圾收集器(GC.disable();)似乎根本不会影响结果。释放(git_repository_free(repo))似乎也没有效果。

这是一些示例代码:

import std.stdio : writeln;
import std.string : toStringz;

import core.memory : GC;

import deimos.git2.types : git_repository;
import deimos.git2.repository : git_repository_open, git_repository_free;

void main() {
    GC.disable();
    git_repository *repo;
    git_repository_open(&repo, ".".toStringz());
    git_repository_free(repo);
    writeln("END");
}
Run Code Online (Sandbox Code Playgroud)

输出:

$ ./gittest
END
zsh: segmentation fault (core dumped)  ./gittest
Run Code Online (Sandbox Code Playgroud)

版本:

  • libgit2-dev:0.22.1-0ubuntu3
  • libgit2: ~>0.20.1
  • 配音:0.9.23-0
  • dmd-bin:2.067.1-0
  • 库班图:15.04

如果有的话,我做错了什么?如果没有什么可以确定错误的罪魁祸首(d、libgit2 或 libgit2 d 绑定)?

附加说明:我尝试使用 dlibgit 并发现它有令人难以置信的错误,主要是看起来已经过时了。这个问题涉及 libgit2 d 绑定。

d libgit2

2
推荐指数
1
解决办法
485
查看次数

libgit2sharp - Git - 无法推送非快进引用

libgit2sharp生成文件后,我正在使用它们将文件推送到存储库。

using (var repo = new Repository(RepositoryPath))
{
    // Stage the file
    Commands.Stage(repo, "*");

    // Create the committer's signature and commit
    Signature author = new Signature("translator", "example.com", DateTime.Now);
    Signature committer = author;

    // Commit to the repository
    Commit commit = repo.Commit($"Resx files updated {DateTime.Now}", author, committer);

    Remote remote = repo.Network.Remotes["origin"];
    var options = new PushOptions
    {
        CredentialsProvider = (_url, _user, _cred) =>
           new UsernamePasswordCredentials
           {
               Username = _settings.GitUserName,
               Password = _settings.GitPassword
           }
     };
     repo.Network.Push(remote, @"refs/heads/master", options);
 } 
Run Code Online (Sandbox Code Playgroud)

这已经有一段时间了,并且没有问题地推送到存储库,但是我现在收到某些文件的以下错误消息,并且没有发生任何文件的推送。

错误消息(来自服务器日志): …

c# git libgit2 libgit2sharp

2
推荐指数
1
解决办法
5070
查看次数

获取历史而不检出

对于一个项目,我需要知道两个修订之间的所有提交。

通常,只需克隆存储库并检查历史记录即可。我不需要文件实际存在于文件系统中,我只对历史本身感兴趣。
由于大型存储库的性质,克隆它们可能需要一些时间。

有没有一种方法可以在最短的时间内获取历史记录(甚至两个修订之间的历史记录)?是否有可能实际上不检出文件(因为我猜这就是最耗时的时间)。

git libgit2

2
推荐指数
1
解决办法
82
查看次数

如何使用libgit2从git存储库中获取HEAD的最后一次提交?

由于没有使用libgit2进行最后一次提交的复制粘贴示例,我想我应该添加一个.libgit2中的示例广泛使用git_oid_fromstr()...

不要忘记libgit2目前处于全面开发阶段(2013年3月),因此请查看官方文档和源代码,因为每天都会添加新功能:

c c++ libgit2

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

Objective-Git Merge

我正在使用Objective-Git.我无法使用以下方法:

- (GTIndex *)merge:(GTTree *)otherTree ancestor:(GTTree *)ancestorTree error:(NSError **)error
Run Code Online (Sandbox Code Playgroud)

没有返回错误,但返回的索引为空,当它存在时,所有属性都为零.合并操作不会发生,我无法写出树,因为我无法获得尝试合并产生的索引.

有没有人设法使用目标git成功执行合并 - 如何?救命!

        GTBranch *branch1 = branches[0];
        GTCommit *commit1 = [branch1 targetCommitAndReturnError:NULL];
        GTOID *oid1 =  commit1.OID;
        GTTree *tree1 = commit1.tree;

        GTBranch *branch2 = branches[1];
        GTCommit *commit2 = [branch2 targetCommitAndReturnError:NULL];
        GTTree *tree2 = commit2.tree;
        GTOID *oid2 =  commit2.OID;

        GTRepository *repo = branch1.repository;

        NSError *error;
        GTCommit *ancestor = [repo mergeBaseBetweenFirstOID:oid1 secondOID:oid2 error:&error];
        if (error){
            NSLog(@"%@", error.description);
        }
        GTTree *ancTree = ancestor.tree;
        NSError *someError;
        NSLog(@"attempting merge into ""%@"" from ""%@"" with ancestor ""%@""", …
Run Code Online (Sandbox Code Playgroud)

git objective-c git-merge libgit2 objective-git

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

LibGit2Sharp:"太多重定向或身份验证重放"提取失败

这是我用来获取的代码:

public static void GitFetch()
{
    var creds = new UsernamePasswordCredentials()
                {Username = "user",
                 Password = "pass"};
    var fetchOpts = new FetchOptions {Credentials = creds};
    using (repo = new Repository(@"C:\project");)
    {
        repo.Network.Fetch(repo.Network.Remotes["origin"], fetchOpts);
    }
}
Run Code Online (Sandbox Code Playgroud)

但在获取期间失败并出现以下异常:

LibGit2Sharp.LibGit2SharpException: Too many redirects or authentication replays
Result StackTrace:  
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result)
   at LibGit2Sharp.Core.Proxy.git_remote_fetch(RemoteSafeHandle remote, Signature signature, String logMessage)
   at LibGit2Sharp.Network.DoFetch(RemoteSafeHandle remoteHandle, FetchOptions options, Signature signature, String logMessage)
   at LibGit2Sharp.Network.Fetch(Remote remote, FetchOptions options, Signature signature, String logMessage)
Run Code Online (Sandbox Code Playgroud)

我已经验证配置文件具有所需的远程名称,并且git fetch可以从命令行运行.我发现异常起源于libgit2\src\transport\winhttp.c但我无法提出解决方法/解决方案.

libgit2 libgit2sharp

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

使用 libgit2,如何创建一个空的初始提交?

以前我问过如何在 libgit2 中创建一个空提交。这个问题得到了充分的回答,但是当我最初问它时我还不够清楚。

使用 libgit2,如何创建一个空的初始提交?我上一个问题的答案依赖于父提交对象,我不知道如何为空存储库获取该对象。也许可以使用空树对象(可以使用 生成其散列git hash-object -t tree /dev/null)来完成某些事情?

c git libgit2

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

标签 统计

libgit2 ×10

git ×4

libgit2sharp ×3

c ×2

authentication ×1

c# ×1

c++ ×1

d ×1

git-merge ×1

github ×1

macos ×1

objective-c ×1

objective-git ×1

ssh ×1