diff options
Diffstat (limited to 'tests/submodule')
| -rw-r--r-- | tests/submodule/add.c | 25 | ||||
| -rw-r--r-- | tests/submodule/repository_init.c | 40 | ||||
| -rw-r--r-- | tests/submodule/submodule_helpers.c | 4 |
3 files changed, 66 insertions, 3 deletions
diff --git a/tests/submodule/add.c b/tests/submodule/add.c index af81713f1..10717809e 100644 --- a/tests/submodule/add.c +++ b/tests/submodule/add.c @@ -2,6 +2,7 @@ #include "posix.h" #include "path.h" #include "submodule_helpers.h" +#include "fileops.h" static git_repository *g_repo = NULL; @@ -29,6 +30,10 @@ static void assert_submodule_url(const char* name, const char *url) void test_submodule_add__url_absolute(void) { git_submodule *sm; + git_config *cfg; + git_repository *repo; + const char *worktree_path; + git_buf dot_git_content = GIT_BUF_INIT; g_repo = setup_fixture_submod2(); @@ -51,6 +56,21 @@ void test_submodule_add__url_absolute(void) cl_assert(git_path_isfile("submod2/.git/modules/" "sm_libgit2" "/HEAD")); assert_submodule_url("sm_libgit2", "https://github.com/libgit2/libgit2.git"); + cl_git_pass(git_repository_open(&repo, "submod2/" "sm_libgit2")); + + /* Verify worktree path is relative */ + cl_git_pass(git_repository_config(&cfg, repo)); + cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree")); + cl_assert_equal_s("../../../sm_libgit2/", worktree_path); + + /* Verify gitdir path is relative */ + cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_libgit2" "/.git")); + cl_assert_equal_s("gitdir: ../.git/modules/sm_libgit2/", dot_git_content.ptr); + + git_config_free(cfg); + git_repository_free(repo); + git_buf_free(&dot_git_content); + /* add a submodule not using a gitlink */ cl_git_pass( @@ -68,13 +88,16 @@ void test_submodule_add__url_relative(void) { git_submodule *sm; git_remote *remote; + git_strarray problems = {0}; /* default remote url is https://github.com/libgit2/false.git */ g_repo = cl_git_sandbox_init("testrepo2"); /* make sure we don't default to origin - rename origin -> test_remote */ cl_git_pass(git_remote_load(&remote, g_repo, "origin")); - cl_git_pass(git_remote_rename(remote, "test_remote", NULL, NULL)); + cl_git_pass(git_remote_rename(&problems, remote, "test_remote")); + cl_assert_equal_i(0, problems.count); + git_strarray_free(&problems); cl_git_fail(git_remote_load(&remote, g_repo, "origin")); git_remote_free(remote); diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c new file mode 100644 index 000000000..24b47aff8 --- /dev/null +++ b/tests/submodule/repository_init.c @@ -0,0 +1,40 @@ +#include "clar_libgit2.h" +#include "posix.h" +#include "path.h" +#include "submodule_helpers.h" +#include "fileops.h" + +static git_repository *g_repo = NULL; + +void test_submodule_repository_init__basic(void) +{ + git_submodule *sm; + git_repository *repo; + git_config *cfg; + const char *worktree_path; + git_buf dot_git_content = GIT_BUF_INIT; + + g_repo = setup_fixture_submod2(); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); + cl_git_pass(git_submodule_repo_init(&repo, sm, 1)); + + /* Verify worktree */ + cl_git_pass(git_repository_config(&cfg, repo)); + cl_git_pass(git_config_get_string(&worktree_path, cfg, "core.worktree")); + cl_assert_equal_s("../../../sm_gitmodules_only/", worktree_path); + + /* Verify gitlink */ + cl_git_pass(git_futils_readbuffer(&dot_git_content, "submod2/" "sm_gitmodules_only" "/.git")); + cl_assert_equal_s("gitdir: ../.git/modules/sm_gitmodules_only/", dot_git_content.ptr); + + cl_assert(git_path_isfile("submod2/" "sm_gitmodules_only" "/.git")); + + cl_assert(git_path_isdir("submod2/.git/modules")); + cl_assert(git_path_isdir("submod2/.git/modules/" "sm_gitmodules_only")); + cl_assert(git_path_isfile("submod2/.git/modules/" "sm_gitmodules_only" "/HEAD")); + + git_config_free(cfg); + git_repository_free(repo); + git_buf_free(&dot_git_content); +} diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index 50aa97568..c6d04b40a 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -19,8 +19,8 @@ void rewrite_gitmodules(const char *workdir) cl_git_pass(git_buf_joinpath(&in_f, workdir, "gitmodules")); cl_git_pass(git_buf_joinpath(&out_f, workdir, ".gitmodules")); - cl_assert((in = fopen(in_f.ptr, "r")) != NULL); - cl_assert((out = fopen(out_f.ptr, "w")) != NULL); + cl_assert((in = fopen(in_f.ptr, "rb")) != NULL); + cl_assert((out = fopen(out_f.ptr, "wb")) != NULL); while (fgets(line, sizeof(line), in) != NULL) { char *scan = line; |
