#include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
#include "git2/reflog.h"
#include "git2/refdb.h"
#include "reflog.h"
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));
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;
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 */
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);
+}