Skip to content

Instantly share code, notes, and snippets.

@brennie
Created December 14, 2023 04:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brennie/72afc8e0d61a490023392e6b31608540 to your computer and use it in GitHub Desktop.
Save brennie/72afc8e0d61a490023392e6b31608540 to your computer and use it in GitHub Desktop.
libgit2 push error demo
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "git2/errors.h"
#include "git2/global.h"
#include "git2/remote.h"
#include "git2/repository.h"
#include "git2/strarray.h"
void git_die(const char *msg) {
const git_error *const err = git_error_last();
fprintf(stderr, "%s: %s\n", msg, err->message);
exit(1);
}
#define GIT_TRY(fn, ...) \
do { \
if (fn(__VA_ARGS__) != 0) { \
git_die(#fn); \
} \
} while (0)
int negotiate_push(const git_push_update **updates, size_t len, void *payload);
int main(int argc, char **argv) {
if (argc < 2) {
fprintf(stderr, "usage: %s REPOSITORY\n", argv[0]);
return 1;
}
git_libgit2_init();
const char *const repository_path = argv[1];
git_repository *repo = NULL;
GIT_TRY(git_repository_open, &repo, repository_path);
char *refspec = "+refs/heads/main:refs/heads/main";
git_strarray refspecs = {
.count = 1,
.strings = &refspec,
};
git_remote *remote;
GIT_TRY(git_remote_lookup, &remote, repo, "origin");
git_push_options push_options = GIT_PUSH_OPTIONS_INIT;
push_options.callbacks.push_negotiation = negotiate_push;
push_options.callbacks.payload = NULL;
GIT_TRY(git_remote_push, remote, &refspecs, &push_options);
git_remote_free(remote);
git_repository_free(repo);
return 0;
}
int negotiate_push(const git_push_update **updates, size_t len, void *payload) {
return -1;
}
@brennie
Copy link
Author

brennie commented Dec 14, 2023

Error:

git_remote_push: config value 'pack.windowMemory' was not found

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment