libgit2 / objective-git

Objective-C bindings to libgit2
MIT License
1.16k stars 280 forks source link

authentication required but no callback set #634

Closed remirobert closed 6 years ago

remirobert commented 7 years ago

I got that error authentication required but no callback set from the libgit2, when I tried to push a new branch. I can successfully clone the repo, but impossible to push.

Here some snippets :

+ (GTCredentialProvider *)credential:(NSURL *)url {
    __block GTCredentialProvider *provider = nil;
    provider = [[GTCredentialProvider alloc] init];

    provider = [GTCredentialProvider providerWithBlock:^GTCredential *(GTCredentialType type, NSString *URL, NSString *credUserName) {
        GTCredential *cred = nil;
        NSError* error = nil;

        NSURL *sshPublic = [url URLByAppendingPathComponent:@"id_rsa.pub"];
        NSURL *sshPrivate = [url URLByAppendingPathComponent:@"id_rsa"];

        cred = [GTCredential credentialWithUserName:@"git"
                                       publicKeyURL:sshPublic
                                      privateKeyURL:sshPrivate
                                         passphrase:nil
                                              error:&error];

        if (error) {
            NSLog(@"credential error : %@", error.localizedDescription);
        }
        return cred;
    }];
    return provider;
}

//Creating the new branch, and try to push it.
GTBranch *branch = [repo createBranchNamed:@"branch-1" fromOID:head.OID message:nil error:&error];

GTRemote *remote = [GTRemote remoteWithName:@"origin" inRepository:repo error:&error];

if (error) {
        NSLog(@"error create remote : %@", error.localizedDescription);
        return;
}

NSDictionary *optionsPush = @{GTRepositoryCloneOptionsCredentialProvider:provider};

[repo pushBranch:branch toRemote:remote withOptions:optionsPush error:&error progress:^(unsigned int current, unsigned int total, size_t bytes, BOOL * _Nonnull stop) {
        NSLog(@"push current : %d", current);
}];

if (error) {
        NSLog(@"error push branch : %@", error);
        return;
}
sallu89 commented 6 years ago

Try NSDictionary *optionsPush = @{GTRepositoryRemoteOptionsCredentialProvider:provider} instead of NSDictionary *optionsPush = @{GTRepositoryCloneOptionsCredentialProvider:provider}

tiennou commented 6 years ago

@remirobert Does the above comment fixes it ?

tiennou commented 6 years ago

Sweet, thanks for the support @sallu89 ! @remirobert Feel free to reopen if you're still having an issue !