libgit2推送错误(GIT_ENNOFASTFORWARD)

时间:2013-01-14 06:05:48

标签: ios git libgit2

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

这就是我所做的。

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

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

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

CONFIG:

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

CODE:

-(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();

}

0 个答案:

没有答案