diff options
| author | Russell Belfer <rb@github.com> | 2013-03-18 17:24:13 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2013-03-18 17:24:13 -0700 |
| commit | 65025cb8934a289460bc64f82c27027c68a85be6 (patch) | |
| tree | 4b945ad28ff220ffa8500275a5e7a635749e3d11 /tests-clar/submodule | |
| parent | 5b27bf7e5bfd5c2f92a15c0058c801d49faf8403 (diff) | |
| download | libgit2-65025cb8934a289460bc64f82c27027c68a85be6.tar.gz | |
Three submodule status bug fixes
1. Fix sort order problem with submodules where "mod" was sorting
after "mod-plus" because they were being sorted as "mod/" and
"mod-plus/". This involved pushing the "contains a .git entry"
test significantly lower in the stack.
2. Reinstate behavior that a directory which contains a .git entry
will be treated as a submodule during iteration even if it is
not yet added to the .gitmodules.
3. Now that any directory containing .git is reported as submodule,
we have to be more careful checking for GIT_EEXISTS when we
do a submodule lookup, because that is the error code that is
returned by git_submodule_lookup when you try to look up a
directory containing .git that has no record in gitmodules or
the index.
Diffstat (limited to 'tests-clar/submodule')
| -rw-r--r-- | tests-clar/submodule/lookup.c | 4 | ||||
| -rw-r--r-- | tests-clar/submodule/modify.c | 2 | ||||
| -rw-r--r-- | tests-clar/submodule/status.c | 88 |
3 files changed, 86 insertions, 8 deletions
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c index 868b51e55..acf8f6462 100644 --- a/tests-clar/submodule/lookup.c +++ b/tests-clar/submodule/lookup.c @@ -13,7 +13,7 @@ void test_submodule_lookup__initialize(void) /* must create submod2_target before rewrite so prettify will work */ rewrite_gitmodules(git_repository_workdir(g_repo)); - p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); + p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git"); } void test_submodule_lookup__cleanup(void) @@ -39,7 +39,7 @@ void test_submodule_lookup__simple_lookup(void) cl_assert(sm); /* lookup git repo subdir that is not added as submodule */ - cl_assert(git_submodule_lookup(&sm, g_repo, "not_submodule") == GIT_EEXISTS); + cl_assert(git_submodule_lookup(&sm, g_repo, "not-submodule") == GIT_EEXISTS); /* lookup existing directory that is not a submodule */ cl_assert(git_submodule_lookup(&sm, g_repo, "just_a_dir") == GIT_ENOTFOUND); diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c index f6d41fdf2..94eb3738a 100644 --- a/tests-clar/submodule/modify.c +++ b/tests-clar/submodule/modify.c @@ -18,7 +18,7 @@ void test_submodule_modify__initialize(void) /* must create submod2_target before rewrite so prettify will work */ rewrite_gitmodules(git_repository_workdir(g_repo)); - p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); + p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git"); } void test_submodule_modify__cleanup(void) diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c index 3fd6960c9..282e82758 100644 --- a/tests-clar/submodule/status.c +++ b/tests-clar/submodule/status.c @@ -3,6 +3,7 @@ #include "path.h" #include "submodule_helpers.h" #include "fileops.h" +#include "iterator.h" static git_repository *g_repo = NULL; @@ -15,7 +16,8 @@ void test_submodule_status__initialize(void) /* must create submod2_target before rewrite so prettify will work */ rewrite_gitmodules(git_repository_workdir(g_repo)); - p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); + p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git"); + p_rename("submod2/not/.gitted", "submod2/not/.git"); } void test_submodule_status__cleanup(void) @@ -52,7 +54,12 @@ void test_submodule_status__ignore_none(void) cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged")); cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES)); - cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule")); + cl_assert_equal_i(GIT_ENOTFOUND, + git_submodule_lookup(&sm, g_repo, "just_a_dir")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not-submodule")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); @@ -138,7 +145,7 @@ void test_submodule_status__ignore_untracked(void) cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); - cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule")); + cl_git_fail(git_submodule_lookup(&sm, g_repo, "not-submodule")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); @@ -198,7 +205,12 @@ void test_submodule_status__ignore_dirty(void) cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); - cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule")); + cl_assert_equal_i(GIT_ENOTFOUND, + git_submodule_lookup(&sm, g_repo, "just_a_dir")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not-submodule")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); @@ -258,7 +270,12 @@ void test_submodule_status__ignore_all(void) cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); - cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule")); + cl_assert_equal_i(GIT_ENOTFOUND, + git_submodule_lookup(&sm, g_repo, "just_a_dir")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not-submodule")); + cl_assert_equal_i(GIT_EEXISTS, + git_submodule_lookup(&sm, g_repo, "not")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); @@ -305,3 +322,64 @@ void test_submodule_status__ignore_all(void) git_buf_free(&path); } + +typedef struct { + size_t counter; + const char **paths; +} submodule_expectations; + +static int confirm_submodule_status( + const char *path, unsigned int status_flags, void *payload) +{ + submodule_expectations *exp = payload; + + while (git__suffixcmp(exp->paths[exp->counter], "/") == 0) + exp->counter++; + + cl_assert_equal_s(exp->paths[exp->counter++], path); + + GIT_UNUSED(status_flags); + + return 0; +} + +void test_submodule_status__iterator(void) +{ + git_iterator *iter; + const git_index_entry *entry; + size_t i; + static const char *expected[] = { + ".gitmodules", + "just_a_dir/", + "just_a_dir/contents", + "just_a_file", + "not", + "not-submodule", + "README.txt", + "sm_added_and_uncommited", + "sm_changed_file", + "sm_changed_head", + "sm_changed_index", + "sm_changed_untracked_file", + "sm_missing_commits", + "sm_unchanged", + NULL + }; + submodule_expectations exp = { 0, expected }; + git_status_options opts = GIT_STATUS_OPTIONS_INIT; + + cl_git_pass(git_iterator_for_workdir(&iter, g_repo, + GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES, NULL, NULL)); + cl_git_pass(git_iterator_current(&entry, iter)); + + for (i = 0; entry; ++i) { + cl_assert_equal_s(expected[i], entry->path); + cl_git_pass(git_iterator_advance(&entry, iter)); + } + + git_iterator_free(iter); + + opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; + + cl_git_pass(git_status_foreach_ext(g_repo, &opts, confirm_submodule_status, &exp)); +} |
