コード例 #1
0
ファイル: init.c プロジェクト: azyx3/libgit2
void test_submodule_init__absolute_url(void)
{
    git_submodule *sm;
    git_config *cfg;
    git_buf absolute_url = GIT_BUF_INIT;
    const char *config_url;

    g_repo = setup_fixture_submodule_simple();

    cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
    cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));

    cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo"));

    /* write the absolute url to the .gitmodules file*/
    cl_git_pass(git_submodule_set_url(sm, absolute_url.ptr));

    /* verify that the .gitmodules is set with an absolute path*/
    cl_assert_equal_s(absolute_url.ptr, git_submodule_url(sm));

    /* init and verify that absolute path is written to .git/config */
    cl_git_pass(git_submodule_init(sm, false));

    cl_git_pass(git_repository_config_snapshot(&cfg, g_repo));

    cl_git_pass(git_config_get_string(&config_url, cfg, "submodule.testrepo.url"));
    cl_assert_equal_s(absolute_url.ptr, config_url);

    git_buf_free(&absolute_url);
    git_config_free(cfg);
    git_submodule_free(sm);
}
コード例 #2
0
ファイル: submodule.c プロジェクト: Arhzi/libgit2
// 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);
}
コード例 #3
0
ファイル: modify.c プロジェクト: duralog/node-sencillo
void test_submodule_modify__edit_and_save(void)
{
	git_submodule *sm1, *sm2;
	char *old_url;
	git_submodule_ignore_t old_ignore;
	git_submodule_update_t old_update;
	git_repository *r2;
	int old_fetchrecurse;

	cl_git_pass(git_submodule_lookup(&sm1, g_repo, "sm_changed_head"));

	old_url = git__strdup(git_submodule_url(sm1));

	/* modify properties of submodule */
	cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
	old_ignore = git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
	old_update = git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
	old_fetchrecurse = git_submodule_set_fetch_recurse_submodules(sm1, 1);

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
	cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));

	/* revert without saving (and confirm setters return old value) */
	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));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE,
		(int)git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_DEFAULT));
	cl_assert_equal_i(
		1, git_submodule_set_fetch_recurse_submodules(sm1, old_fetchrecurse));

	/* check that revert was successful */
	cl_assert_equal_s(old_url, git_submodule_url(sm1));
	cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i((int)old_update, (int)git_submodule_update(sm1));
	cl_assert_equal_i(
		old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1));

	/* modify properties of submodule (again) */
	cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
	git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
	git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
	git_submodule_set_fetch_recurse_submodules(sm1, 1);

	/* call save */
	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);

	/* but ignore and update should NOT revert because the DEFAULT
	 * should now be the newly saved value...
	 */
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
	cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));

	/* call reload and check that the new values are loaded */
	cl_git_pass(git_submodule_reload(sm1));

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm1));
	cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm1));

	/* open a second copy of the repo and compare submodule */
	cl_git_pass(git_repository_open(&r2, "submod2"));
	cl_git_pass(git_submodule_lookup(&sm2, r2, "sm_changed_head"));

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm2));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm2));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update(sm2));
	cl_assert_equal_i(1, git_submodule_fetch_recurse_submodules(sm2));

	git_repository_free(r2);
	git__free(old_url);
}
コード例 #4
0
/*
 *  call-seq:
 *    submodules.update(submodule, settings) -> nil
 *    submodules.update(name, settings) -> nil
 *
 *  Update settings for the given submodule in the submodule config.
 *
 *  Existing `Rugged::Submodule` instances are not updated, but can be
 *  reloaded by calling `#reload`.
 *
 *  The following options can be passed in the +settings+ Hash:
 *
 *  :url ::
 *    Updates the URL for the submodule.
 *
 *  :ignore_rule ::
 *    See `Rugged::Submodule#ignore_rule` for a list of accepted rules.
 *
 *  :update_rule ::
 *    See `Rugged::Submodule#update_rule` for a list of accepted rules.
 *
 *  :fetch_recurse_submodules ::
 *    Updates the +fetchRecurseSubmodules+ rule.
 */
static VALUE rb_git_submodule_update(VALUE self, VALUE rb_name_or_submodule, VALUE rb_settings)
{
	git_repository *repo;
	git_submodule_ignore_t ignore_rule = GIT_SUBMODULE_IGNORE_UNSPECIFIED;
	git_submodule_update_t update_rule = GIT_SUBMODULE_UPDATE_DEFAULT;
	const char *submodule_name;
	int fetch_recurse_submodules = 0;
	VALUE rb_repo = rugged_owner(self);
	VALUE rb_url, rb_fetch_recurse_submodules, rb_ignore_rule, rb_update_rule;

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	if (rb_obj_is_kind_of(rb_name_or_submodule, rb_cRuggedSubmodule))
		rb_name_or_submodule = rb_funcall(rb_name_or_submodule, rb_intern("name"), 0);

	if (TYPE(rb_name_or_submodule) != T_STRING)
		rb_raise(rb_eTypeError, "Expecting a String or Rugged::Submodule instance");

	rb_url = rb_hash_aref(rb_settings, CSTR2SYM("url"));
	rb_fetch_recurse_submodules = rb_hash_aref(rb_settings, CSTR2SYM("fetch_recurse_submodules"));
	rb_ignore_rule = rb_hash_aref(rb_settings, CSTR2SYM("ignore_rule"));
	rb_update_rule = rb_hash_aref(rb_settings, CSTR2SYM("update_rule"));

	if (!NIL_P(rb_url)) {
		Check_Type(rb_url, T_STRING);
	}

	if (!NIL_P(rb_fetch_recurse_submodules)) {
		fetch_recurse_submodules = rugged_parse_bool(rb_fetch_recurse_submodules);
	}

	if (!NIL_P(rb_ignore_rule)) {
		ignore_rule = rb_git_subm_ignore_rule_toC(rb_ignore_rule);
	}

	if (!NIL_P(rb_update_rule)) {
		update_rule = rb_git_subm_update_rule_toC(rb_update_rule);
	}

	submodule_name = StringValueCStr(rb_name_or_submodule);

	if (!NIL_P(rb_url)) {
		rugged_exception_check(
			git_submodule_set_url(repo,
				submodule_name,
				StringValueCStr(rb_url)
			)
		);
	}

	if (!NIL_P(rb_fetch_recurse_submodules)) {
		rugged_exception_check(
			git_submodule_set_fetch_recurse_submodules(repo,
				submodule_name,
				fetch_recurse_submodules
			)
		);
	}

	if (!NIL_P(rb_ignore_rule)) {
		rugged_exception_check(
			git_submodule_set_ignore(repo,
				submodule_name,
				ignore_rule
			)
		);
	}

	if (!NIL_P(rb_update_rule)) {
		rugged_exception_check(
			git_submodule_set_update(repo,
				submodule_name,
				update_rule
			)
		);
	}

	return Qnil;
}
コード例 #5
0
ファイル: modify.c プロジェクト: CODECOMMUNITY/libgit2
void test_submodule_modify__edit_and_save(void)
{
	git_submodule *sm1, *sm2;
	char *old_url, *old_branch;
	git_submodule_ignore_t old_ignore;
	git_submodule_update_t old_update;
	git_repository *r2;
	git_submodule_recurse_t old_fetchrecurse;

	cl_git_pass(git_submodule_lookup(&sm1, g_repo, "sm_changed_head"));

	old_url = git__strdup(git_submodule_url(sm1));
	old_branch = NULL;

	/* modify properties of submodule */
	cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
	cl_git_pass(git_submodule_set_branch(sm1, SM_LIBGIT2_BRANCH));
	old_ignore = git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
	old_update = git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
	old_fetchrecurse = git_submodule_set_fetch_recurse_submodules(
		sm1, GIT_SUBMODULE_RECURSE_YES);

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
	cl_assert_equal_s(SM_LIBGIT2_BRANCH, git_submodule_branch(sm1));
	cl_assert_equal_i(
		GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm1));
	cl_assert_equal_i(
		GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm1));
	cl_assert_equal_i(
		GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));

	/* revert without saving (and confirm setters return old value) */
	cl_git_pass(git_submodule_set_url(sm1, old_url));
	cl_git_pass(git_submodule_set_branch(sm1, old_branch));
	cl_assert_equal_i(
		GIT_SUBMODULE_IGNORE_UNTRACKED,
		git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_RESET));
	cl_assert_equal_i(
		GIT_SUBMODULE_UPDATE_REBASE,
		git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_RESET));
	cl_assert_equal_i(
		GIT_SUBMODULE_RECURSE_YES, git_submodule_set_fetch_recurse_submodules(
			sm1, GIT_SUBMODULE_RECURSE_RESET));

	/* check that revert was successful */
	cl_assert_equal_s(old_url, git_submodule_url(sm1));
	cl_assert_equal_s(old_branch, git_submodule_branch(sm1));
	cl_assert_equal_i((int)old_ignore, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i((int)old_update, (int)git_submodule_update_strategy(sm1));
	cl_assert_equal_i(
		old_fetchrecurse, git_submodule_fetch_recurse_submodules(sm1));

	/* modify properties of submodule (again) */
	cl_git_pass(git_submodule_set_url(sm1, SM_LIBGIT2_URL));
	cl_git_pass(git_submodule_set_branch(sm1, SM_LIBGIT2_BRANCH));
	git_submodule_set_ignore(sm1, GIT_SUBMODULE_IGNORE_UNTRACKED);
	git_submodule_set_update(sm1, GIT_SUBMODULE_UPDATE_REBASE);
	git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_YES);

	/* call save */
	cl_git_pass(git_submodule_save(sm1));

	/* attempt to "revert" values */
	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 RESET
	 * should now be the newly saved value...
	 */
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1));
	cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));

	/* call reload and check that the new values are loaded */
	cl_git_pass(git_submodule_reload(sm1, 0));

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm1));
	cl_assert_equal_s(SM_LIBGIT2_BRANCH, git_submodule_branch(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_IGNORE_UNTRACKED, (int)git_submodule_ignore(sm1));
	cl_assert_equal_i(
		(int)GIT_SUBMODULE_UPDATE_REBASE, (int)git_submodule_update_strategy(sm1));
	cl_assert_equal_i(GIT_SUBMODULE_RECURSE_YES, git_submodule_fetch_recurse_submodules(sm1));

	/* unset branch again and verify that the property is deleted in config */
	cl_git_pass(git_submodule_set_branch(sm1, NULL));
	cl_git_pass(git_submodule_save(sm1));
	cl_git_pass(git_submodule_reload(sm1, 0));
	cl_assert_equal_s(NULL, git_submodule_branch(sm1));

	/* open a second copy of the repo and compare submodule */
	cl_git_pass(git_repository_open(&r2, "submod2"));
	cl_git_pass(git_submodule_lookup(&sm2, r2, "sm_changed_head"));

	cl_assert_equal_s(SM_LIBGIT2_URL, git_submodule_url(sm2));
	cl_assert_equal_i(
		GIT_SUBMODULE_IGNORE_UNTRACKED, git_submodule_ignore(sm2));
	cl_assert_equal_i(
		GIT_SUBMODULE_UPDATE_REBASE, git_submodule_update_strategy(sm2));
	cl_assert_equal_i(
		GIT_SUBMODULE_RECURSE_NO, git_submodule_fetch_recurse_submodules(sm2));

	/* set fetchRecurseSubmodules on-demand */
	cl_git_pass(git_submodule_reload(sm1, 0));
	git_submodule_set_fetch_recurse_submodules(sm1, GIT_SUBMODULE_RECURSE_ONDEMAND);
	cl_assert_equal_i(
		GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));
	/* call save */
	cl_git_pass(git_submodule_save(sm1));
	cl_git_pass(git_submodule_reload(sm1, 0));
	cl_assert_equal_i(
		GIT_SUBMODULE_RECURSE_ONDEMAND, git_submodule_fetch_recurse_submodules(sm1));

	git_submodule_free(sm1);
	git_submodule_free(sm2);
	git_repository_free(r2);
	git__free(old_url);
}