when I use git clone to get a git from the remote, the git_index_entrycount return 0?

Refresh

March 2019

Views

70 time

1

I use git_repository_index to get the index first ,and then I use git_index_entrycount to see how many index items in it , but the result is 0? why? Below is my code, what's wrong with it? 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 answers

2

On order to trigger the checkout as part of the git_clone() process, have you considered using GIT_CHECKOUT_SAFE_CREATE as the checkout_strategy?

Both this commit and the the git_checkout() documentation hint about this.