1

我先用 git_repository_index 获取索引,然后用 git_index_entrycount 看看里面有多少个索引项,结果是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);
}

}

4

1 回答 1

2

为了触发结帐作为git_clone()流程的一部分,您是否考虑过将 GIT_CHECKOUT_SAFE_CREATE其用作checkout_strategy

提交和有关此的git_checkout() 文档提示。

于 2013-01-12T10:58:41.653 回答