Clone via SSH.

This commit is contained in:
tastytea 2020-07-01 10:18:53 +02:00
parent 8af8115e24
commit ca61c1e391
Signed by: tastytea
GPG Key ID: CFC39497F1B26E07
2 changed files with 21 additions and 2 deletions

View File

@ -55,10 +55,22 @@ void check(int error)
}
}
int cred_acquire(git_cred **cred, const char * /*url*/,
const char *username_from_url, unsigned int /*allowed_types*/,
void * /*payload*/)
{
// return git_credential_ssh_key_new(
// cred, username_from_url, "/home/tastytea/.ssh/noid_fediblock.pub",
// "/home/tastytea/.ssh/noid_fediblock.pub", "");
return git_credential_ssh_key_from_agent(cred, username_from_url);
}
void clone()
{
check(git_clone(&_repo, "https://schlomp.space/FediBlock/data.git",
(get_tmpdir() / "repo").c_str(), nullptr));
git_clone_options options = GIT_CLONE_OPTIONS_INIT;
options.fetch_opts.callbacks.credentials = cred_acquire;
check(git_clone(&_repo, "git@schlomp.space:FediBlock/data.git",
(get_tmpdir() / "repo").c_str(), &options));
}
uint64_t get_last_id()

View File

@ -19,6 +19,8 @@
#include "cgi.hpp"
#include <git2.h>
#include <cstdint>
namespace FediBlock::git
@ -29,6 +31,11 @@ using std::uint64_t;
// Throws runtime_error on error.
void check(int error);
// Acquire credentials for SSH.
int cred_acquire(git_cred **cred, const char *url,
const char *username_from_url, unsigned int allowed_types,
void *payload);
// Clone the git repo.
void clone();