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

我使用git_repository_index首先得到索引,然后我使用git_index_entrycount看看有多less索引项,但结果是0? 为什么? 下面是我的代码,它有什么问题? 谢谢

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

}

为了触发checkout作为git_clone()过程的一部分,是否考虑使用GIT_CHECKOUT_SAFE_CREATE作为checkout_strategy

这个提交git_checkout() 文档暗示了这一点。