From 7ed00c5c92682edea3a67581c534ea5e970db038 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20L=C3=BChne?= Date: Wed, 2 Jun 2021 16:31:54 +0200 Subject: [PATCH] Support authentication in push example This adds basic support for user/password and SSH authentication to the push example. Authentication is implemented by using the cred_acquire_cb credential callback defined in examples/common.c. Co-authored-by: Marius Knaust --- examples/push.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/examples/push.c b/examples/push.c index bcf307607..5113eed39 100644 --- a/examples/push.c +++ b/examples/push.c @@ -32,6 +32,7 @@ /** Entry point for this command */ int lg2_push(git_repository *repo, int argc, char **argv) { git_push_options options; + git_remote_callbacks callbacks; git_remote* remote = NULL; char *refspec = "refs/heads/master"; const git_strarray refspecs = { @@ -47,7 +48,11 @@ int lg2_push(git_repository *repo, int argc, char **argv) { check_lg2(git_remote_lookup(&remote, repo, "origin" ), "Unable to lookup remote", NULL); + check_lg2(git_remote_init_callbacks(&callbacks, GIT_REMOTE_CALLBACKS_VERSION), "Error initializing remote callbacks", NULL); + callbacks.credentials = cred_acquire_cb; + check_lg2(git_push_options_init(&options, GIT_PUSH_OPTIONS_VERSION ), "Error initializing push", NULL); + options.callbacks = callbacks; check_lg2(git_remote_push(remote, &refspecs, &options), "Error pushing", NULL);