Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Created July 31, 2020 15:05
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 alexcrichton/63eb27cd2428e0edf3fce8997bdf08ec to your computer and use it in GitHub Desktop.
Save alexcrichton/63eb27cd2428e0edf3fce8997bdf08ec to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <git2/remote.h>
#include <git2/repository.h>
#include <git2/errors.h>
#include <git2/global.h>
#include <stdio.h>
int main() {
assert(git_libgit2_init() == 1);
git_repository *repo;
assert(git_repository_init(&repo, "index-clone", 0) == 0);
git_remote *remote;
assert(git_remote_create_anonymous(&remote, repo, "index/.git") == 0);
git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT;
char *strings[] = {"HEAD:refs/remotes/origin/head"};
git_strarray refspecs;
refspecs.strings = strings;
refspecs.count = 1;
int err = git_remote_fetch(remote, &refspecs, &fetch_opts, NULL);
printf("err = %d\n", err);
if (err == 0)
return 0;
const git_error *last = git_error_last();
if (last != NULL) {
printf("message: %s\n", last->message);
printf("klass: %d\n", last->klass);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment