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