]> git.proxmox.com Git - libgit2.git/blobdiff - tests/refs/delete.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / refs / delete.c
index 5e4afb138cf8128dd9d9a4f2c5eef2d8d67d6f7b..42cc534b561f7df97796bbc04a1b74aa9a4dffcd 100644 (file)
@@ -1,6 +1,6 @@
 #include "clar_libgit2.h"
 
-#include "fileops.h"
+#include "futils.h"
 #include "git2/reflog.h"
 #include "git2/refdb.h"
 #include "reflog.h"
@@ -27,13 +27,13 @@ void test_refs_delete__cleanup(void)
 
 void test_refs_delete__packed_loose(void)
 {
-   // deleting a ref which is both packed and loose should remove both tracks in the filesystem
+       /* deleting a ref which is both packed and loose should remove both tracks in the filesystem */
        git_reference *looked_up_ref, *another_looked_up_ref;
-       git_buf temp_path = GIT_BUF_INIT;
+       git_str temp_path = GIT_STR_INIT;
 
        /* Ensure the loose reference exists on the file system */
-       cl_git_pass(git_buf_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
-       cl_assert(git_path_exists(temp_path.ptr));
+       cl_git_pass(git_str_joinpath(&temp_path, git_repository_path(g_repo), packed_test_head_name));
+       cl_assert(git_fs_path_exists(temp_path.ptr));
 
        /* Lookup the reference */
        cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name));
@@ -49,15 +49,15 @@ void test_refs_delete__packed_loose(void)
        cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name));
 
        /* Ensure the loose reference doesn't exist any longer on the file system */
-       cl_assert(!git_path_exists(temp_path.ptr));
+       cl_assert(!git_fs_path_exists(temp_path.ptr));
 
        git_reference_free(another_looked_up_ref);
-       git_buf_free(&temp_path);
+       git_str_dispose(&temp_path);
 }
 
 void test_refs_delete__packed_only(void)
 {
-   // can delete a just packed reference
+       /* can delete a just packed reference */
        git_reference *ref;
        git_refdb *refdb;
        git_oid id;
@@ -66,7 +66,7 @@ void test_refs_delete__packed_only(void)
        git_oid_fromstr(&id, current_master_tip);
 
        /* Create and write the new object id reference */
-       cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0, NULL, NULL));
+       cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0, NULL));
        git_reference_free(ref);
 
        /* Lookup the reference */
@@ -91,3 +91,28 @@ void test_refs_delete__packed_only(void)
        git_reference_free(ref);
        git_refdb_free(refdb);
 }
+
+void test_refs_delete__remove(void)
+{
+       git_reference *ref;
+
+       /* Check that passing no old values lets us delete */
+
+       cl_git_pass(git_reference_lookup(&ref, g_repo, packed_test_head_name));
+       git_reference_free(ref);
+
+       cl_git_pass(git_reference_remove(g_repo, packed_test_head_name));
+
+       cl_git_fail(git_reference_lookup(&ref, g_repo, packed_test_head_name));
+}
+
+void test_refs_delete__head(void)
+{
+       git_reference *ref;
+
+       /* Check that it is not possible to delete HEAD */
+
+       cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
+       cl_git_fail(git_reference_delete(ref));
+       git_reference_free(ref);
+}