| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <git2.h> | ||
| 2 | #include <stddef.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include "examples/git.h" | ||
| 6 | |||
| 7 | ✗ | int git_example() { | |
| 8 | ✗ | git_libgit2_init(); | |
| 9 | |||
| 10 | ✗ | const char* repo_path = "."; | |
| 11 | ✗ | git_repository* repo = NULL; | |
| 12 | |||
| 13 | // Open the repo | ||
| 14 | ✗ | if (git_repository_open(&repo, repo_path) != 0) { | |
| 15 | ✗ | const git_error* e = git_error_last(); | |
| 16 | ✗ | printf("Error %d: %s\n", e->klass, e->message); | |
| 17 | ✗ | return 1; | |
| 18 | } | ||
| 19 | |||
| 20 | ✗ | git_reference* head = NULL; | |
| 21 | ✗ | git_commit* commit = NULL; | |
| 22 | |||
| 23 | // Get the latest commit | ||
| 24 | ✗ | if (git_repository_head(&head, repo) == 0) { | |
| 25 | git_oid oid; | ||
| 26 | ✗ | git_reference_name_to_id(&oid, repo, git_reference_name(head)); | |
| 27 | ✗ | if (git_commit_lookup(&commit, repo, &oid) == 0) { | |
| 28 | ✗ | printf("Latest commit: %s %s\n", | |
| 29 | git_oid_tostr_s(git_commit_id(commit)), | ||
| 30 | git_commit_message(commit)); | ||
| 31 | ✗ | git_commit_free(commit); | |
| 32 | } | ||
| 33 | ✗ | git_reference_free(head); | |
| 34 | } | ||
| 35 | |||
| 36 | ✗ | return 0; | |
| 37 | } | ||
| 38 |