tests: submodule: insert index entries directly into index
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
diff --git a/tests/submodule/add.c b/tests/submodule/add.c
index ef7faa8..383b5e5 100644
--- a/tests/submodule/add.c
+++ b/tests/submodule/add.c
@@ -7,6 +7,7 @@
#include "repository.h"
static git_repository *g_repo = NULL;
+static const char *valid_blob_id = "fa49b077972391ad58037050f2a75f74e3671e92";
void test_submodule_add__cleanup(void)
{
@@ -129,31 +130,39 @@ void test_submodule_add__url_relative_to_workdir(void)
assert_submodule_url("TestGitRepository", git_repository_workdir(g_repo));
}
+static void test_add_entry(
+ git_index *index,
+ const char *idstr,
+ const char *path,
+ git_filemode_t mode)
+{
+ git_index_entry entry = {{0}};
+
+ cl_git_pass(git_oid_fromstr(&entry.id, idstr));
+
+ entry.path = path;
+ entry.mode = mode;
+
+ cl_git_pass(git_index_add(index, &entry));
+}
+
void test_submodule_add__path_exists_in_index(void)
{
git_index *index;
git_submodule *sm;
- git_buf dirname = GIT_BUF_INIT;
git_buf filename = GIT_BUF_INIT;
g_repo = cl_git_sandbox_init("testrepo");
- cl_git_pass(git_buf_joinpath(&dirname, git_repository_workdir(g_repo), "subdirectory"));
- cl_git_pass(git_buf_joinpath(&filename, dirname.ptr, "test.txt"));
-
- cl_git_pass(p_mkdir(dirname.ptr, 0700));
- cl_git_mkfile(filename.ptr, "This is some content");
+ cl_git_pass(git_buf_joinpath(&filename, "subdirectory", "test.txt"));
- cl_git_pass(git_repository_index__weakptr(&index, g_repo));
- cl_git_pass(git_index_add_bypath(index, "subdirectory/test.txt"));
+ cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(p_unlink(filename.ptr));
- cl_git_pass(p_rmdir(dirname.ptr));
+ test_add_entry(index, valid_blob_id, filename.ptr, GIT_FILEMODE_BLOB);
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
git_submodule_free(sm);
- git_buf_free(&dirname);
git_buf_free(&filename);
}
@@ -165,14 +174,9 @@ void test_submodule_add__file_exists_in_index(void)
g_repo = cl_git_sandbox_init("testrepo");
- cl_git_pass(git_buf_joinpath(&name, git_repository_workdir(g_repo), "subdirectory"));
-
- cl_git_mkfile(name.ptr, "Test content");
-
- cl_git_pass(git_repository_index__weakptr(&index, g_repo));
- cl_git_pass(git_index_add_bypath(index, "subdirectory"));
+ cl_git_pass(git_repository_index(&index, g_repo));
- cl_git_pass(p_unlink(name.ptr));
+ test_add_entry(index, valid_blob_id, "subdirectory", GIT_FILEMODE_BLOB);
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);