From ca61c1e3918a57b111b5f3e03c9da05644923b34 Mon Sep 17 00:00:00 2001 From: tastytea Date: Wed, 1 Jul 2020 10:18:53 +0200 Subject: [PATCH] Clone via SSH. --- src/git.cpp | 16 ++++++++++++++-- src/git.hpp | 7 +++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/git.cpp b/src/git.cpp index 33eb247..654644f 100644 --- a/src/git.cpp +++ b/src/git.cpp @@ -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() diff --git a/src/git.hpp b/src/git.hpp index 9288a5c..6b138bc 100644 --- a/src/git.hpp +++ b/src/git.hpp @@ -19,6 +19,8 @@ #include "cgi.hpp" +#include + #include 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();