Example #1
0
static void get_annotated_commit(git_annotated_commit **annotated_commit, VALUE rb_repo, VALUE rb_value)
{
	git_repository *repo;
	int error;

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

	if (rb_obj_is_kind_of(rb_value, rb_cRuggedCommit)) {
		const git_commit * commit;
		const git_oid * oid;

		Data_Get_Struct(rb_value, git_commit, commit);

		oid = git_commit_id(commit);
		error = git_annotated_commit_lookup(annotated_commit, repo, oid);
	} else if (rb_obj_is_kind_of(rb_value, rb_cRuggedReference)) {
		const git_reference * ref;

		Data_Get_Struct(rb_value, git_reference, ref);

		error = git_annotated_commit_from_ref(annotated_commit, repo, ref);
	} else if (TYPE(rb_value) == T_STRING) {
		error = git_annotated_commit_from_revspec(annotated_commit, repo, StringValueCStr(rb_value));
	} else {
		rb_raise(rb_eTypeError, "Expecting a Rugged::Reference, Rugged::Commit or String instance");
	}

	rugged_exception_check(error);
}
Example #2
0
File: head.c Project: 1336/libgit2
void test_repo_head__setting_head_updates_reflog(void)
{
	git_object *tag;
	git_signature *sig;
	git_annotated_commit *annotated;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
	cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
	cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
	cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));

	test_reflog(repo, 2, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from master to haacked");
	test_reflog(repo, 1, NULL, "tags/test^{commit}", "*****@*****.**", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
	test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "*****@*****.**", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "haacked~0"));
	cl_git_pass(git_repository_set_head_detached_from_annotated(repo, annotated));

	test_reflog(repo, 0, NULL, "refs/heads/haacked", "*****@*****.**", "checkout: moving from haacked to haacked~0");

	git_annotated_commit_free(annotated);
	git_object_free(tag);
	git_signature_free(sig);
}
Example #3
0
File: mixed.c Project: 1336/libgit2
void test_reset_mixed__reflog_is_correct(void)
{
	git_buf buf = GIT_BUF_INIT;
	git_annotated_commit *annotated;
	const char *exp_msg = "commit: Updating test data so we can test inter-hunk-context";

	reflog_check(repo, "HEAD", 9, "*****@*****.**", exp_msg);
	reflog_check(repo, "refs/heads/master", 9, "*****@*****.**", exp_msg);

	/* Branch not moving, no reflog entry */
	cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
	cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
	reflog_check(repo, "HEAD", 9, "*****@*****.**", exp_msg);
	reflog_check(repo, "refs/heads/master", 9, "*****@*****.**", exp_msg);

	git_object_free(target);
	target = NULL;

	/* Moved branch, expect id in message */
	cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
	git_buf_clear(&buf);
	cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
	cl_git_pass(git_reset(repo, target, GIT_RESET_MIXED, NULL));
	reflog_check(repo, "HEAD", 10, NULL, git_buf_cstr(&buf));
	reflog_check(repo, "refs/heads/master", 10, NULL, git_buf_cstr(&buf));
	git_buf_free(&buf);

	/* Moved branch, expect revspec in message */
	exp_msg = "reset: moving to HEAD~^{commit}";
	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
	cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_MIXED, NULL));
	reflog_check(repo, "HEAD", 11, NULL, exp_msg);
	reflog_check(repo, "refs/heads/master", 11, NULL, exp_msg);
	git_annotated_commit_free(annotated);
}
Example #4
0
void test_refs_reflog_messages__setting_head_updates_reflog(void)
{
	git_object *tag;
	git_signature *sig;
	git_annotated_commit *annotated;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked")); /* 4 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/unborn"));
	cl_git_pass(git_revparse_single(&tag, g_repo, "tags/test"));
	cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(tag))); /* 3 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/heads/haacked"));        /* 2 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/tags/test"));            /* 1 */
	cl_git_pass(git_repository_set_head(g_repo, "refs/remotes/test/master"));  /* 0 */

	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 4,
		NULL, "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from master to haacked");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 3,
		NULL, "tags/test^{commit}",
		"*****@*****.**",
		"checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 2,
		"tags/test^{commit}", "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 1,
		"refs/heads/haacked", "tags/test^{commit}",
		"*****@*****.**",
		"checkout: moving from haacked to test");
	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		"tags/test^{commit}", "refs/remotes/test/master",
		"*****@*****.**",
		"checkout: moving from e90810b8df3e80c413d903f631643c716887138d to test/master");

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "haacked~0"));
	cl_git_pass(git_repository_set_head_detached_from_annotated(g_repo, annotated));

	cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0,
		NULL, "refs/heads/haacked",
		"*****@*****.**",
		"checkout: moving from be3563ae3f795b2b4353bcce3a527ad0a4f7f644 to haacked~0");

	git_annotated_commit_free(annotated);
	git_object_free(tag);
	git_signature_free(sig);
}
Example #5
0
void test_refs_branches_create__default_reflog_message(void)
{
	git_reflog *log;
	git_buf buf = GIT_BUF_INIT;
	const git_reflog_entry *entry;
	git_annotated_commit *annotated;
	git_signature *sig;
	git_config *cfg;

	cl_git_pass(git_repository_config(&cfg, repo));
	cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
	cl_git_pass(git_config_set_string(cfg, "user.email", "*****@*****.**"));
	git_config_free(cfg);

	cl_git_pass(git_signature_default(&sig, repo));

	retrieve_known_commit(&target, repo);
	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	entry = git_reflog_entry_byindex(log, 0);
	cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
	cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);

	cl_git_pass(git_reference_remove(repo, "refs/heads/" NEW_BRANCH_NAME));
	git_reference_free(branch);
	git_reflog_free(log);
	git_buf_clear(&buf);

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "e90810b8df3"));
	cl_git_pass(git_branch_create_from_annotated(&branch, repo, NEW_BRANCH_NAME, annotated, true));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	entry = git_reflog_entry_byindex(log, 0);
	cl_git_pass(git_buf_printf(&buf, "branch: Created from e90810b8df3"));
	cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);

	git_annotated_commit_free(annotated);
	git_buf_free(&buf);
	git_reflog_free(log);
	git_signature_free(sig);
}
Example #6
0
void test_reset_hard__reflog_is_correct(void)
{
    git_buf buf = GIT_BUF_INIT;
    git_annotated_commit *annotated;
    const char *exp_msg = "commit: Add a file which name should appear before the "
                          "\"subdir/\" folder while being dealt with by the treewalker";

    reflog_check(repo, "HEAD", 3, "*****@*****.**", exp_msg);
    reflog_check(repo, "refs/heads/master", 3, "*****@*****.**", exp_msg);

    /* Branch not moving, no reflog entry */
    cl_git_pass(git_revparse_single(&target, repo, "HEAD^{commit}"));
    cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
    reflog_check(repo, "HEAD", 3, "*****@*****.**", exp_msg);
    reflog_check(repo, "refs/heads/master", 3, "*****@*****.**", exp_msg);

    git_object_free(target);

    /* Moved branch, expect id in message */
    cl_git_pass(git_revparse_single(&target, repo, "HEAD~^{commit}"));
    cl_git_pass(git_buf_printf(&buf, "reset: moving to %s", git_oid_tostr_s(git_object_id(target))));
    cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
    reflog_check(repo, "HEAD", 4, NULL, git_buf_cstr(&buf));
    reflog_check(repo, "refs/heads/master", 4, NULL, git_buf_cstr(&buf));

    git_buf_free(&buf);

    /* Moved branch, expect revspec in message */
    exp_msg = "reset: moving to HEAD~^{commit}";
    cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "HEAD~^{commit}"));
    cl_git_pass(git_reset_from_annotated(repo, annotated, GIT_RESET_HARD, NULL));
    reflog_check(repo, "HEAD", 5, NULL, exp_msg);
    reflog_check(repo, "refs/heads/master", 5, NULL, exp_msg);

    git_annotated_commit_free(annotated);

}
Example #7
0
void test_refs_reflog_messages__creating_branches_default_messages(void)
{
	git_buf buf = GIT_BUF_INIT;
	git_annotated_commit *annotated;
	git_object *obj;
	git_commit *target;
	git_reference *branch1, *branch2;

	cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3"));
	cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj)));
	git_object_free(obj);

	cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));

	cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
	cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
		GIT_OID_HEX_ZERO,
		git_oid_tostr_s(git_commit_id(target)),
		g_email, git_buf_cstr(&buf));

	cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
	cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true));

	cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
		GIT_OID_HEX_ZERO,
		git_oid_tostr_s(git_commit_id(target)),
		g_email, "branch: Created from e90810b8df3");

	git_annotated_commit_free(annotated);
	git_buf_free(&buf);
	git_commit_free(target);
	git_reference_free(branch1);
	git_reference_free(branch2);
}