Skip to content

Commit 677d393

Browse files
Carson HowardCarson Howard
authored andcommitted
tests: submodule: insert index entries directly into index
1 parent ef9a774 commit 677d393

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

tests/submodule/add.c

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "repository.h"
88

99
static git_repository *g_repo = NULL;
10+
static const char *valid_blob_id = "fa49b077972391ad58037050f2a75f74e3671e92";
1011

1112
void test_submodule_add__cleanup(void)
1213
{
@@ -129,31 +130,39 @@ void test_submodule_add__url_relative_to_workdir(void)
129130
assert_submodule_url("TestGitRepository", git_repository_workdir(g_repo));
130131
}
131132

133+
static void test_add_entry(
134+
git_index *index,
135+
const char *idstr,
136+
const char *path,
137+
git_filemode_t mode)
138+
{
139+
git_index_entry entry = {{0}};
140+
141+
cl_git_pass(git_oid_fromstr(&entry.id, idstr));
142+
143+
entry.path = path;
144+
entry.mode = mode;
145+
146+
cl_git_pass(git_index_add(index, &entry));
147+
}
148+
132149
void test_submodule_add__path_exists_in_index(void)
133150
{
134151
git_index *index;
135152
git_submodule *sm;
136-
git_buf dirname = GIT_BUF_INIT;
137153
git_buf filename = GIT_BUF_INIT;
138154

139155
g_repo = cl_git_sandbox_init("testrepo");
140156

141-
cl_git_pass(git_buf_joinpath(&dirname, git_repository_workdir(g_repo), "subdirectory"));
142-
cl_git_pass(git_buf_joinpath(&filename, dirname.ptr, "test.txt"));
143-
144-
cl_git_pass(p_mkdir(dirname.ptr, 0700));
145-
cl_git_mkfile(filename.ptr, "This is some content");
157+
cl_git_pass(git_buf_joinpath(&filename, "subdirectory", "test.txt"));
146158

147-
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
148-
cl_git_pass(git_index_add_bypath(index, "subdirectory/test.txt"));
159+
cl_git_pass(git_repository_index(&index, g_repo));
149160

150-
cl_git_pass(p_unlink(filename.ptr));
151-
cl_git_pass(p_rmdir(dirname.ptr));
161+
test_add_entry(index, valid_blob_id, filename.ptr, GIT_FILEMODE_BLOB);
152162

153163
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
154164

155165
git_submodule_free(sm);
156-
git_buf_free(&dirname);
157166
git_buf_free(&filename);
158167
}
159168

@@ -165,14 +174,9 @@ void test_submodule_add__file_exists_in_index(void)
165174

166175
g_repo = cl_git_sandbox_init("testrepo");
167176

168-
cl_git_pass(git_buf_joinpath(&name, git_repository_workdir(g_repo), "subdirectory"));
169-
170-
cl_git_mkfile(name.ptr, "Test content");
171-
172-
cl_git_pass(git_repository_index__weakptr(&index, g_repo));
173-
cl_git_pass(git_index_add_bypath(index, "subdirectory"));
177+
cl_git_pass(git_repository_index(&index, g_repo));
174178

175-
cl_git_pass(p_unlink(name.ptr));
179+
test_add_entry(index, valid_blob_id, "subdirectory", GIT_FILEMODE_BLOB);
176180

177181
cl_git_fail_with(git_submodule_add_setup(&sm, g_repo, "./", "subdirectory", 1), GIT_EEXISTS);
178182

0 commit comments

Comments
 (0)