summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-09-10 21:23:03 +0200
committerCarlos Martín Nieto <cmn@dwim.me>2015-09-10 21:23:03 +0200
commita3b9731ff8846870a4c5124cd57d2d797913ad1f (patch)
tree0357c4bc94266255beacefc877bfa0b21d21d628
parentf17525b0ff4aa6b0909c56dff80b8bb0b68d7be1 (diff)
downloadlibgit2-cmn/submodule-refactor.tar.gz
submodule: add a test for a renamed submdoule dircmn/submodule-refactor
-rw-r--r--tests/submodule/lookup.c55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index ecea694e5..5f1614871 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -333,3 +333,58 @@ void test_submodule_lookup__prefix_name(void)
git_submodule_free(sm);
}
+
+void test_submodule_lookup__renamed(void)
+{
+ const char *newpath = "sm_actually_changed";
+ git_index *idx;
+ sm_lookup_data data;
+
+ cl_git_pass(git_repository_index__weakptr(&idx, g_repo));
+
+ /* We're replicating 'git mv sm_unchanged sm_actually_changed' in this test */
+
+ cl_git_pass(p_rename("submod2/sm_unchanged", "submod2/sm_actually_changed"));
+
+ /* Change the path in .gitmodules and stage it*/
+ {
+ git_config *cfg;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "submod2/.gitmodules"));
+ cl_git_pass(git_config_set_string(cfg, "submodule.sm_unchanged.path", newpath));
+ git_config_free(cfg);
+
+ cl_git_pass(git_index_add_bypath(idx, ".gitmodules"));
+ }
+
+ /* Change the worktree info in the the submodule's config */
+ {
+ git_config *cfg;
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "submod2/.git/modules/sm_unchanged/config"));
+ cl_git_pass(git_config_set_string(cfg, "core.worktree", "../../../sm_actually_changed"));
+ git_config_free(cfg);
+ }
+
+ /* Rename the entry in the index */
+ {
+ const git_index_entry *e;
+ git_index_entry entry = { 0 };
+
+ e = git_index_get_bypath(idx, "sm_unchanged", 0);
+ cl_assert(e);
+ cl_assert_equal_i(GIT_FILEMODE_COMMIT, e->mode);
+
+ entry.path = newpath;
+ entry.mode = GIT_FILEMODE_COMMIT;
+ git_oid_cpy(&entry.id, &e->id);
+
+ cl_git_pass(git_index_remove(idx, "sm_unchanged", 0));
+ cl_git_pass(git_index_add(idx, &entry));
+ cl_git_pass(git_index_write(idx));
+ }
+
+ memset(&data, 0, sizeof(data));
+ cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
+ cl_assert_equal_i(8, data.count);
+}