Merge pull request #1102 from nulltoken/topic/fetch-test-coverage fetch: enhance test coverage
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
diff --git a/tests-clar/network/fetch.c b/tests-clar/network/fetch.c
index 81a0eed..b9eaedf 100644
--- a/tests-clar/network/fetch.c
+++ b/tests-clar/network/fetch.c
@@ -33,7 +33,7 @@ static void progress(const git_transfer_progress *stats, void *payload)
*bytes_received = stats->received_bytes;
}
-static void do_fetch(const char *url, int flag, int n)
+static void do_fetch(const char *url, git_remote_autotag_option_t flag, int n)
{
git_remote *remote;
git_remote_callbacks callbacks;
@@ -75,3 +75,36 @@ void test_network_fetch__no_tags_http(void)
{
do_fetch("http://github.com/libgit2/TestGitRepository.git", GIT_REMOTE_DOWNLOAD_TAGS_NONE, 3);
}
+
+static void transferProgressCallback(const git_transfer_progress *stats, void *payload)
+{
+ bool *invoked = (bool *)payload;
+ *invoked = true;
+}
+
+void test_network_fetch__doesnt_retrieve_a_pack_when_the_repository_is_up_to_date(void)
+{
+ git_repository *_repository;
+ git_remote *remote;
+ bool invoked = false;
+
+ cl_git_pass(git_clone_bare(&_repository, "https://github.com/libgit2/TestGitRepository.git", "./fetch/lg2", NULL, NULL));
+ git_repository_free(_repository);
+
+ cl_git_pass(git_repository_open(&_repository, "./fetch/lg2"));
+
+ cl_git_pass(git_remote_load(&remote, _repository, "origin"));
+ cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+
+ cl_assert_equal_i(false, invoked);
+
+ cl_git_pass(git_remote_download(remote, &transferProgressCallback, &invoked));
+
+ cl_assert_equal_i(false, invoked);
+
+ cl_git_pass(git_remote_update_tips(remote));
+ git_remote_disconnect(remote);
+
+ git_remote_free(remote);
+ git_repository_free(_repository);
+}