コード例 #1
0
ファイル: parse.c プロジェクト: CodeSmithyIDE/libgit2
static void assert_commit_parses(const char *data, size_t datalen,
	const char *expected_treeid,
	const char *expected_author,
	const char *expected_committer,
	const char *expected_encoding,
	const char *expected_message,
	size_t expected_parents)
{
	git_commit *commit;
	if (!datalen)
		datalen = strlen(data);
	cl_git_pass(git_object__from_raw((git_object **) &commit, data, datalen, GIT_OBJECT_COMMIT));

	if (expected_author) {
		git_signature *author;
		cl_git_pass(git_signature_from_buffer(&author, expected_author));
		cl_assert(git_signature__equal(author, commit->author));
		cl_assert_equal_s(author->name, commit->author->name);
		cl_assert_equal_s(author->email, commit->author->email);
		cl_assert_equal_i(author->when.time, commit->author->when.time);
		cl_assert_equal_i(author->when.offset, commit->author->when.offset);
		cl_assert_equal_i(author->when.sign, commit->author->when.sign);
		git_signature_free(author);
	}

	if (expected_committer) {
		git_signature *committer;
		cl_git_pass(git_signature_from_buffer(&committer, expected_committer));
		cl_assert_equal_s(committer->name, commit->committer->name);
		cl_assert_equal_s(committer->email, commit->committer->email);
		cl_assert_equal_i(committer->when.time, commit->committer->when.time);
		cl_assert_equal_i(committer->when.offset, commit->committer->when.offset);
		cl_assert_equal_i(committer->when.sign, commit->committer->when.sign);
		git_signature_free(committer);
	}

	if (expected_encoding)
		cl_assert_equal_s(commit->message_encoding, expected_encoding);
	else
		cl_assert_equal_p(commit->message_encoding, NULL);

	if (expected_message)
		cl_assert_equal_s(commit->raw_message, expected_message);
	else
		cl_assert_equal_p(commit->message_encoding, NULL);

	if (expected_treeid) {
		git_oid tree_oid;
		cl_git_pass(git_oid_fromstr(&tree_oid, expected_treeid));
		cl_assert_equal_oid(&tree_oid, &commit->tree_id);
	}

	cl_assert_equal_i(commit->parent_ids.size, expected_parents);

	git_object__free(&commit->object);
}
コード例 #2
0
ファイル: new.c プロジェクト: 1336/libgit2
void test_repo_new__has_nothing(void)
{
	git_repository *repo;

	cl_git_pass(git_repository_new(&repo));
	cl_assert_equal_b(true, git_repository_is_bare(repo));
	cl_assert_equal_p(NULL, git_repository_path(repo));
	cl_assert_equal_p(NULL, git_repository_workdir(repo));
	git_repository_free(repo);
}
コード例 #3
0
ファイル: merge.c プロジェクト: mikeando/agb
void test_core_merge__basic_iterator_all(void) {
	AGBMergeIterator * it = agb_merge__create_iterator(head_tree, branch_tree, base_tree, agb_merge_iterator_options_ALL_ENTRIES);
	cl_assert(it!=NULL);
    AGBMergeEntry * mergeEntry = agb_merge_entry_from_iterator(it);


    // Since everything should be sorted alphabetically our first entry in the iterator should be
	// created_in_a.txt, which should only occur in the head side.
	//
	char hexid[GIT_OID_HEXSZ+1] = {0};
	char hexid2[GIT_OID_HEXSZ+1] = {0};

	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(head_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_LOCAL)));
	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(branch_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_REMOTE)));
	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(base_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_BASE)));

	cl_assert_equal_s("README.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_s("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL)));
	cl_assert_equal_s("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE)));
	cl_assert_equal_s("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE)));

	cl_assert_equal_i(0, agb_merge_iterator_next(it) );
    mergeEntry = agb_merge_entry_from_iterator(it);
    cl_assert_equal_s("created_in_a.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_s("6a8f9dc8fbbc0a9c632ff7f58b419ab09f7d49d9", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL)));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE));

	cl_assert_equal_i(0, agb_merge_iterator_next(it) );
    mergeEntry = agb_merge_entry_from_iterator(it);

    cl_assert_equal_s("created_in_b.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL));
	cl_assert_equal_s("21a97ca7942380e581d314d80aed559be2150219", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE)));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE));

	cl_assert_equal_i(0, agb_merge_iterator_next(it) );
    mergeEntry = agb_merge_entry_from_iterator(it);
    cl_assert_equal_s("created_in_root.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL)));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE)));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE)));

	cl_assert_equal_i(0, agb_merge_iterator_next(it) );
    mergeEntry = agb_merge_entry_from_iterator(it);
    cl_assert_equal_s("created_in_root_2.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL)));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE)));
	cl_assert_equal_s("0867712ecec02144b5bf4ee2a59deb0f42b49a53", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE)));

	cl_assert_equal_i(1, agb_merge_iterator_next(it) );

	agb_merge_iterator_free(it);
}
コード例 #4
0
ファイル: remotes.c プロジェクト: Angolier/sonic-pi
void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void)
{
	git_remote *remote = NULL;

	cl_assert_equal_i(
		GIT_EINVALIDSPEC,
		git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2"));
	cl_assert_equal_p(remote, NULL);

	cl_assert_equal_i(
		GIT_EINVALIDSPEC,
		git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2"));
	cl_assert_equal_p(remote, NULL);
}
コード例 #5
0
ファイル: stream.c プロジェクト: Angeldude/sonic-pi
void test_core_stream__register_tls(void)
{
	git_stream *stream;
	int error;

	ctor_called = 0;
	cl_git_pass(git_stream_register_tls(test_ctor));
	cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
	cl_assert_equal_i(1, ctor_called);
	cl_assert_equal_p(&test_stream, stream);

	ctor_called = 0;
	stream = NULL;
	cl_git_pass(git_stream_register_tls(NULL));
	error = git_tls_stream_new(&stream, "localhost", "443");

	/* We don't have arbitrary TLS stream support on Windows
	 * or when openssl support is disabled (except on OSX
	 * with Security framework).
	 */
#if defined(GIT_WIN32) || \
	(!defined(GIT_SECURE_TRANSPORT) && !defined(GIT_OPENSSL))
	cl_git_fail_with(-1, error);
#else
	cl_git_pass(error);
#endif

	cl_assert_equal_i(0, ctor_called);
	cl_assert(&test_stream != stream);

	git_stream_free(stream);
}
コード例 #6
0
ファイル: deprecated.c プロジェクト: ethomson/libgit2
void test_stream_deprecated__register_tls(void)
{
	git_stream *stream;
	int error;

	ctor_called = 0;
	cl_git_pass(git_stream_register_tls(test_stream_init));
	cl_git_pass(git_tls_stream_new(&stream, "localhost", "443"));
	cl_assert_equal_i(1, ctor_called);
	cl_assert_equal_p(&test_stream, stream);

	ctor_called = 0;
	stream = NULL;
	cl_git_pass(git_stream_register_tls(NULL));
	error = git_tls_stream_new(&stream, "localhost", "443");

	/*
	 * We don't have TLS support enabled, or we're on Windows,
	 * which has no arbitrary TLS stream support.
	 */
#if defined(GIT_WIN32) || !defined(GIT_HTTPS)
	cl_git_fail_with(-1, error);
#else
	cl_git_pass(error);
#endif

	cl_assert_equal_i(0, ctor_called);
	cl_assert(&test_stream != stream);

	git_stream_free(stream);
}
コード例 #7
0
ファイル: insteadof.c プロジェクト: 1336/libgit2
void test_remote_insteadof__pushurl_insteadof_not_applicable(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_lookup(&g_remote, g_repo, REMOTE_ORIGIN));

	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
}
コード例 #8
0
ファイル: getters.c プロジェクト: 1336/libgit2
void test_blame_getters__byline(void)
{
	const git_blame_hunk *h = git_blame_get_hunk_byline(g_blame, 5);
	cl_assert(h);
	cl_assert_equal_s(h->orig_path, "b");

	h = git_blame_get_hunk_byline(g_blame, 95);
	cl_assert_equal_p(h, NULL);
}
コード例 #9
0
ファイル: sample.c プロジェクト: phkelley/clar
void test_sample__3(void)
{
	const char *actual = "expected";
	int value = 100;

	cl_assert_equal_s("expected", actual);
	cl_assert_equal_i(100, value);
	cl_assert_equal_b(1, value);       /* equal as booleans */
	cl_assert_equal_p(actual, actual); /* pointers to same object */
}
コード例 #10
0
ファイル: remotes.c プロジェクト: Angolier/sonic-pi
void assert_cannot_create_remote(const char *name, int expected_error)
{
	git_remote *remote = NULL;

	cl_git_fail_with(
		git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"),
		expected_error);

	cl_assert_equal_p(remote, NULL);
}
コード例 #11
0
ファイル: tree.c プロジェクト: Kat7984/libgit2
void test_checkout_tree__removes_conflicts_only_by_pathscope(void)
{
	git_oid commit_id;
	git_commit *commit;
	git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
	git_index *index;
	const char *path = "executable.txt";
	
	cl_git_pass(git_oid_fromstr(&commit_id, "afe4393b2b2a965f06acf2ca9658eaa01e0cd6b6"));
	cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));

	opts.checkout_strategy = GIT_CHECKOUT_FORCE;
	opts.paths.count = 1;
	opts.paths.strings = (char **)&path;

	cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts));

	cl_git_pass(git_repository_index(&index, g_repo));
	cl_git_pass(git_index_remove(index, "executable.txt", 0));

	create_conflict("executable.txt");
	cl_git_mkfile("testrepo/executable.txt", "This is the conflict file.\n");

	create_conflict("other.txt");
	cl_git_mkfile("testrepo/other.txt", "This is another conflict file.\n");

	git_index_write(index);

	cl_git_pass(git_checkout_tree(g_repo, (const git_object *)commit, &opts));

	cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 1));
	cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 2));
	cl_assert_equal_p(NULL, git_index_get_bypath(index, "executable.txt", 3));

	cl_assert(git_index_get_bypath(index, "other.txt", 1) != NULL);
	cl_assert(git_index_get_bypath(index, "other.txt", 2) != NULL);
	cl_assert(git_index_get_bypath(index, "other.txt", 3) != NULL);

	cl_assert(git_path_exists("testrepo/other.txt"));

	git_commit_free(commit);
	git_index_free(index);
}
コード例 #12
0
ファイル: insteadof.c プロジェクト: 1336/libgit2
void test_remote_insteadof__anonymous_remote(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture(REPO_PATH)));
	cl_git_pass(git_remote_create_anonymous(&g_remote, g_repo,
	    "http://example.com/libgit2/libgit2"));

	cl_assert_equal_s(
	    git_remote_url(g_remote),
	    "http://github.com/libgit2/libgit2");
	cl_assert_equal_p(git_remote_pushurl(g_remote), NULL);
}
コード例 #13
0
ファイル: buffer.c プロジェクト: Angeldude/sonic-pi
void test_core_buffer__dont_grow_borrowed(void)
{
	const char *somestring = "blah blah";
	git_buf buf = GIT_BUF_INIT;

	git_buf_attach_notowned(&buf, somestring, strlen(somestring) + 1);
	cl_assert_equal_p(somestring, buf.ptr);
	cl_assert_equal_i(0, buf.asize);
	cl_assert_equal_i(strlen(somestring) + 1, buf.size);

	cl_git_fail_with(GIT_EINVALID, git_buf_grow(&buf, 1024));
}
コード例 #14
0
ファイル: oidmap.c プロジェクト: CodeSmithyIDE/libgit2
void test_core_oidmap__hash_collision(void)
{
	git_oidmap *map;
	oidmap_item items[NITEMS];
	uint32_t i, j;

	for (i = 0; i < NITEMS; ++i) {
		uint32_t segment = i / 8;
		int modi = i - (segment * 8);

		items[i].extra = i;

		for (j = 0; j < GIT_OID_RAWSZ / 4; ++j) {
			items[i].oid.id[j * 4    ] = (unsigned char)modi;
			items[i].oid.id[j * 4 + 1] = (unsigned char)(modi >> 8);
			items[i].oid.id[j * 4 + 2] = (unsigned char)(modi >> 16);
			items[i].oid.id[j * 4 + 3] = (unsigned char)(modi >> 24);
		}

		items[i].oid.id[ 8] = (unsigned char)i;
		items[i].oid.id[ 9] = (unsigned char)(i >> 8);
		items[i].oid.id[10] = (unsigned char)(i >> 16);
		items[i].oid.id[11] = (unsigned char)(i >> 24);
	}

	map = git_oidmap_alloc();
	cl_assert(map != NULL);

	for (i = 0; i < NITEMS; ++i) {
		size_t pos;
		int ret;

		pos = git_oidmap_lookup_index(map, &items[i].oid);
		cl_assert(!git_oidmap_valid_index(map, pos));

		pos = git_oidmap_put(map, &items[i].oid, &ret);
		cl_assert(ret != 0);

		git_oidmap_set_value_at(map, pos, &items[i]);
	}


	for (i = 0; i < NITEMS; ++i) {
		size_t pos;

		pos = git_oidmap_lookup_index(map, &items[i].oid);
		cl_assert(git_oidmap_valid_index(map, pos));

		cl_assert_equal_p(git_oidmap_value_at(map, pos), &items[i]);
	}

	git_oidmap_free(map);
}
コード例 #15
0
ファイル: merge.c プロジェクト: mikeando/agb
void test_core_merge__basic_iterator(void) {
	AGBMergeIterator * it = agb_merge__create_iterator(head_tree, branch_tree, base_tree, agb_merge_iterator_options_NONE);
	cl_assert(it!=NULL);

	// Since everything should be sorted alphabetically our first entry in the iterator should be
	// created_in_a.txt, which should only occur in the head side.
	//
	char hexid[GIT_OID_HEXSZ+1] = {0};
	char hexid2[GIT_OID_HEXSZ+1] = {0};

    AGBMergeEntry * mergeEntry = agb_merge_entry_from_iterator(it);

	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(head_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_LOCAL)));
	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(branch_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_REMOTE)));
	cl_assert_equal_s(git_oid_tostr(hexid2, GIT_OID_HEXSZ+1, git_tree_id(base_tree)), git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_iterator_tree_id(it,AGB_MERGE_BASE)));

	//TODO: How do we handle the case with zero entries.
	//We probably need a agb_merge_iterator_is_valid(it)
	//We can then use it like:
	//
	//
	cl_assert_equal_s("created_in_a.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_s("6a8f9dc8fbbc0a9c632ff7f58b419ab09f7d49d9", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL)));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE));

	cl_assert_equal_i(0, agb_merge_iterator_next(it) );
    mergeEntry = agb_merge_entry_from_iterator(it);

    cl_assert_equal_s("created_in_b.txt", agb_merge_entry_name(mergeEntry));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_LOCAL));
	cl_assert_equal_s("21a97ca7942380e581d314d80aed559be2150219", git_oid_tostr(hexid,GIT_OID_HEXSZ+1,agb_merge_entry_id(mergeEntry,AGB_MERGE_REMOTE)));
	cl_assert_equal_p(NULL, agb_merge_entry_id(mergeEntry,AGB_MERGE_BASE));

	cl_assert_equal_i(1, agb_merge_iterator_next(it) );

	agb_merge_iterator_free(it);
}
コード例 #16
0
ファイル: index.c プロジェクト: DavidMolinari/sonic-pi
void test_diff_index__checks_options_version(void)
{
	const char *a_commit = "26a125ee1bf";
	git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
	git_diff *diff = NULL;
	const git_error *err;

	opts.version = 0;
	cl_git_fail(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
	err = giterr_last();
	cl_assert_equal_i(GITERR_INVALID, err->klass);
	cl_assert_equal_p(diff, NULL);

	giterr_clear();
	opts.version = 1024;
	cl_git_fail(git_diff_tree_to_index(&diff, g_repo, a, NULL, &opts));
	err = giterr_last();
	cl_assert_equal_i(GITERR_INVALID, err->klass);
	cl_assert_equal_p(diff, NULL);

	git_tree_free(a);
}
コード例 #17
0
ファイル: conflicts.c プロジェクト: KTXSoftware/libgit2
void test_index_conflicts__add_removes_stage_zero(void)
{
	git_index_entry staged, ancestor_entry, our_entry, their_entry;
	const git_index_entry *conflict_entry[3];

	cl_assert(git_index_entrycount(repo_index) == 8);

	memset(&staged, 0x0, sizeof(git_index_entry));
	memset(&ancestor_entry, 0x0, sizeof(git_index_entry));
	memset(&our_entry, 0x0, sizeof(git_index_entry));
	memset(&their_entry, 0x0, sizeof(git_index_entry));

	staged.path = "test-one.txt";
	staged.mode = 0100644;
	git_oid_fromstr(&staged.id, TEST_STAGED_OID);
	cl_git_pass(git_index_add(repo_index, &staged));
	cl_assert(git_index_entrycount(repo_index) == 9);

	ancestor_entry.path = "test-one.txt";
	ancestor_entry.mode = 0100644;
	GIT_IDXENTRY_STAGE_SET(&ancestor_entry, 3);
	git_oid_fromstr(&ancestor_entry.id, TEST_ANCESTOR_OID);

	our_entry.path = "test-one.txt";
	our_entry.mode = 0100644;
	GIT_IDXENTRY_STAGE_SET(&our_entry, 1);
	git_oid_fromstr(&our_entry.id, TEST_OUR_OID);

	their_entry.path = "test-one.txt";
	their_entry.mode = 0100644;
	GIT_IDXENTRY_STAGE_SET(&their_entry, 2);
	git_oid_fromstr(&their_entry.id, TEST_THEIR_OID);

	cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry));

	cl_assert(git_index_entrycount(repo_index) == 11);

	cl_assert_equal_p(NULL, git_index_get_bypath(repo_index, "test-one.txt", 0));

	cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, "test-one.txt"));

	cl_assert_equal_oid(&ancestor_entry.id, &conflict_entry[0]->id);
	cl_assert_equal_i(1, git_index_entry_stage(conflict_entry[0]));
	cl_assert_equal_oid(&our_entry.id, &conflict_entry[1]->id);
	cl_assert_equal_i(2, git_index_entry_stage(conflict_entry[1]));
	cl_assert_equal_oid(&their_entry.id, &conflict_entry[2]->id);
	cl_assert_equal_i(3, git_index_entry_stage(conflict_entry[2]));
}