diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-11-05 00:16:51 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-11-05 00:53:41 +0300 |
commit | 790012ce782e2b97e90e52ae9fdaff098b56b999 (patch) | |
tree | 1210a2cf045a0f74fc31b63b4e0590a395110c28 /tests/submodule | |
parent | 610e553f5b43b4741b5c74d77cc1e07c88749bfc (diff) |
submodule: test updating a submodule w/ a path
Test that `git_submodule_update` can handle a submodule that is
freshly cloned and has a path differing from its name.
Diffstat (limited to 'tests/submodule')
-rw-r--r-- | tests/submodule/submodule_helpers.c | 15 | ||||
-rw-r--r-- | tests/submodule/submodule_helpers.h | 1 | ||||
-rw-r--r-- | tests/submodule/update.c | 48 |
3 files changed, 64 insertions, 0 deletions
diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index cde69d92d..4ff4b4da7 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -156,6 +156,21 @@ git_repository *setup_fixture_submodule_simple(void) return repo; } +git_repository *setup_fixture_submodule_with_path(void) +{ + git_repository *repo = cl_git_sandbox_init("submodule_with_path"); + + cl_fixture_sandbox("testrepo.git"); + p_mkdir("submodule_with_path/lib", 0777); + p_mkdir("submodule_with_path/lib/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 1191ab35b..42b14a7bc 100644 --- a/tests/submodule/submodule_helpers.h +++ b/tests/submodule/submodule_helpers.h @@ -5,6 +5,7 @@ extern git_repository *setup_fixture_submodules(void); extern git_repository *setup_fixture_submod2(void); extern git_repository *setup_fixture_submodule_simple(void); extern git_repository *setup_fixture_super(void); +extern git_repository *setup_fixture_submodule_with_path(void); extern unsigned int get_submodule_status(git_repository *, const char *); diff --git a/tests/submodule/update.c b/tests/submodule/update.c index 40d24d0a7..cbd519d81 100644 --- a/tests/submodule/update.c +++ b/tests/submodule/update.c @@ -131,6 +131,53 @@ void test_submodule_update__update_submodule(void) git_submodule_free(sm); } +void test_submodule_update__update_submodule_with_path(void) +{ + git_submodule *sm; + git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; + unsigned int submodule_status = 0; + struct update_submodule_cb_payload update_payload = { 0 }; + + g_repo = setup_fixture_submodule_with_path(); + + update_options.checkout_opts.progress_cb = checkout_progress_cb; + update_options.checkout_opts.progress_payload = &update_payload; + + update_options.fetch_opts.callbacks.update_tips = update_tips; + update_options.fetch_opts.callbacks.payload = &update_payload; + + /* get the submodule */ + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + + /* verify the initial state of the submodule */ + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | + GIT_SUBMODULE_STATUS_IN_INDEX | + GIT_SUBMODULE_STATUS_IN_CONFIG | + GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); + + /* initialize and update the submodule */ + cl_git_pass(git_submodule_init(sm, 0)); + cl_git_pass(git_submodule_update(sm, 0, &update_options)); + + /* verify state */ + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_UNSPECIFIED)); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | + GIT_SUBMODULE_STATUS_IN_INDEX | + GIT_SUBMODULE_STATUS_IN_CONFIG | + GIT_SUBMODULE_STATUS_IN_WD); + + cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); + + /* verify that the expected callbacks have been called. */ + cl_assert_equal_i(1, update_payload.checkout_progress_called); + cl_assert_equal_i(1, update_payload.update_tips_called); + + git_submodule_free(sm); +} + void test_submodule_update__update_and_init_submodule(void) { git_submodule *sm; @@ -390,3 +437,4 @@ void test_submodule_update__can_force_update(void) git_object_free(branch_commit); git_reference_free(branch_reference); } + |