]>
Commit | Line | Data |
---|---|---|
b0f6e45d ET |
1 | #include "clar_libgit2.h" |
2 | ||
3 | #include "repository.h" | |
4 | #include "fetchhead.h" | |
156cfec0 | 5 | #include "../fetchhead/fetchhead_data.h" |
b0f6e45d ET |
6 | #include "git2/clone.h" |
7 | ||
b0f6e45d ET |
8 | #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository" |
9 | ||
10 | static git_repository *g_repo; | |
b9e7e2b4 | 11 | static git_remote *g_origin; |
18b2d560 | 12 | static git_clone_options g_options; |
b0f6e45d | 13 | |
6443eaf2 | 14 | void test_online_fetchhead__initialize(void) |
b0f6e45d ET |
15 | { |
16 | g_repo = NULL; | |
18b2d560 BS |
17 | |
18 | memset(&g_options, 0, sizeof(git_clone_options)); | |
19 | g_options.version = GIT_CLONE_OPTIONS_VERSION; | |
b9e7e2b4 | 20 | cl_git_pass(git_remote_new(&g_origin, NULL, "origin", LIVE_REPO_URL, GIT_REMOTE_DEFAULT_FETCH)); |
44f36f6e BS |
21 | } |
22 | ||
6443eaf2 | 23 | void test_online_fetchhead__cleanup(void) |
44f36f6e | 24 | { |
b9e7e2b4 | 25 | git_remote_free(g_origin); |
b0f6e45d ET |
26 | } |
27 | ||
28 | static void cleanup_repository(void *path) | |
29 | { | |
9094d30b | 30 | if (g_repo) { |
b0f6e45d | 31 | git_repository_free(g_repo); |
9094d30b SC |
32 | g_repo = NULL; |
33 | } | |
34 | ||
b0f6e45d ET |
35 | cl_fixture_cleanup((const char *)path); |
36 | } | |
37 | ||
38 | ||
39 | static void fetchhead_test_clone(void) | |
40 | { | |
18b2d560 | 41 | cl_set_cleanup(&cleanup_repository, "./foo"); |
b0f6e45d | 42 | |
b9e7e2b4 | 43 | cl_git_pass(git_clone(&g_repo, g_origin, "./foo", &g_options)); |
b0f6e45d ET |
44 | } |
45 | ||
46 | static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead) | |
47 | { | |
48 | git_remote *remote; | |
49 | git_buf fetchhead_buf = GIT_BUF_INIT; | |
50 | int equals = 0; | |
51 | ||
52 | cl_git_pass(git_remote_load(&remote, g_repo, "origin")); | |
53 | git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO); | |
54 | ||
55 | if(fetchspec != NULL) | |
56 | git_remote_set_fetchspec(remote, fetchspec); | |
57 | ||
df705148 | 58 | cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); |
b0f6e45d | 59 | cl_git_pass(git_remote_download(remote, NULL, NULL)); |
b0f6e45d | 60 | cl_git_pass(git_remote_update_tips(remote)); |
5cf1b4f0 | 61 | git_remote_disconnect(remote); |
b0f6e45d ET |
62 | git_remote_free(remote); |
63 | ||
a7f125cd | 64 | cl_git_pass(git_futils_readbuffer(&fetchhead_buf, "./foo/.git/FETCH_HEAD")); |
b0f6e45d ET |
65 | |
66 | equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0); | |
67 | ||
68 | git_buf_free(&fetchhead_buf); | |
69 | ||
70 | cl_assert(equals); | |
71 | } | |
72 | ||
6443eaf2 | 73 | void test_online_fetchhead__wildcard_spec(void) |
b0f6e45d ET |
74 | { |
75 | fetchhead_test_clone(); | |
76 | fetchhead_test_fetch(NULL, FETCH_HEAD_WILDCARD_DATA); | |
77 | } | |
78 | ||
6443eaf2 | 79 | void test_online_fetchhead__explicit_spec(void) |
b0f6e45d ET |
80 | { |
81 | fetchhead_test_clone(); | |
82 | fetchhead_test_fetch("refs/heads/first-merge:refs/remotes/origin/first-merge", FETCH_HEAD_EXPLICIT_DATA); | |
83 | } | |
84 | ||
6443eaf2 | 85 | void test_online_fetchhead__no_merges(void) |
b0f6e45d ET |
86 | { |
87 | git_config *config; | |
88 | ||
89 | fetchhead_test_clone(); | |
90 | ||
91 | cl_git_pass(git_repository_config(&config, g_repo)); | |
92 | cl_git_pass(git_config_set_string(config, "branch.master.remote", NULL)); | |
93 | cl_git_pass(git_config_set_string(config, "branch.master.merge", NULL)); | |
94 | git_config_free(config); | |
95 | ||
96 | fetchhead_test_fetch(NULL, FETCH_HEAD_NO_MERGE_DATA); | |
97 | } |