Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2012-11-02 00:47:18 +0400
committerEdward Thomson <ethomson@edwardthomson.com>2012-11-11 21:56:33 +0400
commitb0f6e45d149c033c9fe41d49af2a87d169d11f40 (patch)
tree7cc89f19d1ddbe8ded27944756eccc51f57b8205 /tests-clar/fetchhead
parentd18713fb4ad1ba3d18a75272e1c1c3eb45715aba (diff)
create FETCH_HEAD specially instead of as a ref file
Diffstat (limited to 'tests-clar/fetchhead')
-rw-r--r--tests-clar/fetchhead/fetchhead_data.h21
-rw-r--r--tests-clar/fetchhead/network.c87
-rw-r--r--tests-clar/fetchhead/nonetwork.c96
3 files changed, 204 insertions, 0 deletions
diff --git a/tests-clar/fetchhead/fetchhead_data.h b/tests-clar/fetchhead/fetchhead_data.h
new file mode 100644
index 000000000..71f67be25
--- /dev/null
+++ b/tests-clar/fetchhead/fetchhead_data.h
@@ -0,0 +1,21 @@
+
+#define FETCH_HEAD_WILDCARD_DATA \
+ "49322bb17d3acc9146f98c97d078513228bbf3c0\t\tbranch 'master' of git://github.com/libgit2/TestGitRepository\n" \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\tnot-for-merge\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n" \
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1\tnot-for-merge\tbranch 'no-parent' of git://github.com/libgit2/TestGitRepository\n" \
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb\tnot-for-merge\ttag 'annotated_tag' of git://github.com/libgit2/TestGitRepository\n" \
+ "55a1a760df4b86a02094a904dfa511deb5655905\tnot-for-merge\ttag 'blob' of git://github.com/libgit2/TestGitRepository\n" \
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee\tnot-for-merge\ttag 'commit_tree' of git://github.com/libgit2/TestGitRepository\n"
+
+#define FETCH_HEAD_NO_MERGE_DATA \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\tnot-for-merge\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n" \
+ "49322bb17d3acc9146f98c97d078513228bbf3c0\tnot-for-merge\tbranch 'master' of git://github.com/libgit2/TestGitRepository\n" \
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1\tnot-for-merge\tbranch 'no-parent' of git://github.com/libgit2/TestGitRepository\n" \
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb\tnot-for-merge\ttag 'annotated_tag' of git://github.com/libgit2/TestGitRepository\n" \
+ "55a1a760df4b86a02094a904dfa511deb5655905\tnot-for-merge\ttag 'blob' of git://github.com/libgit2/TestGitRepository\n" \
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee\tnot-for-merge\ttag 'commit_tree' of git://github.com/libgit2/TestGitRepository\n"
+
+
+#define FETCH_HEAD_EXPLICIT_DATA \
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6\t\tbranch 'first-merge' of git://github.com/libgit2/TestGitRepository\n"
+
diff --git a/tests-clar/fetchhead/network.c b/tests-clar/fetchhead/network.c
new file mode 100644
index 000000000..ef9d01bf9
--- /dev/null
+++ b/tests-clar/fetchhead/network.c
@@ -0,0 +1,87 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "fetchhead.h"
+#include "fetchhead_data.h"
+#include "git2/clone.h"
+
+CL_IN_CATEGORY("network")
+
+#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
+
+static git_repository *g_repo;
+
+void test_fetchhead_network__initialize(void)
+{
+ g_repo = NULL;
+}
+
+static void cleanup_repository(void *path)
+{
+ if (g_repo)
+ git_repository_free(g_repo);
+ cl_fixture_cleanup((const char *)path);
+}
+
+
+static void fetchhead_test_clone(void)
+{
+ cl_set_cleanup(&cleanup_repository, "./test1");
+
+ cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test1", NULL, NULL, NULL));
+}
+
+static void fetchhead_test_fetch(const char *fetchspec, const char *expected_fetchhead)
+{
+ git_remote *remote;
+ git_buf fetchhead_buf = GIT_BUF_INIT;
+ int equals = 0;
+
+ cl_git_pass(git_remote_load(&remote, g_repo, "origin"));
+ git_remote_set_autotag(remote, GIT_REMOTE_DOWNLOAD_TAGS_AUTO);
+
+ if(fetchspec != NULL)
+ git_remote_set_fetchspec(remote, fetchspec);
+
+ cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
+ cl_git_pass(git_remote_download(remote, NULL, NULL));
+ git_remote_disconnect(remote);
+
+ cl_git_pass(git_remote_update_tips(remote));
+ git_remote_free(remote);
+
+ cl_git_pass(git_futils_readbuffer(&fetchhead_buf,
+ "./test1/.git/FETCH_HEAD"));
+
+ equals = (strcmp(fetchhead_buf.ptr, expected_fetchhead) == 0);
+
+ git_buf_free(&fetchhead_buf);
+
+ cl_assert(equals);
+}
+
+void test_fetchhead_network__wildcard_spec(void)
+{
+ fetchhead_test_clone();
+ fetchhead_test_fetch(NULL, FETCH_HEAD_WILDCARD_DATA);
+}
+
+void test_fetchhead_network__explicit_spec(void)
+{
+ fetchhead_test_clone();
+ fetchhead_test_fetch("refs/heads/first-merge:refs/remotes/origin/first-merge", FETCH_HEAD_EXPLICIT_DATA);
+}
+
+void test_fetchhead_network__no_merges(void)
+{
+ git_config *config;
+
+ fetchhead_test_clone();
+
+ cl_git_pass(git_repository_config(&config, g_repo));
+ cl_git_pass(git_config_set_string(config, "branch.master.remote", NULL));
+ cl_git_pass(git_config_set_string(config, "branch.master.merge", NULL));
+ git_config_free(config);
+
+ fetchhead_test_fetch(NULL, FETCH_HEAD_NO_MERGE_DATA);
+}
diff --git a/tests-clar/fetchhead/nonetwork.c b/tests-clar/fetchhead/nonetwork.c
new file mode 100644
index 000000000..1de5280a8
--- /dev/null
+++ b/tests-clar/fetchhead/nonetwork.c
@@ -0,0 +1,96 @@
+#include "clar_libgit2.h"
+
+#include "repository.h"
+#include "fetchhead.h"
+#include "fetchhead_data.h"
+
+#define DO_LOCAL_TEST 0
+
+static git_repository *g_repo;
+
+void test_fetchhead_nonetwork__initialize(void)
+{
+ g_repo = NULL;
+}
+
+static void cleanup_repository(void *path)
+{
+ if (g_repo)
+ git_repository_free(g_repo);
+ cl_fixture_cleanup((const char *)path);
+}
+
+void test_fetchhead_nonetwork__write(void)
+{
+ git_vector fetchhead_vector;
+ git_fetchhead_ref *fetchhead[6];
+ git_oid oid[6];
+ git_buf fetchhead_buf = GIT_BUF_INIT;
+ size_t i;
+ int equals = 0;
+
+ git_vector_init(&fetchhead_vector, 6, NULL);
+
+ cl_set_cleanup(&cleanup_repository, "./test1");
+
+ cl_git_pass(git_repository_init(&g_repo, "./test1", 0));
+
+ cl_git_pass(git_oid_fromstr(&oid[0],
+ "49322bb17d3acc9146f98c97d078513228bbf3c0"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[0], &oid[0], 1,
+ "refs/heads/master",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[0]));
+
+ cl_git_pass(git_oid_fromstr(&oid[1],
+ "0966a434eb1a025db6b71485ab63a3bfbea520b6"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[1], &oid[1], 0,
+ "refs/heads/first-merge",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[1]));
+
+ cl_git_pass(git_oid_fromstr(&oid[2],
+ "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[2], &oid[2], 0,
+ "refs/heads/no-parent",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[2]));
+
+ cl_git_pass(git_oid_fromstr(&oid[3],
+ "d96c4e80345534eccee5ac7b07fc7603b56124cb"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[3], &oid[3], 0,
+ "refs/tags/annotated_tag",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[3]));
+
+ cl_git_pass(git_oid_fromstr(&oid[4],
+ "55a1a760df4b86a02094a904dfa511deb5655905"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[4], &oid[4], 0,
+ "refs/tags/blob",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[4]));
+
+ cl_git_pass(git_oid_fromstr(&oid[5],
+ "8f50ba15d49353813cc6e20298002c0d17b0a9ee"));
+ cl_git_pass(git_fetchhead_ref_create(&fetchhead[5], &oid[5], 0,
+ "refs/tags/commit_tree",
+ "git://github.com/libgit2/TestGitRepository"));
+ cl_git_pass(git_vector_insert(&fetchhead_vector, fetchhead[5]));
+
+ git_fetchhead_write(g_repo, &fetchhead_vector);
+
+ cl_git_pass(git_futils_readbuffer(&fetchhead_buf,
+ "./test1/.git/FETCH_HEAD"));
+
+ equals = (strcmp(fetchhead_buf.ptr, FETCH_HEAD_WILDCARD_DATA) == 0);
+
+ for (i=0; i < 6; i++)
+ git_fetchhead_ref_free(fetchhead[i]);
+
+ git_buf_free(&fetchhead_buf);
+
+ git_vector_free(&fetchhead_vector);
+
+ cl_assert(equals);
+}
+