-
Notifications
You must be signed in to change notification settings - Fork 0
/
zapgit.cc
54 lines (41 loc) · 1.25 KB
/
zapgit.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "libgit2pp/git2pp.h"
#include <iostream>
void prologue() {
std::cerr << "zapgit 0.1";
int major, minor, rev;
git_libgit2_version(&major, &minor, &rev);
std::cerr << " (libgit2 " << major << "." << minor << "." << rev << ")\n";
}
int usage() {
std::cerr << "Usage: zapgit init|new|show|ls|fixed\n";
return 1;
}
bool git2ok(int rc) {
if (rc >= 0) {
return true;
}
const git_error *e = giterr_last();
fprintf(stderr, "Error %d/%d: %s\n", rc, e->klass, e->message);
return false;
}
int main(int argc, char * argv[]) try {
prologue();
if (argc < 2) {
return usage();
}
git2pp::Session git2;
auto repo = git2[git_repository_open](".");
auto master = repo[git_reference_dwim]("master");
auto commit = master[git_reference_peel](GIT_OBJ_COMMIT).as<git_commit>();
auto dup = commit;
dup = commit;
std::cout << "master = " << commit[git_commit_id]() << "\n";
std::cout << "author = " << commit[git_commit_author]()->name << "\n";
std::cout << "message = " << commit[git_commit_message]() << "\n";
} catch (std::exception const & ex) {
std::cerr << ex.what() << "\n";
return 1;
} catch (...) {
std::cerr << "unknown exception\n";
return 1;
}