示例#1
0
文件: nosubs.c 项目: horacio/sonic-pi
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);
}
示例#2
0
void test_submodule_lookup__accessors(void)
{
	git_submodule *sm;
	const char *oid = "480095882d281ed676fe5b863569520e54a7d5c0";

	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));
	cl_assert(git_submodule_owner(sm) == g_repo);
	cl_assert_equal_s("sm_unchanged", git_submodule_name(sm));
	cl_assert(git__suffixcmp(git_submodule_path(sm), "sm_unchanged") == 0);
	cl_assert(git__suffixcmp(git_submodule_url(sm), "/submod2_target") == 0);

	cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);

	cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE);
	cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT);

	git_submodule_free(sm);


	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head"));
	cl_assert_equal_s("sm_changed_head", git_submodule_name(sm));

	cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_wd_id(sm),
		"3d9386c507f6b093471a3e324085657a3c2b4247") == 0);

	git_submodule_free(sm);


	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited"));
	cl_assert_equal_s("sm_added_and_uncommited", git_submodule_name(sm));

	cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
	cl_assert(git_submodule_head_id(sm) == NULL);
	cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0);

	git_submodule_free(sm);


	cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits"));
	cl_assert_equal_s("sm_missing_commits", git_submodule_name(sm));

	cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0);
	cl_assert(git_oid_streq(git_submodule_wd_id(sm),
		"5e4963595a9774b90524d35a807169049de8ccad") == 0);

	git_submodule_free(sm);
}
示例#3
0
static int sm_lookup_cb(git_submodule *sm, const char *name, void *payload)
{
	sm_lookup_data *data = payload;
	data->count += 1;
	cl_assert_equal_s(git_submodule_name(sm), name);
	return 0;
}
static int cb_submodule__each(git_submodule *submodule, const char *name, void *data)
{
	struct rugged_cb_payload *payload = data;
	git_repository *repo;
	git_submodule *dummy_sm;
	VALUE rb_repo;

	rb_repo = payload->rb_data;
	Data_Get_Struct(rb_repo, git_repository, repo);

	/* The submodule passed here has it's refcount decreased just after
	 * the foreach finishes. The only way to increase that refcount is
	 * to lookup the submodule.
	 *
	 * This should not return an error as the submodule name here is valid
	 * and exists, as it was just passed to this callback.
	 */
	git_submodule_lookup(&dummy_sm, repo, git_submodule_name(submodule));

	rb_protect(
		rb_yield,
		rugged_submodule_new(rb_repo, dummy_sm),
		&payload->exception
	);
	return (payload->exception) ? GIT_ERROR : GIT_OK;
}
示例#5
0
 Submodule::status Submodule::get_status() const
 {
     unsigned int res;
     if (auto err = git_submodule_status(&res, repo_, git_submodule_name(sm_.get()), git_submodule_ignore(sm_.get())))
         throw error_t("git_submodule_status failed with error code " + std::to_string(err));
     else
         return static_cast<status>(res);
 }
示例#6
0
文件: status.c 项目: ethomson/libgit2
static int print_submod(git_submodule *sm, const char *name, void *payload)
{
	int *count = payload;
	(void)name;

	if (*count == 0)
		printf("# Submodules\n");
	(*count)++;

	printf("# - submodule '%s' at %s\n",
		git_submodule_name(sm), git_submodule_path(sm));

	return 0;
}
示例#7
0
文件: nosubs.c 项目: horacio/sonic-pi
void test_submodule_nosubs__add_and_delete(void)
{
    git_repository *repo = cl_git_sandbox_init("status");
    git_submodule *sm;
    git_buf buf = GIT_BUF_INIT;

    /* note lack of calls to git_submodule_reload_all - this *should* work */

    cl_git_fail(git_submodule_lookup(NULL, repo, "libgit2"));
    cl_git_fail(git_submodule_lookup(NULL, repo, "submodules/libgit2"));

    /* create */

    cl_git_pass(git_submodule_add_setup(
                    &sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
    cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm));
    cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
    git_submodule_free(sm);

    cl_git_pass(git_futils_readbuffer(&buf, "status/.gitmodules"));
    cl_assert(strstr(buf.ptr, "[submodule \"submodules/libgit2\"]") != NULL);
    cl_assert(strstr(buf.ptr, "path = submodules/libgit2") != NULL);
    git_buf_free(&buf);

    /* lookup */

    cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
    cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
    cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm));
    cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
    git_submodule_free(sm);

    /* update name */

    cl_git_rewritefile(
        "status/.gitmodules",
        "[submodule \"libgit2\"]\n"
        "  path = submodules/libgit2\n"
        "  url = https://github.com/libgit2/libgit2.git\n");

    cl_git_pass(git_submodule_lookup(&sm, repo, "libgit2"));
    cl_assert_equal_s("libgit2", git_submodule_name(sm));
    cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm));
    git_submodule_free(sm);
    cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
    git_submodule_free(sm);

    /* revert name update */

    cl_git_rewritefile(
        "status/.gitmodules",
        "[submodule \"submodules/libgit2\"]\n"
        "  path = submodules/libgit2\n"
        "  url = https://github.com/libgit2/libgit2.git\n");

    cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
    cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
    git_submodule_free(sm);

    /* remove completely */

    cl_must_pass(p_unlink("status/.gitmodules"));
    cl_git_fail(git_submodule_lookup(&sm, repo, "libgit2"));
    cl_git_fail(git_submodule_lookup(&sm, repo, "submodules/libgit2"));
}