libgit2/rugged — pull request #292 by arthurschreiber (2013-11-20 23:20:36+00:00)
Title: Add credentials support

This is a first rough draft for credentials support in Rugged.

It tries to expose a simple as well as flexible API.

For simple use-case (like scripting/automation, where the credentials are most likely known/fixed), it allows passing a `Rugged::Credentials` object directly in the options hash to `Rugged::Repository#clone_at`:

```ruby
repo = Rugged::Repository.clone_at("git@github.com:arthurschreiber/private.git", dir, {
credentials: Rugged::Credentials::SshKey.new("git", File.expand_path("~/.ssh/id_rsa.pub"), File.expand_path("~/.ssh/id_rsa"), "passphrase")
})
```

For more complex use cases, like GUIs, it allows passing a proc instead. This proc can then handle the credential lookup:

```ruby
repo = Rugged::Repository.clone_at("git@github.com:arthurschreiber/private.git", dir, {
credentials: lambda { |url, username, allowed_types|
# Dynamically create the correct credentials object, based on the url, username, and/or
# allowed credential types.
return Rugged::Credentials::SshKey.new("git", File.expand_path("~/.ssh/id_rsa.pub"), File.expand_path("~/.ssh/id_rsa"), "passphrase")
}
})
```