1

当我使用 libgit2 推送到远程存储库时出现问题。它返回GIT_ENNOFASTFORWARD错误,但我只是从远程存储库克隆它,没有人推送它。此时本地和远程的提交对象应该相同。为什么???

这是我所做的。

  • 从远程克隆一个 git,并更改一个文件的内容。

  • 将更改推送到远程 git 存储库。

  • 错误:git_push_finish 返回 -11,没有错误信息。(GIT_ENNOFASTFORWARD = -11)

配置:

[remote "origin"]
    url = http://path/git/share.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

代码:

-(IBAction)push:(id)sender {
    git_repository *repo = NULL;
    const git_error *err;
    int ret = -1;
    NSArray *str = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docPath = [str objectAtIndex:0];
    NSString *localPath = [docPath stringByAppendingPathComponent:@"abc/.git"];
    NSLog(@"localPath:%@", localPath);

    ret = git_repository_open(&repo, [localPath UTF8String]);
    NSLog(@"git_repository_open ret:%d",ret);
    err = giterr_last();

    char *remote_url = "http://path/git/share.git";
    git_remote *remote = NULL;
    bool cred_acquire_called = false;
    ret = git_remote_load(&remote, repo, "origin");
    NSLog(@"git_remote_load ret:%d", ret);

    git_remote_set_cred_acquire_cb(remote, cred_acquire_cb, &cred_acquire_called);
    ret = git_remote_connect(remote, GIT_DIRECTION_PUSH);
    NSLog(@"git_remote_connect ret:%d cred_acquire_called:%d", ret, cred_acquire_called);

    git_push *push;
    ret = git_push_new(&push, remote);
    NSLog(@"git_push_new ret:%d", ret);

    char* refspec = "refs/heads/master:refs/heads/master";
    ret = git_push_add_refspec(push, refspec);
    NSLog(@"git_push_add_refspec ret:%d", ret);

    ret = git_push_finish(push);
    NSLog(@"git_push_finish ret:%d", ret);

    ret = git_push_unpack_ok(push);
    NSLog(@"git_push_unpack_ok ret:%d", ret);
    err = giterr_last();

}
4

0 回答 0