]> git.proxmox.com Git - libgit2.git/blobdiff - tests/clone/empty.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / clone / empty.c
index 6d19244cc26f63805fb3fd38a1da990a5bd02aec..94847bc7326154bb31c6d573f2da5bef4e10bbdf 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "git2/clone.h"
 #include "repository.h"
+#include "repo/repo_helpers.h"
 
 static git_clone_options g_options;
 static git_repository *g_repo;
@@ -10,18 +11,19 @@ static git_repository *g_repo_cloned;
 void test_clone_empty__initialize(void)
 {
        git_repository *sandbox = cl_git_sandbox_init("empty_bare.git");
-       git_remote_callbacks dummy_callbacks = GIT_REMOTE_CALLBACKS_INIT;
+       git_fetch_options dummy_options = GIT_FETCH_OPTIONS_INIT;
        cl_git_remove_placeholders(git_repository_path(sandbox), "dummy-marker.txt");
 
        g_repo = NULL;
 
        memset(&g_options, 0, sizeof(git_clone_options));
        g_options.version = GIT_CLONE_OPTIONS_VERSION;
-       g_options.remote_callbacks = dummy_callbacks;
+       g_options.fetch_opts = dummy_options;
 }
 
 void test_clone_empty__cleanup(void)
 {
+       cl_fixture_cleanup("tmp_global_path");
        cl_git_sandbox_cleanup();
 }
 
@@ -38,7 +40,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
        char *local_name = "refs/heads/master";
        const char *expected_tracked_branch_name = "refs/remotes/origin/master";
        const char *expected_remote_name = "origin";
-       char buffer[1024];
+       git_buf buf = GIT_BUF_INIT;
        git_reference *ref;
 
        cl_set_cleanup(&cleanup_repository, "./empty");
@@ -50,22 +52,37 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void)
        cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name));
 
        /* ...one can still retrieve the name of the remote tracking reference */
-       cl_assert_equal_i((int)strlen(expected_tracked_branch_name) + 1,
-               git_branch_upstream_name(buffer, 1024, g_repo_cloned, local_name));
+       cl_git_pass(git_branch_upstream_name(&buf, g_repo_cloned, local_name));
 
-       cl_assert_equal_s(expected_tracked_branch_name, buffer);
+       cl_assert_equal_s(expected_tracked_branch_name, buf.ptr);
+       git_buf_dispose(&buf);
 
        /* ...and the name of the remote... */
-       cl_assert_equal_i((int)strlen(expected_remote_name) + 1,
-               git_branch_remote_name(buffer, 1024, g_repo_cloned, expected_tracked_branch_name));
+       cl_git_pass(git_branch_remote_name(&buf, g_repo_cloned, expected_tracked_branch_name));
 
-       cl_assert_equal_s(expected_remote_name, buffer);
+       cl_assert_equal_s(expected_remote_name, buf.ptr);
+       git_buf_dispose(&buf);
 
        /* ...even when the remote HEAD is unborn as well */
        cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned,
                expected_tracked_branch_name));
 }
 
+void test_clone_empty__respects_initialbranch_config(void)
+{
+       git_buf buf = GIT_BUF_INIT;
+
+       create_tmp_global_config("tmp_global_path", "init.defaultbranch", "my_default_branch");
+
+       cl_set_cleanup(&cleanup_repository, "./empty");
+
+       g_options.bare = true;
+       cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options));
+       cl_git_pass(git_branch_upstream_name(&buf, g_repo_cloned, "refs/heads/my_default_branch"));
+       cl_assert_equal_s("refs/remotes/origin/my_default_branch", buf.ptr);
+       git_buf_dispose(&buf);
+}
+
 void test_clone_empty__can_clone_an_empty_local_repo(void)
 {
        cl_set_cleanup(&cleanup_repository, "./empty");