void test_diff_workdir__submodules(void) { const char *a_commit = "873585b94bdeabccea991ea5e3ec1a277895b698"; git_tree *a; git_diff_options opts = {0}; git_diff_list *diff = NULL; diff_expects exp; g_repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submod2/not_submodule/.gitted", "submod2/not_submodule/.git"); cl_fixture_cleanup("submod2_target"); a = resolve_commit_oid_to_tree(g_repo, a_commit); opts.flags = GIT_DIFF_INCLUDE_UNTRACKED | GIT_DIFF_RECURSE_UNTRACKED_DIRS | GIT_DIFF_INCLUDE_UNTRACKED_CONTENT; cl_git_pass(git_diff_workdir_to_tree(g_repo, &opts, a, &diff)); /* diff_print(stderr, diff); */ /* essentially doing: git diff 873585b94bdeabccea991ea5e3ec1a277895b698 */ memset(&exp, 0, sizeof(exp)); cl_git_pass(git_diff_foreach( diff, &exp, diff_file_fn, diff_hunk_fn, diff_line_fn)); /* the following differs from "git diff 873585" by one "untracked" file * because the diff list includes the "not_submodule/" directory which * is not displayed in the text diff. */ cl_assert_equal_i(10, exp.files); cl_assert_equal_i(0, exp.file_adds); cl_assert_equal_i(0, exp.file_dels); cl_assert_equal_i(1, exp.file_mods); cl_assert_equal_i(0, exp.file_ignored); cl_assert_equal_i(9, exp.file_untracked); /* the following numbers match "git diff 873585" exactly */ cl_assert_equal_i(9, exp.hunks); cl_assert_equal_i(33, exp.lines); cl_assert_equal_i(2, exp.line_ctxt); cl_assert_equal_i(30, exp.line_adds); cl_assert_equal_i(1, exp.line_dels); git_diff_list_free(diff); git_tree_free(a); }
static void setup_submodules(void) { g_repo = cl_git_sandbox_init("submodules"); cl_fixture_sandbox("testrepo.git"); rewrite_gitmodules(git_repository_workdir(g_repo)); p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git"); }
void test_submodule_modify__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"); }
static void setup_submodules2(void) { g_repo = cl_git_sandbox_init("submod2"); cl_fixture_sandbox("submod2_target"); p_rename("submod2_target/.gitted", "submod2_target/.git"); 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"); }
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"); cl_set_cleanup(cleanup_fixture_submodules, "testrepo.git"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
git_repository *setup_fixture_super(void) { git_repository *repo = cl_git_sandbox_init("super"); cl_fixture_sandbox("sub.git"); p_mkdir("super/sub", 0777); rewrite_gitmodules(git_repository_workdir(repo)); cl_set_cleanup(cleanup_fixture_submodules, "sub.git"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); 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"); cl_set_cleanup(cleanup_fixture_submodules, "submod2_target"); cl_git_pass(git_repository_reinit_filesystem(repo, 1)); return repo; }
// Fixture setup and teardown void test_rebase_submodule__initialize(void) { git_index *index; git_oid tree_oid, commit_id; git_tree *tree; git_commit *parent; git_object *obj; git_reference *master_ref; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; repo = cl_git_sandbox_init("rebase-submodule"); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1405694510, 0)); rewrite_gitmodules(git_repository_workdir(repo)); cl_git_pass(git_submodule_set_url(repo, "my-submodule", git_repository_path(repo))); /* We have to commit the rewritten .gitmodules file */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, ".gitmodules")); cl_git_pass(git_index_write_tree(&tree_oid, index)); cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_git_pass(git_repository_head(&master_ref, repo)); cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref))); cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent)); /* And a final reset, for good measure */ cl_git_pass(git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts)); git_index_free(index); git_object_free(obj); git_commit_free(parent); git_reference_free(master_ref); git_tree_free(tree); }