summaryrefslogtreecommitdiff
path: root/tests-clar/submodule
diff options
context:
space:
mode:
Diffstat (limited to 'tests-clar/submodule')
-rw-r--r--tests-clar/submodule/lookup.c71
-rw-r--r--tests-clar/submodule/modify.c10
-rw-r--r--tests-clar/submodule/status.c42
-rw-r--r--tests-clar/submodule/submodule_helpers.c35
-rw-r--r--tests-clar/submodule/submodule_helpers.h3
5 files changed, 142 insertions, 19 deletions
diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c
index acf8f6462..013bbdf96 100644
--- a/tests-clar/submodule/lookup.c
+++ b/tests-clar/submodule/lookup.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "submodule_helpers.h"
#include "posix.h"
+#include "git2/sys/repository.h"
static git_repository *g_repo = NULL;
@@ -112,3 +113,73 @@ void test_submodule_lookup__foreach(void)
cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
cl_assert_equal_i(8, data.count);
}
+
+void test_submodule_lookup__lookup_even_with_orphaned_head(void)
+{
+ git_reference *orphan;
+ git_submodule *sm;
+
+ /* orphan the head */
+ cl_git_pass(git_reference_symbolic_create(
+ &orphan, g_repo, "HEAD", "refs/heads/garbage", 1));
+ git_reference_free(orphan);
+
+ /* lookup existing */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is not in HEAD */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is neither in HEAD nor index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
+ cl_assert(sm);
+
+ /* lookup git repo subdir that is not added as submodule */
+ cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule"));
+
+ /* lookup existing directory that is not a submodule */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+
+ /* lookup existing file that is not a submodule */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file"));
+
+ /* lookup non-existent item */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file"));
+}
+
+void test_submodule_lookup__lookup_even_with_missing_index(void)
+{
+ git_index *idx;
+ git_submodule *sm;
+
+ /* give the repo an empty index */
+ cl_git_pass(git_index_new(&idx));
+ git_repository_set_index(g_repo, idx);
+ git_index_free(idx);
+
+ /* lookup existing */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is not in HEAD */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
+ cl_assert(sm);
+
+ /* lookup pending change in .gitmodules that is neither in HEAD nor index */
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
+ cl_assert(sm);
+
+ /* lookup git repo subdir that is not added as submodule */
+ cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule"));
+
+ /* lookup existing directory that is not a submodule */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir"));
+
+ /* lookup existing file that is not a submodule */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file"));
+
+ /* lookup non-existent item */
+ cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file"));
+}
diff --git a/tests-clar/submodule/modify.c b/tests-clar/submodule/modify.c
index 94eb3738a..c0498ce6e 100644
--- a/tests-clar/submodule/modify.c
+++ b/tests-clar/submodule/modify.c
@@ -204,10 +204,10 @@ void test_submodule_modify__edit_and_save(void)
cl_git_pass(git_submodule_set_url(sm1, old_url));
cl_assert_equal_i(
(int)GIT_SUBMODULE_IGNORE_UNTRACKED,
- (int)git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_DEFAULT));
+ (int)git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET));
cl_assert_equal_i(
(int)GIT_SUBMODULE_UPDATE_REBASE,
- (int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT));
+ (int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET));
cl_assert_equal_i(
1, git_submodule_set_fetch_recurse_submodules(sm1, old_fetchrecurse));
@@ -228,10 +228,10 @@ void test_submodule_modify__edit_and_save(void)
cl_git_pass(git_submodule_save(sm1));
/* attempt to "revert" values */
- git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_DEFAULT);
- git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT);
+ 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 DEFAULT
+ /* but ignore and update should NOT revert because the RESET
* should now be the newly saved value...
*/
cl_assert_equal_i(
diff --git a/tests-clar/submodule/status.c b/tests-clar/submodule/status.c
index 39c83a0b7..7b29ac288 100644
--- a/tests-clar/submodule/status.c
+++ b/tests-clar/submodule/status.c
@@ -9,21 +9,12 @@ static git_repository *g_repo = NULL;
void test_submodule_status__initialize(void)
{
- g_repo = cl_git_sandbox_init("submod2");
-
- cl_fixture_sandbox("submod2_target");
- p_rename("submod2_target/.gitted", "submod2_target/.git");
-
- /* 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/.gitted", "submod2/not/.git");
+ g_repo = setup_fixture_submod2();
}
void test_submodule_status__cleanup(void)
{
- cl_git_sandbox_cleanup();
- cl_fixture_cleanup("submod2_target");
+ cleanup_fixture_submodules();
}
void test_submodule_status__unchanged(void)
@@ -326,6 +317,7 @@ void test_submodule_status__ignore_all(void)
typedef struct {
size_t counter;
const char **paths;
+ int *statuses;
} submodule_expectations;
static int confirm_submodule_status(
@@ -336,6 +328,7 @@ static int confirm_submodule_status(
while (git__suffixcmp(exp->paths[exp->counter], "/") == 0)
exp->counter++;
+ cl_assert_equal_i(exp->statuses[exp->counter], (int)status_flags);
cl_assert_equal_s(exp->paths[exp->counter++], path);
GIT_UNUSED(status_flags);
@@ -365,7 +358,24 @@ void test_submodule_status__iterator(void)
"sm_unchanged",
NULL
};
- submodule_expectations exp = { 0, expected };
+ static int expected_flags[] = {
+ GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_MODIFIED, /* ".gitmodules" */
+ 0, /* "just_a_dir/" will be skipped */
+ GIT_STATUS_CURRENT, /* "just_a_dir/contents" */
+ GIT_STATUS_CURRENT, /* "just_a_file" */
+ GIT_STATUS_IGNORED, /* "not" (contains .git) */
+ GIT_STATUS_IGNORED, /* "not-submodule" (contains .git) */
+ GIT_STATUS_CURRENT, /* "README.txt */
+ GIT_STATUS_INDEX_NEW, /* "sm_added_and_uncommited" */
+ GIT_STATUS_WT_MODIFIED, /* "sm_changed_file" */
+ GIT_STATUS_WT_MODIFIED, /* "sm_changed_head" */
+ GIT_STATUS_WT_MODIFIED, /* "sm_changed_index" */
+ GIT_STATUS_WT_MODIFIED, /* "sm_changed_untracked_file" */
+ GIT_STATUS_WT_MODIFIED, /* "sm_missing_commits" */
+ GIT_STATUS_CURRENT, /* "sm_unchanged" */
+ 0
+ };
+ submodule_expectations exp = { 0, expected, expected_flags };
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
cl_git_pass(git_iterator_for_workdir(&iter, g_repo,
@@ -376,9 +386,13 @@ void test_submodule_status__iterator(void)
git_iterator_free(iter);
- opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
+ opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
+ GIT_STATUS_OPT_INCLUDE_UNMODIFIED |
+ GIT_STATUS_OPT_INCLUDE_IGNORED |
+ GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
- cl_git_pass(git_status_foreach_ext(g_repo, &opts, confirm_submodule_status, &exp));
+ cl_git_pass(git_status_foreach_ext(
+ g_repo, &opts, confirm_submodule_status, &exp));
}
void test_submodule_status__untracked_dirs_containing_ignored_files(void)
diff --git a/tests-clar/submodule/submodule_helpers.c b/tests-clar/submodule/submodule_helpers.c
index 0c3e79f71..a7807522b 100644
--- a/tests-clar/submodule/submodule_helpers.c
+++ b/tests-clar/submodule/submodule_helpers.c
@@ -82,3 +82,38 @@ void rewrite_gitmodules(const char *workdir)
git_buf_free(&out_f);
git_buf_free(&path);
}
+
+git_repository *setup_fixture_submodules(void)
+{
+ git_repository *repo = cl_git_sandbox_init("submodules");
+
+ cl_fixture_sandbox("testrepo.git");
+
+ rewrite_gitmodules(git_repository_workdir(repo));
+ p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git");
+
+ return repo;
+}
+
+git_repository *setup_fixture_submod2(void)
+{
+ git_repository *repo = cl_git_sandbox_init("submod2");
+
+ cl_fixture_sandbox("submod2_target");
+ p_rename("submod2_target/.gitted", "submod2_target/.git");
+
+ rewrite_gitmodules(git_repository_workdir(repo));
+ p_rename("submod2/not-submodule/.gitted", "submod2/not-submodule/.git");
+ p_rename("submod2/not/.gitted", "submod2/not/.git");
+
+ return repo;
+}
+
+void cleanup_fixture_submodules(void)
+{
+ cl_git_sandbox_cleanup();
+
+ /* just try to clean up both possible extras */
+ cl_fixture_cleanup("testrepo.git");
+ cl_fixture_cleanup("submod2_target");
+}
diff --git a/tests-clar/submodule/submodule_helpers.h b/tests-clar/submodule/submodule_helpers.h
index 6b76a832e..1de15ca17 100644
--- a/tests-clar/submodule/submodule_helpers.h
+++ b/tests-clar/submodule/submodule_helpers.h
@@ -1,2 +1,5 @@
extern void rewrite_gitmodules(const char *workdir);
+extern git_repository *setup_fixture_submodules(void);
+extern git_repository *setup_fixture_submod2(void);
+extern void cleanup_fixture_submodules(void);