diff options
| author | Jameson Miller <jamill@microsoft.com> | 2014-10-20 18:07:32 -0400 |
|---|---|---|
| committer | Jameson Miller <jamill@microsoft.com> | 2014-12-22 16:35:45 -0500 |
| commit | b2ab887e1137207edb286812a3237b351ab39506 (patch) | |
| tree | 38f060dd5fbe37fc6f1f7f0a34b3cc331b806930 /tests/submodule | |
| parent | 0bb237ed89a6700a1b6b884444ff044fd1467535 (diff) | |
| download | libgit2-b2ab887e1137207edb286812a3237b351ab39506.tar.gz | |
submodule init should resolve relative url paths
Submodule init should handle relative paths in .gitmodules files
and resolve these urls when updating the git config file.
Diffstat (limited to 'tests/submodule')
| -rw-r--r-- | tests/submodule/init.c | 73 | ||||
| -rw-r--r-- | tests/submodule/repository_init.c | 1 | ||||
| -rw-r--r-- | tests/submodule/submodule_helpers.c | 14 | ||||
| -rw-r--r-- | tests/submodule/submodule_helpers.h | 1 |
4 files changed, 89 insertions, 0 deletions
diff --git a/tests/submodule/init.c b/tests/submodule/init.c new file mode 100644 index 000000000..c03bf4610 --- /dev/null +++ b/tests/submodule/init.c @@ -0,0 +1,73 @@ +#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_init__cleanup(void) +{ + cl_git_sandbox_cleanup(); +} + +void test_submodule_init__absolute_url(void) +{ + git_submodule *sm; + git_config *cfg; + git_buf absolute_url = GIT_BUF_INIT; + const char *config_url; + + g_repo = setup_fixture_submodule_simple(); + + cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); + cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git")); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + + /* write the absolute url to the .gitmodules file*/ + cl_git_pass(git_submodule_set_url(sm, absolute_url.ptr)); + + /* verify that the .gitmodules is set with an absolute path*/ + cl_assert_equal_s(absolute_url.ptr, git_submodule_url(sm)); + + /* init and verify that absolute path is written to .git/config */ + cl_git_pass(git_submodule_init(sm, false)); + + cl_git_pass(git_repository_config(&cfg, g_repo)); + + git_config_get_string(&config_url, cfg, "submodule.testrepo.url"); + cl_assert_equal_s(absolute_url.ptr, config_url); + + git_buf_free(&absolute_url); + git_config_free(cfg); +} + +void test_submodule_init__relative_url(void) +{ + git_submodule *sm; + git_config *cfg; + git_buf absolute_url = GIT_BUF_INIT; + const char *config_url; + + g_repo = setup_fixture_submodule_simple(); + + cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0); + cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git")); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + + /* verify that the .gitmodules is set with an absolute path*/ + cl_assert_equal_s("../testrepo.git", git_submodule_url(sm)); + + /* init and verify that absolute path is written to .git/config */ + cl_git_pass(git_submodule_init(sm, false)); + + cl_git_pass(git_repository_config(&cfg, g_repo)); + + git_config_get_string(&config_url, cfg, "submodule.testrepo.url"); + cl_assert_equal_s(absolute_url.ptr, config_url); + + git_buf_free(&absolute_url); + git_config_free(cfg); +} diff --git a/tests/submodule/repository_init.c b/tests/submodule/repository_init.c index e9733a658..bf1968d66 100644 --- a/tests/submodule/repository_init.c +++ b/tests/submodule/repository_init.c @@ -17,6 +17,7 @@ void test_submodule_repository_init__basic(void) g_repo = setup_fixture_submod2(); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); + cl_git_pass(git_submodule_init(sm, 0)); cl_git_pass(git_submodule_repo_init(&repo, sm, 1)); /* Verify worktree */ diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index c6d04b40a..19bb04f75 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -126,6 +126,20 @@ git_repository *setup_fixture_submod2(void) return repo; } +git_repository *setup_fixture_submodule_simple(void) +{ + git_repository *repo = cl_git_sandbox_init("submodule_simple"); + + cl_fixture_sandbox("testrepo.git"); + p_mkdir("submodule_simple/testrepo", 0777); + + cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git"); + + cl_git_pass(git_repository_reinit_filesystem(repo, 1)); + + return repo; +} + void assert__submodule_exists( git_repository *repo, const char *name, const char *msg, const char *file, int line) diff --git a/tests/submodule/submodule_helpers.h b/tests/submodule/submodule_helpers.h index 4b2620bfa..1493f245f 100644 --- a/tests/submodule/submodule_helpers.h +++ b/tests/submodule/submodule_helpers.h @@ -3,6 +3,7 @@ extern void rewrite_gitmodules(const char *workdir); /* these will automatically set a cleanup callback */ extern git_repository *setup_fixture_submodules(void); extern git_repository *setup_fixture_submod2(void); +extern git_repository *setup_fixture_submodule_simple(void); extern unsigned int get_submodule_status(git_repository *, const char *); |
