]> git.proxmox.com Git - libgit2.git/blob - tests/t0402-details.c
Redesigned the walking/object lookup interface
[libgit2.git] / tests / t0402-details.c
1 #include "test_lib.h"
2 #include "test_helpers.h"
3 #include "commit.h"
4
5 #include <git/odb.h>
6 #include <git/commit.h>
7 #include <git/revwalk.h>
8
9 static const char *odb_dir = "../t0501-objects";
10 static const char *commit_ids[] = {
11 "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
12 "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
13 "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
14 "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
15 "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
16 "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
17 };
18
19 BEGIN_TEST(query_details_test)
20 const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
21
22 unsigned int i;
23 git_odb *db;
24 git_repository *repo;
25
26 must_pass(git_odb_open(&db, odb_dir));
27
28 repo = git_repository_alloc(db);
29 must_be_true(repo != NULL);
30
31 for (i = 0; i < commit_count; ++i) {
32 git_oid id;
33 git_commit *commit;
34
35 const git_person *author, *committer;
36 const char *message, *message_short;
37 time_t commit_time;
38
39 git_oid_mkstr(&id, commit_ids[i]);
40
41 commit = git_commit_lookup(repo, &id);
42 must_be_true(commit != NULL);
43
44 message = git_commit_message(commit);
45 message_short = git_commit_message_short(commit);
46 author = git_commit_author(commit);
47 committer = git_commit_committer(commit);
48 commit_time = git_commit_time(commit);
49
50 must_be_true(strcmp(author->name, "Scott Chacon") == 0);
51 must_be_true(strcmp(author->email, "schacon@gmail.com") == 0);
52 must_be_true(strcmp(committer->name, "Scott Chacon") == 0);
53 must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0);
54 must_be_true(strchr(message, '\n') != NULL);
55 must_be_true(strchr(message_short, '\n') == NULL);
56 must_be_true(commit_time > 0);
57 }
58
59 git_repository_free(repo);
60 git_odb_close(db);
61 END_TEST