libgit2 / objective-git

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

Accessing private repos #703

Open schriftgestalt opened 4 years ago

schriftgestalt commented 4 years ago

Is there a way to access private repos (e.g. clone them). How do I supply username and password.

iain17 commented 4 years ago

You supply them using the CredentialProvider flags. For instance if you're doing a fetch set GTRepositoryRemoteOptionsCredentialProvider.

In Swift this could look like:

let auth = GTCredentialProvider { (type, url, username) -> GTCredential? in
                let cred = try? GTCredential(userName: username, publicKeyString: publicKey, privateKeyString: privateKey, passphrase: passphrase)
                return cred
 }
var options = [String : Any]()
options[GTRepositoryCloneOptionsCredentialProvider] = auth
options[GTRepositoryRemoteOptionsCredentialProvider] = auth
//Then call fetch or clone using these options:
GTRepository.clone(from: url, toWorkingDirectory: path, options: options)