当我使用git clone从远程获取git时,git_index_entrycount返回0?

时间:2013-01-12 10:01:00

标签: ios libgit2

我首先使用git_repository_index获取索引,然后使用git_index_entrycount查看其中有多少索引项,但结果为0?为什么?下面是我的代码,它有什么问题? THX

(void)viewDidLoad
{
[super viewDidLoad];
git_repository *repo;
progress_data pd = {{0}};
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [array objectAtIndex:0];

git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
checkout_opts.progress_cb = checkout_progress;
checkout_opts.progress_payload = &pd;
clone_opts.checkout_opts = checkout_opts;
clone_opts.fetch_progress_cb = &fetch_progress;
clone_opts.fetch_progress_payload = &pd;
clone_opts.cred_acquire_cb = cred_acquire;
NSString *pp = [docPath stringByAppendingPathComponent:@"/abc" ];
const char * a =[pp UTF8String];   

int res =  git_clone(&repo, "http://path/.git", a, &clone_opts);
NSLog(@"Get it. res:%d\n path:%s", res, a);
//get index
int ret;
git_index* index;
ret = git_repository_index(&index, repo);
NSLog(@"git_repository_index ret:%d", ret);
int count = git_index_entrycount(index);
if(count != 0)
{
    NSLog(@"index number:%d", count);
}
else
{
    NSLog(@"count == 0");
}

const git_error *err = giterr_last();
if(err == NULL)
{
    NSLog(@"NULL");
}
else
{
    NSLog(@"err:%s", err->message);
}

}

1 个答案:

答案 0 :(得分:2)

为了在git_clone()进程中触发结帐,您是否考虑过使用 GIT_CHECKOUT_SAFE_CREATE作为checkout_strategy

commit 以及git_checkout() documentation 都暗示了这一点。