我阅读了fetch.c并尝试更新本地存储库中的内容(就像“git fetch”),但 git_remote_connect 返回 -1。
err:Unexpected HTTP status code: 401
连接到遥控器时在哪里设置凭据?代码有什么问题??谢谢。
(IBAction)Fetch:(id)sender {
git_remote *remote = NULL;
const git_error *err = NULL;
int ret = -1;
bool invoked = false;
git_repository *repo = NULL;
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();
if(err == NULL)
{
NSLog(@"NULL");
}
else
{
NSLog(@"err:%s", err->message);
}
ret = git_remote_load(&remote, repo, "origin");
NSLog(@"git_remote_load ret:%d", ret);
err = giterr_last();
if(err == NULL)
{
NSLog(@"No error");
}
else
{
NSLog(@"err:%s", err->message);
return;
}
ret = git_remote_load(&remote, repo, "origin");
NSLog(@"git_remote_load ret:%d", ret);
ret = git_remote_connect(remote, GIT_DIRECTION_FETCH);
NSLog(@"git_remote_connect ret:%d", ret);
err = giterr_last();
if(err == NULL)
{
NSLog(@"No error");
}
else
{
NSLog(@"err:%s", err->message);
return;
}
ret = git_remote_download(remote, &transferProgressCallback, &invoked);
NSLog(@"git_remote_download ret:%d", ret);
err = giterr_last();
if(err == NULL)
{
NSLog(@"No error");
}
else
{
NSLog(@"err:%s", err->message);
return;
}
ret = git_remote_update_tips(remote);
NSLog(@"git_remote_update_tips ret:%d", ret);
err = giterr_last();
if(err == NULL)
{
NSLog(@"No error");
}
else
{
NSLog(@"err:%s", err->message);
return;
}
}
这是远程配置
[remote "origin"]
url = http://remote_path/git/share.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master