diff options
| author | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-24 23:34:40 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-24 23:34:40 +0200 |
| commit | daacf96d101b9d2100a5028090b5af5249d8893d (patch) | |
| tree | 450942a1431c22f634f9c16916408bd80f165702 /tests | |
| parent | e1f434f8643f26d48ee8de21d715069de76b14e1 (diff) | |
| parent | 783672fa5be4f0e9dce72bcd74690258bdbac0a9 (diff) | |
| download | libgit2-daacf96d101b9d2100a5028090b5af5249d8893d.tar.gz | |
Merge pull request #3097 from libgit2/cmn/submodule-config-state
Remove run-time configuration settings from submodules
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/diff/submodules.c | 16 | ||||
| -rw-r--r-- | tests/diff/tree.c | 2 | ||||
| -rw-r--r-- | tests/submodule/init.c | 6 | ||||
| -rw-r--r-- | tests/submodule/modify.c | 203 | ||||
| -rw-r--r-- | tests/submodule/nosubs.c | 44 | ||||
| -rw-r--r-- | tests/submodule/status.c | 65 | ||||
| -rw-r--r-- | tests/submodule/submodule_helpers.c | 11 | ||||
| -rw-r--r-- | tests/submodule/update.c | 30 |
8 files changed, 141 insertions, 236 deletions
diff --git a/tests/diff/submodules.c b/tests/diff/submodules.c index e2169583b..08682cd4b 100644 --- a/tests/diff/submodules.c +++ b/tests/diff/submodules.c @@ -273,13 +273,13 @@ void test_diff_submodules__invalid_cache(void) /* create untracked file in submodule working directory */ cl_git_mkfile("submod2/sm_changed_head/new_around_here", "hello"); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_NONE); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_dirty); git_diff_free(diff); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_UNTRACKED); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_unchanged); @@ -301,7 +301,7 @@ void test_diff_submodules__invalid_cache(void) check_diff_patches(diff, expected_dirty); git_diff_free(diff); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_DIRTY); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_unchanged); @@ -312,13 +312,13 @@ void test_diff_submodules__invalid_cache(void) cl_git_pass(git_repository_index(&smindex, smrepo)); cl_git_pass(git_index_add_bypath(smindex, "file_to_modify")); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_UNTRACKED); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_UNTRACKED); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_dirty); git_diff_free(diff); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_DIRTY); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_unchanged); @@ -327,19 +327,19 @@ void test_diff_submodules__invalid_cache(void) /* commit changed index of submodule */ cl_repo_commit_from_index(NULL, smrepo, NULL, 1372350000, "Move it"); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_DIRTY); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_DIRTY); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_moved); git_diff_free(diff); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_ALL); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_ALL); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_unchanged); git_diff_free(diff); - git_submodule_set_ignore(sm, GIT_SUBMODULE_IGNORE_NONE); + git_submodule_set_ignore(g_repo, git_submodule_name(sm), GIT_SUBMODULE_IGNORE_NONE); cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, NULL, &opts)); check_diff_patches(diff, expected_moved_dirty); diff --git a/tests/diff/tree.c b/tests/diff/tree.c index 6dd17203d..977e21f5b 100644 --- a/tests/diff/tree.c +++ b/tests/diff/tree.c @@ -89,7 +89,7 @@ void test_diff_tree__0(void) } #define DIFF_OPTS(FLAGS, CTXT) \ - {GIT_DIFF_OPTIONS_VERSION, (FLAGS), GIT_SUBMODULE_IGNORE_DEFAULT, \ + {GIT_DIFF_OPTIONS_VERSION, (FLAGS), GIT_SUBMODULE_IGNORE_FALLBACK, \ {NULL,0}, NULL, NULL, (CTXT), 1} void test_diff_tree__options(void) diff --git a/tests/submodule/init.c b/tests/submodule/init.c index dbde0f284..9e0cf5753 100644 --- a/tests/submodule/init.c +++ b/tests/submodule/init.c @@ -23,10 +23,10 @@ void test_submodule_init__absolute_url(void) 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)); + cl_git_pass(git_submodule_set_url(g_repo, "testrepo", absolute_url.ptr)); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); /* verify that the .gitmodules is set with an absolute path*/ cl_assert_equal_s(absolute_url.ptr, git_submodule_url(sm)); diff --git a/tests/submodule/modify.c b/tests/submodule/modify.c index bbbb2d56e..f7a089e72 100644 --- a/tests/submodule/modify.c +++ b/tests/submodule/modify.c @@ -41,17 +41,15 @@ void test_submodule_modify__init(void) git_config_free(cfg); /* confirm no submodule data in config */ - cl_git_pass(git_repository_config(&cfg, g_repo)); - cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); - cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); - cl_git_fail(git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); + cl_git_pass(git_repository_config_snapshot(&cfg, g_repo)); + cl_git_fail_with(GIT_ENOTFOUND, git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); + cl_git_fail_with(GIT_ENOTFOUND, git_config_get_string(&str, cfg, "submodule.sm_changed_head.url")); + cl_git_fail_with(GIT_ENOTFOUND, git_config_get_string(&str, cfg, "submodule.sm_added_and_uncommited.url")); git_config_free(cfg); /* call init and see that settings are copied */ cl_git_pass(git_submodule_foreach(g_repo, init_one_submodule, NULL)); - git_submodule_reload_all(g_repo, 1); - /* confirm submodule data in config */ cl_git_pass(git_repository_config_snapshot(&cfg, g_repo)); cl_git_pass(git_config_get_string(&str, cfg, "submodule.sm_unchanged.url")); @@ -130,132 +128,85 @@ void test_submodule_modify__sync(void) git_submodule_free(sm3); } -void test_submodule_modify__edit_and_save(void) +void assert_ignore_change(git_submodule_ignore_t ignore) { - git_submodule *sm1, *sm2; - char *old_url, *old_branch; - git_submodule_ignore_t old_ignore; - git_submodule_update_t old_update; - git_repository *r2; - git_submodule_recurse_t old_fetchrecurse; - - cl_git_pass(git_submodule_lookup(&sm1, g_repo, "sm_changed_head")); - - old_url = git__strdup(git_submodule_url(sm1)); - old_branch = NULL; - - /* modify properties of submodule */ - cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL)); - cl_git_pass(git_submodule_set_branch(sm1, SM_LIBGIT2_BRANCH)); - old_ignore = git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED); - old_update = git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE); - old_fetchrecurse = git_submodule_set_fetch_recurse_submodules( - sm1, GIT_SUBMODULE_RECURSE_YES); - - cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1)); - cl_assert_equal_s(SM_LIBGIT2_BRANCH, git_submodule_branch(sm1)); - cl_assert_equal_i( - GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm1)); - cl_assert_equal_i( - GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm1)); - cl_assert_equal_i( - GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1)); - - /* revert without saving (and confirm setters return old value) */ - cl_git_pass(git_submodule_set_url(sm1, old_url)); - cl_git_pass(git_submodule_set_branch(sm1, old_branch)); - cl_assert_equal_i( - GIT_SUBMODULE_IGNORE_UNTRACKED, - git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET)); - cl_assert_equal_i( - GIT_SUBMODULE_UPDATE_REBASE, - git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET)); - cl_assert_equal_i( - GIT_SUBMODULE_RECURSE_YES, git_submodule_set_fetch_recurse_submodules( - sm1, GIT_SUBMODULE_RECURSE_RESET)); - - /* check that revert was successful */ - cl_assert_equal_s(old_url, git_submodule_url(sm1)); - cl_assert_equal_s(old_branch, git_submodule_branch(sm1)); - cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1)); - cl_assert_equal_i((int)old_update, (int)git_submodule_update_strategy(sm1)); - cl_assert_equal_i( - old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1)); - - /* modify properties of submodule (again) */ - cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL)); - cl_git_pass(git_submodule_set_branch(sm1, SM_LIBGIT2_BRANCH)); - git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED); - git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE); - git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_YES); - - /* call save */ - cl_git_pass(git_submodule_save(sm1)); - - /* attempt to "revert" values */ - git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET); - git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET); - - /* but ignore and update should NOT revert because the RESET - * should now be the newly saved value... - */ - cl_assert_equal_i( - (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1)); - cl_assert_equal_i( - (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1)); - cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1)); - - /* call reload and check that the new values are loaded */ - cl_git_pass(git_submodule_reload(sm1, 0)); - - cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1)); - cl_assert_equal_s(SM_LIBGIT2_BRANCH, git_submodule_branch(sm1)); - cl_assert_equal_i( - (int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1)); - cl_assert_equal_i( - (int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1)); - cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1)); - - /* unset branch again and verify that the property is deleted in config */ - cl_git_pass(git_submodule_set_branch(sm1, NULL)); - cl_git_pass(git_submodule_save(sm1)); - cl_git_pass(git_submodule_reload(sm1, 0)); - cl_assert_equal_s(NULL, git_submodule_branch(sm1)); - - /* open a second copy of the repo and compare submodule */ - cl_git_pass(git_repository_open(&r2, "submod2")); - cl_git_pass(git_submodule_lookup(&sm2, r2, "sm_changed_head")); - - cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm2)); - cl_assert_equal_i( - GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm2)); - cl_assert_equal_i( - GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm2)); - cl_assert_equal_i( - GIT_SUBMODULE_RECURSE_NO, git_submodule_fetch_recurse_submodules(sm2)); - - /* set fetchRecurseSubmodules on-demand */ - cl_git_pass(git_submodule_reload(sm1, 0)); - git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_ONDEMAND); - cl_assert_equal_i( - GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1)); - /* call save */ - cl_git_pass(git_submodule_save(sm1)); - cl_git_pass(git_submodule_reload(sm1, 0)); - cl_assert_equal_i( - GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1)); + git_submodule *sm; - git_submodule_free(sm1); - git_submodule_free(sm2); - git_repository_free(r2); - git__free(old_url); + cl_git_pass(git_submodule_set_ignore(g_repo, "sm_changed_head", ignore)); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert_equal_i(ignore, git_submodule_ignore(sm)); + git_submodule_free(sm); +} + +void test_submodule_modify__set_ignore(void) +{ + assert_ignore_change(GIT_SUBMODULE_IGNORE_UNTRACKED); + assert_ignore_change(GIT_SUBMODULE_IGNORE_NONE); + assert_ignore_change(GIT_SUBMODULE_IGNORE_ALL); +} + +void assert_update_change(git_submodule_update_t update) +{ + git_submodule *sm; + + cl_git_pass(git_submodule_set_update(g_repo, "sm_changed_head", update)); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert_equal_i(update, git_submodule_update_strategy(sm)); + git_submodule_free(sm); +} + +void test_submodule_modify__set_update(void) +{ + assert_update_change(GIT_SUBMODULE_UPDATE_REBASE); + assert_update_change(GIT_SUBMODULE_UPDATE_NONE); + assert_update_change(GIT_SUBMODULE_UPDATE_CHECKOUT); +} + +void assert_recurse_change(git_submodule_recurse_t recurse) +{ + git_submodule *sm; + + cl_git_pass(git_submodule_set_fetch_recurse_submodules(g_repo, "sm_changed_head", recurse)); + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert_equal_i(recurse, git_submodule_fetch_recurse_submodules(sm)); + git_submodule_free(sm); +} + +void test_submodule_modify__set_fetch_recurse_submodules(void) +{ + assert_recurse_change(GIT_SUBMODULE_RECURSE_YES); + assert_recurse_change(GIT_SUBMODULE_RECURSE_NO); + assert_recurse_change(GIT_SUBMODULE_RECURSE_ONDEMAND); +} + +void test_submodule_modify__set_branch(void) +{ + git_submodule *sm; + + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert(git_submodule_branch(sm) == NULL); + git_submodule_free(sm); + + cl_git_pass(git_submodule_set_branch(g_repo, "sm_changed_head", SM_LIBGIT2_BRANCH)); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert_equal_s(SM_LIBGIT2_BRANCH, git_submodule_branch(sm)); + git_submodule_free(sm); + + cl_git_pass(git_submodule_set_branch(g_repo, "sm_changed_head", NULL)); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert(git_submodule_branch(sm) == NULL); + git_submodule_free(sm); } -void test_submodule_modify__save_last(void) +void test_submodule_modify__set_url(void) { git_submodule *sm; - cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); - cl_git_pass(git_submodule_save(sm)); + cl_git_pass(git_submodule_set_url(g_repo, "sm_changed_head", SM_LIBGIT2_URL)); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); + cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm)); git_submodule_free(sm); } diff --git a/tests/submodule/nosubs.c b/tests/submodule/nosubs.c index e343c1620..538825c1c 100644 --- a/tests/submodule/nosubs.c +++ b/tests/submodule/nosubs.c @@ -21,19 +21,11 @@ void test_submodule_nosubs__lookup(void) cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, repo, "subrepo")); - cl_git_pass(git_submodule_reload_all(repo, 0)); - cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, repo, "subdir")); cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, repo, "subrepo")); } -void test_submodule_nosubs__immediate_reload(void) -{ - git_repository *repo = cl_git_sandbox_init("status"); - cl_git_pass(git_submodule_reload_all(repo, 0)); -} - static int fake_submod_cb(git_submodule *sm, const char *n, void *p) { GIT_UNUSED(sm); GIT_UNUSED(n); GIT_UNUSED(p); @@ -57,41 +49,7 @@ void test_submodule_nosubs__add(void) git_submodule_free(sm2); cl_git_pass(git_submodule_foreach(repo, fake_submod_cb, NULL)); - cl_git_pass(git_submodule_reload_all(repo, 0)); - - git_submodule_free(sm); -} - -void test_submodule_nosubs__reload_add_reload(void) -{ - git_repository *repo = cl_git_sandbox_init("status"); - git_submodule *sm; - - cl_git_pass(git_submodule_reload_all(repo, 0)); - - /* try one add with a reload (to make sure no errors happen) */ - - cl_git_pass(git_submodule_add_setup(&sm, repo, - "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); - - cl_git_pass(git_submodule_reload_all(repo, 0)); - - cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); - git_submodule_free(sm); - - cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); - cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); - git_submodule_free(sm); - - /* try one add without a reload (to make sure cache inval works, too) */ - - cl_git_pass(git_submodule_add_setup(&sm, repo, - "https://github.com/libgit2/libgit2.git", "libgit2-again", 1)); - cl_assert_equal_s("libgit2-again", git_submodule_name(sm)); - git_submodule_free(sm); - cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2-again")); - cl_assert_equal_s("libgit2-again", git_submodule_name(sm)); git_submodule_free(sm); } @@ -100,10 +58,8 @@ void test_submodule_nosubs__bad_gitmodules(void) git_repository *repo = cl_git_sandbox_init("status"); cl_git_mkfile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=flooble\n\n"); - cl_git_fail(git_submodule_reload_all(repo, 0)); cl_git_rewritefile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=rebase\n\n"); - cl_git_pass(git_submodule_reload_all(repo, 0)); cl_git_pass(git_submodule_lookup(NULL, repo, "foobar")); cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(NULL, repo, "subdir")); diff --git a/tests/submodule/status.c b/tests/submodule/status.c index 6efae35c6..6721ee92a 100644 --- a/tests/submodule/status.c +++ b/tests/submodule/status.c @@ -107,56 +107,47 @@ void test_submodule_status__ignore_none(void) cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_DELETED) != 0); } -static int set_sm_ignore(git_submodule *sm, const char *name, void *payload) -{ - git_submodule_ignore_t ignore = *(git_submodule_ignore_t *)payload; - GIT_UNUSED(name); - git_submodule_set_ignore(sm, ignore); - return 0; -} - void test_submodule_status__ignore_untracked(void) { unsigned int status; git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_UNTRACKED; rm_submodule("sm_unchanged"); - cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); refute_submodule_exists(g_repo, "not", GIT_EEXISTS); - status = get_submodule_status(g_repo, "sm_changed_index"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_index", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_changed_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_file", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_changed_untracked_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_untracked_file", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_missing_commits"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_missing_commits", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_added_and_uncommited"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_added_and_uncommited", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0); /* removed sm_unchanged for deleted workdir */ - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); /* now mkdir sm_unchanged to test uninitialized */ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); /* update sm_changed_head in index */ add_submodule_to_index("sm_changed_head"); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0); } @@ -166,42 +157,41 @@ void test_submodule_status__ignore_dirty(void) git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_DIRTY; rm_submodule("sm_unchanged"); - cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); refute_submodule_exists(g_repo, "not", GIT_EEXISTS); - status = get_submodule_status(g_repo, "sm_changed_index"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_index", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_changed_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_file", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_changed_untracked_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_untracked_file", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_missing_commits"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_missing_commits", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); - status = get_submodule_status(g_repo, "sm_added_and_uncommited"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_added_and_uncommited", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0); /* removed sm_unchanged for deleted workdir */ - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); /* now mkdir sm_unchanged to test uninitialized */ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); /* update sm_changed_head in index */ add_submodule_to_index("sm_changed_head"); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0); } @@ -211,42 +201,41 @@ void test_submodule_status__ignore_all(void) git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_ALL; rm_submodule("sm_unchanged"); - cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); refute_submodule_exists(g_repo, "just_a_dir", GIT_ENOTFOUND); refute_submodule_exists(g_repo, "not-submodule", GIT_EEXISTS); refute_submodule_exists(g_repo, "not", GIT_EEXISTS); - status = get_submodule_status(g_repo, "sm_changed_index"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_index", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_changed_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_file", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_changed_untracked_file"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_untracked_file", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_missing_commits"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_missing_commits", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); - status = get_submodule_status(g_repo, "sm_added_and_uncommited"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_added_and_uncommited", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); /* removed sm_unchanged for deleted workdir */ - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); /* now mkdir sm_unchanged to test uninitialized */ cl_git_pass(git_futils_mkdir("sm_unchanged", "submod2", 0755, 0)); - status = get_submodule_status(g_repo, "sm_unchanged"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_unchanged", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); /* update sm_changed_head in index */ add_submodule_to_index("sm_changed_head"); - status = get_submodule_status(g_repo, "sm_changed_head"); + cl_git_pass(git_submodule_status(&status, g_repo,"sm_changed_head", ign)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); } diff --git a/tests/submodule/submodule_helpers.c b/tests/submodule/submodule_helpers.c index 19bb04f75..2647e1514 100644 --- a/tests/submodule/submodule_helpers.c +++ b/tests/submodule/submodule_helpers.c @@ -156,21 +156,18 @@ void refute__submodule_exists( git_repository *repo, const char *name, int expected_error, const char *msg, const char *file, int line) { - git_submodule *sm; clar__assert_equal( file, line, msg, 1, "%i", - expected_error, (int)(git_submodule_lookup(&sm, repo, name))); + expected_error, (int)(git_submodule_lookup(NULL, repo, name))); } unsigned int get_submodule_status(git_repository *repo, const char *name) { - git_submodule *sm = NULL; unsigned int status = 0; - cl_git_pass(git_submodule_lookup(&sm, repo, name)); - cl_assert(sm); - cl_git_pass(git_submodule_status(&status, sm)); - git_submodule_free(sm); + assert(repo && name); + + cl_git_pass(git_submodule_status(&status, repo, name, GIT_SUBMODULE_IGNORE_FALLBACK)); return status; } diff --git a/tests/submodule/update.c b/tests/submodule/update.c index e7f1b76b8..fed6d38b3 100644 --- a/tests/submodule/update.c +++ b/tests/submodule/update.c @@ -103,7 +103,7 @@ void test_submodule_update__update_submodule(void) 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, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -114,7 +114,7 @@ void test_submodule_update__update_submodule(void) cl_git_pass(git_submodule_update(sm, 0, &update_options)); /* verify state */ - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -142,7 +142,7 @@ void test_submodule_update__update_and_init_submodule(void) /* get the submodule */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -177,7 +177,7 @@ void test_submodule_update__update_already_checked_out_submodule(void) /* Initialize and update the sub repository */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -203,7 +203,11 @@ void test_submodule_update__update_already_checked_out_submodule(void) * HEAD commit and index should be updated, but not the workdir. */ - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); + + git_submodule_free(sm); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -251,7 +255,7 @@ void test_submodule_update__update_blocks_on_dirty_wd(void) /* Initialize and update the sub repository */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -277,7 +281,11 @@ void test_submodule_update__update_blocks_on_dirty_wd(void) * HEAD commit and index should be updated, but not the workdir. */ - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); + + git_submodule_free(sm); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -324,7 +332,7 @@ void test_submodule_update__can_force_update(void) /* Initialize and update the sub repository */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | @@ -349,7 +357,11 @@ void test_submodule_update__can_force_update(void) * Verify state after checkout of parent repository. The submodule ID in the * HEAD commit and index should be updated, but not the workdir. */ - cl_git_pass(git_submodule_status(&submodule_status, sm)); + cl_git_pass(git_submodule_status(&submodule_status, g_repo, "testrepo", GIT_SUBMODULE_IGNORE_FALLBACK)); + + git_submodule_free(sm); + cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); + cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | |
