]> git.proxmox.com Git - libgit2.git/blobdiff - tests/refs/branches/create.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / refs / branches / create.c
index d4cf4c29fb6a26b994f5e50a8eeaf062ed31f723..2fb11668b507b5b492afddd0662fcd7ade8cfdaf 100644 (file)
@@ -65,10 +65,14 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
        cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
 }
 
-void test_refs_branches_create__cannot_force_create_over_current_branch(void)
+void test_refs_branches_create__cannot_force_create_over_current_branch_in_nonbare_repo(void)
 {
        const git_oid *oid;
        git_reference *branch2;
+
+       /* Default repo for these tests is a bare repo, but this test requires a non-bare one */
+       cl_git_sandbox_cleanup();
+       repo = cl_git_sandbox_init("testrepo");
        retrieve_known_commit(&target, repo);
 
        cl_git_pass(git_branch_lookup(&branch2, repo, "master", GIT_BRANCH_LOCAL));
@@ -84,60 +88,51 @@ void test_refs_branches_create__cannot_force_create_over_current_branch(void)
        git_reference_free(branch2);
 }
 
-void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
+void test_refs_branches_create__can_force_create_over_current_branch_in_bare_repo(void)
 {
+       const git_oid *oid;
+       git_reference *branch2;
        retrieve_known_commit(&target, repo);
 
-       cl_assert_equal_i(GIT_EINVALIDSPEC,
-               git_branch_create(&branch, repo, "inv@{id", target, 0));
+       cl_git_pass(git_branch_lookup(&branch2, repo, "master", GIT_BRANCH_LOCAL));
+       cl_assert_equal_s("refs/heads/master", git_reference_name(branch2));
+       cl_assert_equal_i(true, git_branch_is_head(branch2));
+       oid = git_commit_id(target);
+
+       cl_git_pass(git_branch_create(&branch, repo, "master", target, 1));
+       git_reference_free(branch);
+       branch = NULL;
+       cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
+       cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
+       cl_git_pass(git_oid_cmp(git_reference_target(branch), oid));
+       git_reference_free(branch2);
 }
 
-void test_refs_branches_create__default_reflog_message(void)
+void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
 {
-       git_reflog *log;
-       git_buf buf = GIT_BUF_INIT;
-       const git_reflog_entry *entry;
-       git_signature *sig;
-       git_config *cfg;
-
-       cl_git_pass(git_repository_config(&cfg, repo));
-       cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
-       cl_git_pass(git_config_set_string(cfg, "user.email", "foo@example.com"));
-       git_config_free(cfg);
-
-       cl_git_pass(git_signature_default(&sig, repo));
-
        retrieve_known_commit(&target, repo);
-       cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
-       cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
 
-       entry = git_reflog_entry_byindex(log, 0);
-       cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
-       cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
-       cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);
-
-       git_buf_free(&buf);
-       git_reflog_free(log);
-       git_signature_free(sig);
+       cl_assert_equal_i(GIT_EINVALIDSPEC,
+               git_branch_create(&branch, repo, "inv@{id", target, 0));
 }
 
 static void assert_branch_matches_name(
        const char *expected, const char *lookup_as)
 {
        git_reference *ref;
-       git_buf b = GIT_BUF_INIT;
+       git_str b = GIT_STR_INIT;
 
        cl_git_pass(git_branch_lookup(&ref, repo, lookup_as, GIT_BRANCH_LOCAL));
 
-       cl_git_pass(git_buf_sets(&b, "refs/heads/"));
-       cl_git_pass(git_buf_puts(&b, expected));
+       cl_git_pass(git_str_sets(&b, "refs/heads/"));
+       cl_git_pass(git_str_puts(&b, expected));
        cl_assert_equal_s(b.ptr, git_reference_name(ref));
 
        cl_git_pass(
                git_oid_cmp(git_reference_target(ref), git_commit_id(target)));
 
        git_reference_free(ref);
-       git_buf_free(&b);
+       git_str_dispose(&b);
 }
 
 void test_refs_branches_create__can_create_branch_with_unicode(void)
@@ -150,7 +145,7 @@ void test_refs_branches_create__can_create_branch_with_unicode(void)
        const char *expected[] = { nfc, nfd, emoji };
        unsigned int i;
        bool fs_decompose_unicode =
-               git_path_does_fs_decompose_unicode(git_repository_path(repo));
+               git_fs_path_does_decompose_unicode(git_repository_path(repo));
 
        retrieve_known_commit(&target, repo);