Unnamed: 0
int64 0
0
| repo_id
stringlengths 5
186
| file_path
stringlengths 15
223
| content
stringlengths 1
32.8M
⌀ |
---|---|---|---|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/iterator/index.c
|
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "futils.h"
#include "iterator_helpers.h"
#include "../submodule/submodule_helpers.h"
#include <stdarg.h>
static git_repository *g_repo;
void test_iterator_index__initialize(void)
{
}
void test_iterator_index__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void index_iterator_test(
const char *sandbox,
const char *start,
const char *end,
git_iterator_flag_t flags,
int expected_count,
const char **expected_names,
const char **expected_oids)
{
git_index *index;
git_iterator *i;
const git_index_entry *entry;
int error, count = 0, caps;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init(sandbox);
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
iter_opts.flags = flags;
iter_opts.start = start;
iter_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &iter_opts));
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count], entry->path);
if (expected_oids != NULL) {
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected_oids[count]));
cl_assert_equal_oid(&oid, &entry->id);
}
count++;
}
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
cl_assert(caps == git_index_caps(index));
git_index_free(index);
}
static const char *expected_index_0[] = {
"attr0",
"attr1",
"attr2",
"attr3",
"binfile",
"gitattributes",
"macro_bad",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"sub/abc",
"sub/file",
"sub/sub/file",
"sub/sub/subsub.txt",
"sub/subdir_test1",
"sub/subdir_test2.txt",
"subdir/.gitattributes",
"subdir/abc",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
};
static const char *expected_index_oids_0[] = {
"556f8c827b8e4a02ad5cab77dca2bcb3e226b0b3",
"3b74db7ab381105dc0d28f8295a77f6a82989292",
"2c66e14f77196ea763fb1e41612c1aa2bc2d8ed2",
"c485abe35abd4aa6fd83b076a78bbea9e2e7e06c",
"d800886d9c86731ae5c4a62b0b77c437015e00d2",
"2b40c5aca159b04ea8d20ffe36cdf8b09369b14a",
"5819a185d77b03325aaf87cafc771db36f6ddca7",
"ff69f8639ce2e6010b3f33a74160aad98b48da2b",
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"9e5bdc47d6a80f2be0ea3049ad74231b94609242",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"99eae476896f4907224978b88e5ecaa6c5bb67a9",
"3e42ffc54a663f9401cc25843d6c0e71a33e4249",
"e563cf4758f0d646f1b14b76016aa17fa9e549a4",
"fb5067b1aef3ac1ada4b379dbcb7d17255df7d78",
"dccada462d3df8ac6de596fb8c896aba9344f941"
};
void test_iterator_index__0(void)
{
index_iterator_test(
"attr", NULL, NULL, 0, ARRAY_SIZE(expected_index_0),
expected_index_0, expected_index_oids_0);
}
static const char *expected_index_1[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_new_file",
"staged_new_file_deleted_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
};
static const char* expected_index_oids_1[] = {
"a0de7e0ac200c489c41c59dfa910154a70264e6e",
"5452d32f1dd538eb0405e8a83cc185f79e25e80f",
"452e4244b5d083ddf0460acf1ecc74db9dcfa11a",
"55d316c9ba708999f1918e9677d01dfcae69c6b9",
"a6be623522ce87a1d862128ac42672604f7b468b",
"906ee7711f4f4928ddcb2a5f8fbc500deba0d2a8",
"529a16e8e762d4acb7b9636ff540a00831f9155a",
"90b8c29d8ba39434d1c63e1b093daaa26e5bd972",
"ed062903b8f6f3dccb2fa81117ba6590944ef9bd",
"e8ee89e15bbe9b20137715232387b3de5b28972e",
"53ace0d1cc1145a5f4fe4f78a186a60263190733",
"1888c805345ba265b0ee9449b8877b6064592058",
"a6191982709b746d5650e93c2acf34ef74e11504"
};
void test_iterator_index__1(void)
{
index_iterator_test(
"status", NULL, NULL, 0, ARRAY_SIZE(expected_index_1),
expected_index_1, expected_index_oids_1);
}
static const char *expected_index_range[] = {
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
};
static const char *expected_index_oids_range[] = {
"45141a79a77842c59a63229403220a4e4be74e3d",
"4d713dc48e6b1bd75b0d61ad078ba9ca3a56745d",
"108bb4e7fd7b16490dc33ff7d972151e73d7166e",
"a0f7217ae99f5ac3e88534f5cea267febc5fa85b",
};
void test_iterator_index__range(void)
{
index_iterator_test(
"attr", "root", "root", 0, ARRAY_SIZE(expected_index_range),
expected_index_range, expected_index_oids_range);
}
void test_iterator_index__range_empty_0(void)
{
index_iterator_test(
"attr", "empty", "empty", 0, 0, NULL, NULL);
}
void test_iterator_index__range_empty_1(void)
{
index_iterator_test(
"attr", "z_empty_after", NULL, 0, 0, NULL, NULL);
}
void test_iterator_index__range_empty_2(void)
{
index_iterator_test(
"attr", NULL, ".aaa_empty_before", 0, 0, NULL, NULL);
}
static void check_index_range(
git_repository *repo,
const char *start,
const char *end,
bool ignore_case,
int expected_count)
{
git_index *index;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count, caps;
bool is_ignoring_case;
cl_git_pass(git_repository_index(&index, repo));
caps = git_index_caps(index);
is_ignoring_case = ((caps & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0);
if (ignore_case != is_ignoring_case)
cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEX_CAPABILITY_IGNORE_CASE));
i_opts.flags = 0;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_index(&i, repo, index, &i_opts));
cl_assert(git_iterator_ignore_case(i) == ignore_case);
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__range_icase(void)
{
git_index *index;
git_tree *head;
g_repo = cl_git_sandbox_init("testrepo");
/* reset index to match HEAD */
cl_git_pass(git_repository_head_tree(&head, g_repo));
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_read_tree(index, head));
cl_git_pass(git_index_write(index));
git_tree_free(head);
git_index_free(index);
/* do some ranged iterator checks toggling case sensitivity */
check_index_range(g_repo, "B", "C", false, 0);
check_index_range(g_repo, "B", "C", true, 1);
check_index_range(g_repo, "a", "z", false, 3);
check_index_range(g_repo, "a", "z", true, 4);
}
static const char *expected_index_cs[] = {
"B", "D", "F", "H", "J", "L/1", "L/B", "L/D", "L/a", "L/c",
"a", "c", "e", "g", "i", "k/1", "k/B", "k/D", "k/a", "k/c",
};
static const char *expected_index_ci[] = {
"a", "B", "c", "D", "e", "F", "g", "H", "i", "J",
"k/1", "k/a", "k/B", "k/c", "k/D", "L/1", "L/a", "L/B", "L/c", "L/D",
};
void test_iterator_index__case_folding(void)
{
git_buf path = GIT_BUF_INIT;
int fs_is_ci = 0;
cl_git_pass(git_buf_joinpath(&path, cl_fixture("icase"), ".gitted/CoNfIg"));
fs_is_ci = git_path_exists(path.ptr);
git_buf_dispose(&path);
index_iterator_test(
"icase", NULL, NULL, 0, ARRAY_SIZE(expected_index_cs),
fs_is_ci ? expected_index_ci : expected_index_cs, NULL);
cl_git_sandbox_cleanup();
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_IGNORE_CASE,
ARRAY_SIZE(expected_index_ci), expected_index_ci, NULL);
cl_git_sandbox_cleanup();
index_iterator_test(
"icase", NULL, NULL, GIT_ITERATOR_DONT_IGNORE_CASE,
ARRAY_SIZE(expected_index_cs), expected_index_cs, NULL);
}
/* Index contents (including pseudotrees):
*
* 0: a 5: F 10: k/ 16: L/
* 1: B 6: g 11: k/1 17: L/1
* 2: c 7: H 12: k/a 18: L/a
* 3: D 8: i 13: k/B 19: L/B
* 4: e 9: J 14: k/c 20: L/c
* 15: k/D 21: L/D
*
* 0: B 5: L/ 11: a 16: k/
* 1: D 6: L/1 12: c 17: k/1
* 2: F 7: L/B 13: e 18: k/B
* 3: H 8: L/D 14: g 19: k/D
* 4: J 9: L/a 15: i 20: k/a
* 10: L/c 21: k/c
*/
void test_iterator_index__icase_0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* autoexpand with no tree entries for index */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__icase_1(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
/* autoexpand with no tree entries over range */
i_opts.flags = 0;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
}
void test_iterator_index__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
/* Case sensitive */
{
const char *expected[] = {
"B", "D", "L/1", "a", "c", "e", "k/1", "k/a" };
size_t expected_len = 8;
i_opts.start = NULL;
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Case INsensitive */
{
const char *expected[] = {
"a", "B", "c", "D", "e", "k/1", "k/a", "L/1" };
size_t expected_len = 8;
i_opts.start = NULL;
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set a start, but no end. Case sensitive. */
{
const char *expected[] = { "c", "e", "k/1", "k/a" };
size_t expected_len = 4;
i_opts.start = "c";
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set a start, but no end. Case INsensitive. */
{
const char *expected[] = { "c", "D", "e", "k/1", "k/a", "L/1" };
size_t expected_len = 6;
i_opts.start = "c";
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set no start, but an end. Case sensitive. */
{
const char *expected[] = { "B", "D", "L/1", "a", "c", "e" };
size_t expected_len = 6;
i_opts.start = NULL;
i_opts.end = "e";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set no start, but an end. Case INsensitive. */
{
const char *expected[] = { "a", "B", "c", "D", "e" };
size_t expected_len = 5;
i_opts.start = NULL;
i_opts.end = "e";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case sensitive */
{
const char *expected[] = { "c", "e", "k/1" };
size_t expected_len = 3;
i_opts.start = "c";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case sensitive */
{
const char *expected[] = { "k/1" };
size_t expected_len = 1;
i_opts.start = "k";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case INsensitive */
{
const char *expected[] = { "c", "D", "e", "k/1", "k/a" };
size_t expected_len = 5;
i_opts.start = "c";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case INsensitive */
{
const char *expected[] = { "k/1", "k/a" };
size_t expected_len = 2;
i_opts.start = "k";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_with_dirs(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
/* Test that a prefix `k` matches folders, even without trailing slash */
{
const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "k"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that a `k/` matches a folder */
{
const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "k/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* When the iterator is case sensitive, ensure we can't lookup the
* directory with the wrong case.
*/
{
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
}
/* Test that case insensitive matching works. */
{
const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that case insensitive matching works without trailing slash. */
{
const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_with_dirs_include_trees(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
const char *expected[] = { "k/", "k/1", "k/B", "k/D", "k/a", "k/c" };
size_t expected_len = 6;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "k"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_1(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a ==> 5) vs (c e k/1 ==> 3) */
expect = default_icase ? 5 : 3;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_2(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_four(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist = GIT_VECTOR_INIT;
int default_icase, expect;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "0"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
/* In this test we DO NOT force a case setting on the index. */
default_icase = ((git_index_caps(index) & GIT_INDEX_CAPABILITY_IGNORE_CASE) != 0);
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "b";
i_opts.end = "k/D";
/* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */
expect = default_icase ? 8 : 5;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
int caps;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
caps = git_index_caps(index);
/* force case sensitivity */
cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEX_CAPABILITY_IGNORE_CASE));
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
/* force case insensitivity */
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEX_CAPABILITY_IGNORE_CASE));
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
cl_git_pass(git_index_set_caps(index, caps));
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__pathlist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
git_index *index;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
git_index_free(index);
git_tree_free(tree);
git_vector_free(&filelist);
}
static void create_paths(git_index *index, const char *root, int depth)
{
git_buf fullpath = GIT_BUF_INIT;
git_index_entry entry;
size_t root_len;
int i;
if (root) {
cl_git_pass(git_buf_puts(&fullpath, root));
cl_git_pass(git_buf_putc(&fullpath, '/'));
}
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
git_buf_truncate(&fullpath, root_len);
cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
if (file) {
memset(&entry, 0, sizeof(git_index_entry));
entry.path = fullpath.ptr;
entry.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&entry.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
cl_git_pass(git_index_add(index, &entry));
} else if (depth > 0) {
create_paths(index, fullpath.ptr, (depth - 1));
}
}
git_buf_dispose(&fullpath);
}
void test_iterator_index__pathlist_for_deeply_nested_item(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
create_paths(index, NULL, 3);
/* Ensure that we find the single path we're interested in */
{
const char *expected[] = { "item1/item3/item5/item7" };
size_t expected_len = 1;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/item7"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
{
const char *expected[] = {
"item1/item3/item5/item0", "item1/item3/item5/item1",
"item1/item3/item5/item2", "item1/item3/item5/item3",
"item1/item3/item5/item4", "item1/item3/item5/item5",
"item1/item3/item5/item6", "item1/item3/item5/item7",
};
size_t expected_len = 8;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
{
const char *expected[] = {
"item1/item3/item0",
"item1/item3/item1/item0", "item1/item3/item1/item1",
"item1/item3/item1/item2", "item1/item3/item1/item3",
"item1/item3/item1/item4", "item1/item3/item1/item5",
"item1/item3/item1/item6", "item1/item3/item1/item7",
"item1/item3/item2",
"item1/item3/item3/item0", "item1/item3/item3/item1",
"item1/item3/item3/item2", "item1/item3/item3/item3",
"item1/item3/item3/item4", "item1/item3/item3/item5",
"item1/item3/item3/item6", "item1/item3/item3/item7",
"item1/item3/item4",
"item1/item3/item5/item0", "item1/item3/item5/item1",
"item1/item3/item5/item2", "item1/item3/item5/item3",
"item1/item3/item5/item4", "item1/item3/item5/item5",
"item1/item3/item5/item6", "item1/item3/item5/item7",
"item1/item3/item6",
"item1/item3/item7/item0", "item1/item3/item7/item1",
"item1/item3/item7/item2", "item1/item3/item7/item3",
"item1/item3/item7/item4", "item1/item3/item7/item5",
"item1/item3/item7/item6", "item1/item3/item7/item7",
};
size_t expected_len = 36;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Ensure that we find the single path we're interested in, and we find
* it efficiently, and don't stat the entire world to get there.
*/
{
const char *expected[] = {
"item0", "item1/item2", "item5/item7/item4", "item6",
"item7/item3/item1/item6" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item7/item3/item1/item6"));
cl_git_pass(git_vector_insert(&filelist, "item6"));
cl_git_pass(git_vector_insert(&filelist, "item5/item7/item4"));
cl_git_pass(git_vector_insert(&filelist, "item1/item2"));
cl_git_pass(git_vector_insert(&filelist, "item0"));
/* also add some things that don't exist or don't match the right type */
cl_git_pass(git_vector_insert(&filelist, "item2/"));
cl_git_pass(git_vector_insert(&filelist, "itemN"));
cl_git_pass(git_vector_insert(&filelist, "item1/itemA"));
cl_git_pass(git_vector_insert(&filelist, "item5/item3/item4/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_index_free(index);
git_vector_free(&filelist);
}
void test_iterator_index__advance_over(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
create_paths(index, NULL, 1);
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item0", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item1/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item2", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item3/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item4", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item5/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item6", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item7/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__advance_into(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
g_repo = cl_git_sandbox_init("icase");
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_advance_into(i, "B");
expect_advance_into(i, "D");
expect_advance_into(i, "F");
expect_advance_into(i, "H");
expect_advance_into(i, "J");
expect_advance_into(i, "L/");
expect_advance_into(i, "L/1");
expect_advance_into(i, "L/B");
expect_advance_into(i, "L/D");
expect_advance_into(i, "L/a");
expect_advance_into(i, "L/c");
expect_advance_into(i, "a");
expect_advance_into(i, "c");
expect_advance_into(i, "e");
expect_advance_into(i, "g");
expect_advance_into(i, "i");
expect_advance_into(i, "k/");
expect_advance_into(i, "k/1");
expect_advance_into(i, "k/B");
expect_advance_into(i, "k/D");
expect_advance_into(i, "k/a");
expect_advance_into(i, "k/c");
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
git_index_free(index);
}
void test_iterator_index__advance_into_and_over(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
g_repo = cl_git_sandbox_init("icase");
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_repository_index(&index, g_repo));
create_paths(index, NULL, 2);
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_advance_into(i, "B");
expect_advance_into(i, "D");
expect_advance_into(i, "F");
expect_advance_into(i, "H");
expect_advance_into(i, "J");
expect_advance_into(i, "L/");
expect_advance_into(i, "L/1");
expect_advance_into(i, "L/B");
expect_advance_into(i, "L/D");
expect_advance_into(i, "L/a");
expect_advance_into(i, "L/c");
expect_advance_into(i, "a");
expect_advance_into(i, "c");
expect_advance_into(i, "e");
expect_advance_into(i, "g");
expect_advance_into(i, "i");
expect_advance_into(i, "item0");
expect_advance_into(i, "item1/");
expect_advance_into(i, "item1/item0");
expect_advance_into(i, "item1/item1/");
expect_advance_into(i, "item1/item1/item0");
expect_advance_into(i, "item1/item1/item1");
expect_advance_into(i, "item1/item1/item2");
expect_advance_into(i, "item1/item1/item3");
expect_advance_into(i, "item1/item1/item4");
expect_advance_into(i, "item1/item1/item5");
expect_advance_into(i, "item1/item1/item6");
expect_advance_into(i, "item1/item1/item7");
expect_advance_into(i, "item1/item2");
expect_advance_over(i, "item1/item3/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item1/item4", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item1/item5/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item1/item6", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item1/item7/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_into(i, "item2");
expect_advance_over(i, "item3/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item4", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item5/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item6", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "item7/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_into(i, "k/");
expect_advance_into(i, "k/1");
expect_advance_into(i, "k/B");
expect_advance_into(i, "k/D");
expect_advance_into(i, "k/a");
expect_advance_into(i, "k/c");
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
git_index_free(index);
}
static void add_conflict(
git_index *index,
const char *ancestor_path,
const char *our_path,
const char *their_path)
{
git_index_entry ancestor = {{0}}, ours = {{0}}, theirs = {{0}};
ancestor.path = ancestor_path;
ancestor.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&ancestor.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
GIT_INDEX_ENTRY_STAGE_SET(&ancestor, 1);
ours.path = our_path;
ours.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&ours.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
GIT_INDEX_ENTRY_STAGE_SET(&ours, 2);
theirs.path = their_path;
theirs.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&theirs.id, "d44e18fb93b7107b5cd1b95d601591d77869a1b6");
GIT_INDEX_ENTRY_STAGE_SET(&theirs, 3);
cl_git_pass(git_index_conflict_add(index, &ancestor, &ours, &theirs));
}
void test_iterator_index__include_conflicts(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_index *index;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_index(&index, g_repo));
add_conflict(index, "CONFLICT1", "CONFLICT1" ,"CONFLICT1");
add_conflict(index, "ZZZ-CONFLICT2.ancestor", "ZZZ-CONFLICT2.ours", "ZZZ-CONFLICT2.theirs");
add_conflict(index, "ancestor.conflict3", "ours.conflict3", "theirs.conflict3");
add_conflict(index, "zzz-conflict4", "zzz-conflict4", "zzz-conflict4");
/* Iterate the index, ensuring that conflicts are not included */
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
/* Try again, returning conflicts */
i_opts.flags |= GIT_ITERATOR_INCLUDE_CONFLICTS;
cl_git_pass(git_iterator_for_index(&i, g_repo, index, &i_opts));
expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "CONFLICT1", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "ZZZ-CONFLICT2.ancestor", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "ZZZ-CONFLICT2.ours", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "ZZZ-CONFLICT2.theirs", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "ancestor.conflict3", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "ours.conflict3", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "theirs.conflict3", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "zzz-conflict4", GIT_ITERATOR_STATUS_NORMAL);
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/iterator/tree.c
|
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "futils.h"
#include "tree.h"
#include "../submodule/submodule_helpers.h"
#include "../diff/diff_helpers.h"
#include "iterator_helpers.h"
#include <stdarg.h>
static git_repository *g_repo;
void test_iterator_tree__initialize(void)
{
}
void test_iterator_tree__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void tree_iterator_test(
const char *sandbox,
const char *treeish,
const char *start,
const char *end,
int expected_count,
const char **expected_values)
{
git_tree *t;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, count = 0, count_post_reset = 0;
g_repo = cl_git_sandbox_init(sandbox);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_assert(t = resolve_commit_oid_to_tree(g_repo, treeish));
cl_git_pass(git_iterator_for_tree(&i, t, &i_opts));
/* test loop */
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count], entry->path);
count++;
}
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(expected_count, count);
/* test reset */
cl_git_pass(git_iterator_reset(i));
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
if (expected_values != NULL)
cl_assert_equal_s(expected_values[count_post_reset], entry->path);
count_post_reset++;
}
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(count, count_post_reset);
git_iterator_free(i);
git_tree_free(t);
}
/* results of: git ls-tree -r --name-only 605812a */
const char *expected_tree_0[] = {
".gitattributes",
"attr0",
"attr1",
"attr2",
"attr3",
"binfile",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"subdir/.gitattributes",
"subdir/abc",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
NULL
};
void test_iterator_tree__0(void)
{
tree_iterator_test("attr", "605812a", NULL, NULL, 16, expected_tree_0);
}
/* results of: git ls-tree -r --name-only 6bab5c79 */
const char *expected_tree_1[] = {
".gitattributes",
"attr0",
"attr1",
"attr2",
"attr3",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"subdir/.gitattributes",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
NULL
};
void test_iterator_tree__1(void)
{
tree_iterator_test("attr", "6bab5c79cd5", NULL, NULL, 13, expected_tree_1);
}
/* results of: git ls-tree -r --name-only 26a125ee1 */
const char *expected_tree_2[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL
};
void test_iterator_tree__2(void)
{
tree_iterator_test("status", "26a125ee1", NULL, NULL, 12, expected_tree_2);
}
/* $ git ls-tree -r --name-only 0017bd4ab1e */
const char *expected_tree_3[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file"
};
void test_iterator_tree__3(void)
{
tree_iterator_test("status", "0017bd4ab1e", NULL, NULL, 8, expected_tree_3);
}
/* $ git ls-tree -r --name-only 24fa9a9fc4e202313e24b648087495441dab432b */
const char *expected_tree_4[] = {
"attr0",
"attr1",
"attr2",
"attr3",
"binfile",
"gitattributes",
"macro_bad",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
"sub/abc",
"sub/file",
"sub/sub/file",
"sub/sub/subsub.txt",
"sub/subdir_test1",
"sub/subdir_test2.txt",
"subdir/.gitattributes",
"subdir/abc",
"subdir/subdir_test1",
"subdir/subdir_test2.txt",
"subdir2/subdir2_test1",
NULL
};
void test_iterator_tree__4(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b", NULL, NULL,
23, expected_tree_4);
}
void test_iterator_tree__4_ranged(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"sub", "sub",
11, &expected_tree_4[12]);
}
const char *expected_tree_ranged_0[] = {
"gitattributes",
"macro_bad",
"macro_test",
"root_test1",
"root_test2",
"root_test3",
"root_test4.txt",
NULL
};
void test_iterator_tree__ranged_0(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"git", "root",
7, expected_tree_ranged_0);
}
const char *expected_tree_ranged_1[] = {
"sub/subdir_test2.txt",
NULL
};
void test_iterator_tree__ranged_1(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"sub/subdir_test2.txt", "sub/subdir_test2.txt",
1, expected_tree_ranged_1);
}
void test_iterator_tree__range_empty_0(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"empty", "empty", 0, NULL);
}
void test_iterator_tree__range_empty_1(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
"z_empty_after", NULL, 0, NULL);
}
void test_iterator_tree__range_empty_2(void)
{
tree_iterator_test(
"attr", "24fa9a9fc4e202313e24b648087495441dab432b",
NULL, ".aaa_empty_before", 0, NULL);
}
static void check_tree_entry(
git_iterator *i,
const char *oid,
const char *oid_p,
const char *oid_pp,
const char *oid_ppp)
{
const git_index_entry *ie;
const git_tree_entry *te;
const git_tree *tree;
cl_git_pass(git_iterator_current_tree_entry(&te, i));
cl_assert(te);
cl_assert(git_oid_streq(te->oid, oid) == 0);
cl_git_pass(git_iterator_current(&ie, i));
if (oid_p) {
cl_git_pass(git_iterator_current_parent_tree(&tree, i, 0));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_p) == 0);
}
if (oid_pp) {
cl_git_pass(git_iterator_current_parent_tree(&tree, i, 1));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_pp) == 0);
}
if (oid_ppp) {
cl_git_pass(git_iterator_current_parent_tree(&tree, i, 2));
cl_assert(tree);
cl_assert(git_oid_streq(git_tree_id(tree), oid_ppp) == 0);
}
}
void test_iterator_tree__special_functions(void)
{
git_tree *t;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, cases = 0;
const char *rootoid = "ce39a97a7fb1fa90bcf5e711249c1e507476ae0e";
g_repo = cl_git_sandbox_init("attr");
t = resolve_commit_oid_to_tree(
g_repo, "24fa9a9fc4e202313e24b648087495441dab432b");
cl_assert(t != NULL);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, t, &i_opts));
while (!(error = git_iterator_advance(&entry, i))) {
cl_assert(entry);
if (strcmp(entry->path, "sub/file") == 0) {
cases++;
check_tree_entry(
i, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057",
"ecb97df2a174987475ac816e3847fc8e9f6c596b",
rootoid, NULL);
}
else if (strcmp(entry->path, "sub/sub/subsub.txt") == 0) {
cases++;
check_tree_entry(
i, "9e5bdc47d6a80f2be0ea3049ad74231b94609242",
"4e49ba8c5b6c32ff28cd9dcb60be34df50fcc485",
"ecb97df2a174987475ac816e3847fc8e9f6c596b", rootoid);
}
else if (strcmp(entry->path, "subdir/.gitattributes") == 0) {
cases++;
check_tree_entry(
i, "99eae476896f4907224978b88e5ecaa6c5bb67a9",
"9fb40b6675dde60b5697afceae91b66d908c02d9",
rootoid, NULL);
}
else if (strcmp(entry->path, "subdir2/subdir2_test1") == 0) {
cases++;
check_tree_entry(
i, "dccada462d3df8ac6de596fb8c896aba9344f941",
"2929de282ce999e95183aedac6451d3384559c4b",
rootoid, NULL);
}
}
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert(!entry);
cl_assert_equal_i(4, cases);
git_iterator_free(i);
git_tree_free(t);
}
static void check_tree_range(
git_repository *repo,
const char *start,
const char *end,
bool ignore_case,
int expected_count)
{
git_tree *head;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
int error, count;
i_opts.flags = ignore_case ? GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
/* count em up */;
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_i(expected_count, count);
git_iterator_free(i);
git_tree_free(head);
}
void test_iterator_tree__range_icase(void)
{
g_repo = cl_git_sandbox_init("testrepo");
check_tree_range(g_repo, "B", "C", false, 0);
check_tree_range(g_repo, "B", "C", true, 1);
check_tree_range(g_repo, "b", "c", false, 1);
check_tree_range(g_repo, "b", "c", true, 1);
check_tree_range(g_repo, "a", "z", false, 3);
check_tree_range(g_repo, "a", "z", true, 4);
check_tree_range(g_repo, "A", "Z", false, 1);
check_tree_range(g_repo, "A", "Z", true, 4);
check_tree_range(g_repo, "a", "Z", false, 0);
check_tree_range(g_repo, "a", "Z", true, 4);
check_tree_range(g_repo, "A", "z", false, 4);
check_tree_range(g_repo, "A", "z", true, 4);
check_tree_range(g_repo, "new.txt", "new.txt", true, 1);
check_tree_range(g_repo, "new.txt", "new.txt", false, 1);
check_tree_range(g_repo, "README", "README", true, 1);
check_tree_range(g_repo, "README", "README", false, 1);
}
void test_iterator_tree__icase_0(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_head_tree(&head, g_repo));
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
git_tree_free(head);
}
void test_iterator_tree__icase_1(void)
{
git_iterator *i;
git_tree *head;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_repository_head_tree(&head, g_repo));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
/* auto expand with no tree entries */
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
/* auto expand with tree entries */
i_opts.start = "c";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* auto expand with no tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
git_tree_free(head);
}
void test_iterator_tree__icase_2(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_tree *head;
static const char *expect_basic[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_trees[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
"subdir/current_file",
"subdir/deleted_file",
"subdir/modified_file",
NULL,
};
static const char *expect_noauto[] = {
"current_file",
"file_deleted",
"modified_file",
"staged_changes",
"staged_changes_file_deleted",
"staged_changes_modified_file",
"staged_delete_file_deleted",
"staged_delete_modified_file",
"subdir.txt",
"subdir/",
NULL
};
g_repo = cl_git_sandbox_init("status");
cl_git_pass(git_repository_head_tree(&head, g_repo));
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_tree(&i, head, NULL));
expect_iterator_items(i, 12, expect_basic, 12, expect_basic);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 13, expect_trees, 13, expect_trees);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_tree(&i, head, &i_opts));
expect_iterator_items(i, 10, expect_noauto, 13, expect_trees);
git_iterator_free(i);
git_tree_free(head);
}
/* "b=name,t=name", blob_id, tree_id */
static void build_test_tree(
git_oid *out, git_repository *repo, const char *fmt, ...)
{
git_oid *id;
git_treebuilder *builder;
const char *scan = fmt, *next;
char type, delimiter;
git_filemode_t mode = GIT_FILEMODE_BLOB;
git_buf name = GIT_BUF_INIT;
va_list arglist;
cl_git_pass(git_treebuilder_new(&builder, repo, NULL)); /* start builder */
va_start(arglist, fmt);
while (*scan) {
switch (type = *scan++) {
case 't': case 'T': mode = GIT_FILEMODE_TREE; break;
case 'b': case 'B': mode = GIT_FILEMODE_BLOB; break;
default:
cl_assert(type == 't' || type == 'T' || type == 'b' || type == 'B');
}
delimiter = *scan++; /* read and skip delimiter */
for (next = scan; *next && *next != delimiter; ++next)
/* seek end */;
cl_git_pass(git_buf_set(&name, scan, (size_t)(next - scan)));
for (scan = next; *scan && (*scan == delimiter || *scan == ','); ++scan)
/* skip delimiter and optional comma */;
id = va_arg(arglist, git_oid *);
cl_git_pass(git_treebuilder_insert(NULL, builder, name.ptr, id, mode));
}
va_end(arglist);
cl_git_pass(git_treebuilder_write(out, builder));
git_treebuilder_free(builder);
git_buf_dispose(&name);
}
void test_iterator_tree__case_conflicts_0(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const char *expect_cs[] = {
"A/1.file", "A/3.file", "a/2.file", "a/4.file" };
const char *expect_ci[] = {
"A/1.file", "a/2.file", "A/3.file", "a/4.file" };
const char *expect_cs_trees[] = {
"A/", "A/1.file", "A/3.file", "a/", "a/2.file", "a/4.file" };
const char *expect_ci_trees[] = {
"A/", "A/1.file", "a/2.file", "A/3.file", "a/4.file" };
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
/* create tree with: A/1.file, A/3.file, a/2.file, a/4.file */
build_test_tree(
&biga_id, g_repo, "b|1.file|,b|3.file|", &blob_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|2.file|,b|4.file|", &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_cs, 4, expect_cs);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs_trees, 6, expect_cs_trees);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, expect_ci_trees, 5, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
void test_iterator_tree__case_conflicts_1(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, Ab_id, biga_id, littlea_id, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const char *expect_cs[] = {
"A/a", "A/b/1", "A/c", "a/C", "a/a", "a/b" };
const char *expect_ci[] = {
"A/a", "a/b", "A/b/1", "A/c" };
const char *expect_cs_trees[] = {
"A/", "A/a", "A/b/", "A/b/1", "A/c", "a/", "a/C", "a/a", "a/b" };
const char *expect_ci_trees[] = {
"A/", "A/a", "a/b", "A/b/", "A/b/1", "A/c" };
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
/* create: A/a A/b/1 A/c a/a a/b a/C */
build_test_tree(&Ab_id, g_repo, "b|1|", &blob_id);
build_test_tree(
&biga_id, g_repo, "b|a|,t|b|,b|c|", &blob_id, &Ab_id, &blob_id);
build_test_tree(
&littlea_id, g_repo, "b|a|,b|b|,b|C|", &blob_id, &blob_id, &blob_id);
build_test_tree(
&tree_id, g_repo, "t|A|,t|a|", &biga_id, &littlea_id);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_cs, 6, expect_cs);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 4, expect_ci, 4, expect_ci);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 9, expect_cs_trees, 9, expect_cs_trees);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 6, expect_ci_trees, 6, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
void test_iterator_tree__case_conflicts_2(void)
{
const char *blob_sha = "d44e18fb93b7107b5cd1b95d601591d77869a1b6";
git_tree *tree;
git_oid blob_id, d1, d2, c1, c2, b1, b2, a1, a2, tree_id;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const char *expect_cs[] = {
"A/B/C/D/16", "A/B/C/D/foo", "A/B/C/d/15", "A/B/C/d/FOO",
"A/B/c/D/14", "A/B/c/D/foo", "A/B/c/d/13", "A/B/c/d/FOO",
"A/b/C/D/12", "A/b/C/D/foo", "A/b/C/d/11", "A/b/C/d/FOO",
"A/b/c/D/10", "A/b/c/D/foo", "A/b/c/d/09", "A/b/c/d/FOO",
"a/B/C/D/08", "a/B/C/D/foo", "a/B/C/d/07", "a/B/C/d/FOO",
"a/B/c/D/06", "a/B/c/D/foo", "a/B/c/d/05", "a/B/c/d/FOO",
"a/b/C/D/04", "a/b/C/D/foo", "a/b/C/d/03", "a/b/C/d/FOO",
"a/b/c/D/02", "a/b/c/D/foo", "a/b/c/d/01", "a/b/c/d/FOO", };
const char *expect_ci[] = {
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
const char *expect_ci_trees[] = {
"A/", "A/B/", "A/B/C/", "A/B/C/D/",
"a/b/c/d/01", "a/b/c/D/02", "a/b/C/d/03", "a/b/C/D/04",
"a/B/c/d/05", "a/B/c/D/06", "a/B/C/d/07", "a/B/C/D/08",
"A/b/c/d/09", "A/b/c/D/10", "A/b/C/d/11", "A/b/C/D/12",
"A/B/c/d/13", "A/B/c/D/14", "A/B/C/d/15", "A/B/C/D/16",
"A/B/C/D/foo", };
g_repo = cl_git_sandbox_init("icase");
cl_git_pass(git_oid_fromstr(&blob_id, blob_sha)); /* lookup blob */
build_test_tree(&d1, g_repo, "b|16|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|15|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|14|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|13|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|12|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|11|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|10|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|09|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a1, g_repo, "t|B|,t|b|", &b1, &b2);
build_test_tree(&d1, g_repo, "b|08|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|07|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|06|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|05|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b1, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&d1, g_repo, "b|04|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|03|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c1, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&d1, g_repo, "b|02|,b|foo|", &blob_id, &blob_id);
build_test_tree(&d2, g_repo, "b|01|,b|FOO|", &blob_id, &blob_id);
build_test_tree(&c2, g_repo, "t|D|,t|d|", &d1, &d2);
build_test_tree(&b2, g_repo, "t|C|,t|c|", &c1, &c2);
build_test_tree(&a2, g_repo, "t|B|,t|b|", &b1, &b2);
build_test_tree(&tree_id, g_repo, "t/A/,t/a/", &a1, &a2);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 32, expect_cs, 32, expect_cs);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 17, expect_ci, 17, expect_ci);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 21, expect_ci_trees, 21, expect_ci_trees);
git_iterator_free(i);
git_tree_free(tree);
}
void test_iterator_tree__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
bool default_icase;
int expect;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
/* In this test we DO NOT force a case on the iterators and verify default behavior. */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "c";
i_opts.end = NULL;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
expect = ((default_icase) ? 6 : 4);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
i_opts.start = NULL;
i_opts.end = "e";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
default_icase = git_iterator_ignore_case(i);
/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
expect = ((default_icase) ? 5 : 6);
expect_iterator_items(i, expect, NULL, expect, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
git_tree_free(tree);
}
void test_iterator_tree__pathlist_icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
git_repository_head_tree(&tree, g_repo);
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 1, NULL, 1, NULL);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, 2, NULL, 2, NULL);
git_iterator_free(i);
git_vector_free(&filelist);
git_tree_free(tree);
}
void test_iterator_tree__pathlist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
const char *expected[] = { "subdir/README", "subdir/new.txt",
"subdir/subdir2/README", "subdir/subdir2/new.txt" };
size_t expected_len = 4;
const char *expected2[] = { "subdir/subdir2/README", "subdir/subdir2/new.txt" };
size_t expected_len2 = 2;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "subdir/subdir2"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, expected_len2, expected2, expected_len2, expected2);
git_iterator_free(i);
git_tree_free(tree);
git_vector_free(&filelist);
}
void test_iterator_tree__pathlist_with_directory_include_tree_nodes(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
const char *expected[] = { "subdir/", "subdir/README", "subdir/new.txt",
"subdir/subdir2/", "subdir/subdir2/README", "subdir/subdir2/new.txt" };
size_t expected_len = 6;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_tree_free(tree);
git_vector_free(&filelist);
}
void test_iterator_tree__pathlist_no_match(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_tree *tree;
const git_index_entry *entry;
g_repo = cl_git_sandbox_init("testrepo2");
git_repository_head_tree(&tree, g_repo);
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "nonexistent/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_current(&entry, i));
git_iterator_free(i);
git_tree_free(tree);
git_vector_free(&filelist);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/iterator/iterator_helpers.c
|
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "futils.h"
#include "iterator_helpers.h"
#include <stdarg.h>
static void assert_at_end(git_iterator *i, bool verbose)
{
const git_index_entry *end;
int error = git_iterator_advance(&end, i);
if (verbose && error != GIT_ITEROVER)
fprintf(stderr, "Expected end of iterator, got '%s'\n", end->path);
cl_git_fail_with(GIT_ITEROVER, error);
}
void expect_iterator_items(
git_iterator *i,
size_t expected_flat,
const char **expected_flat_paths,
size_t expected_total,
const char **expected_total_paths)
{
const git_index_entry *entry;
size_t count;
int no_trees = !(git_iterator_flags(i) & GIT_ITERATOR_INCLUDE_TREES);
bool v = false;
int error;
if (v) fprintf(stderr, "== %s ==\n", no_trees ? "notrees" : "trees");
count = 0;
while (!git_iterator_advance(&entry, i)) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_flat_paths) {
const char *expect_path = expected_flat_paths[count];
size_t expect_len = strlen(expect_path);
cl_assert_equal_s(expect_path, entry->path);
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
cl_assert(++count <= expected_flat);
}
assert_at_end(i, v);
cl_assert_equal_i(expected_flat, count);
cl_git_pass(git_iterator_reset(i));
count = 0;
cl_git_pass(git_iterator_current(&entry, i));
if (v) fprintf(stderr, "-- %s --\n", no_trees ? "notrees" : "trees");
while (entry != NULL) {
if (v) fprintf(stderr, " %s %07o\n", entry->path, (int)entry->mode);
if (no_trees)
cl_assert(entry->mode != GIT_FILEMODE_TREE);
if (expected_total_paths) {
const char *expect_path = expected_total_paths[count];
size_t expect_len = strlen(expect_path);
cl_assert_equal_s(expect_path, entry->path);
if (expect_path[expect_len - 1] == '/')
cl_assert_equal_i(GIT_FILEMODE_TREE, entry->mode);
else
cl_assert(entry->mode != GIT_FILEMODE_TREE);
}
if (entry->mode == GIT_FILEMODE_TREE) {
error = git_iterator_advance_into(&entry, i);
/* could return NOTFOUND if directory is empty */
cl_assert(!error || error == GIT_ENOTFOUND);
if (error == GIT_ENOTFOUND) {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
} else {
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
if (++count >= expected_total)
break;
}
assert_at_end(i, v);
cl_assert_equal_i(expected_total, count);
}
void expect_advance_over(
git_iterator *i,
const char *expected_path,
git_iterator_status_t expected_status)
{
const git_index_entry *entry;
git_iterator_status_t status;
int error;
cl_git_pass(git_iterator_current(&entry, i));
cl_assert_equal_s(expected_path, entry->path);
error = git_iterator_advance_over(&entry, &status, i);
cl_assert(!error || error == GIT_ITEROVER);
cl_assert_equal_i(expected_status, status);
}
void expect_advance_into(
git_iterator *i,
const char *expected_path)
{
const git_index_entry *entry;
int error;
cl_git_pass(git_iterator_current(&entry, i));
cl_assert_equal_s(expected_path, entry->path);
if (S_ISDIR(entry->mode))
error = git_iterator_advance_into(&entry, i);
else
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/iterator/workdir.c
|
#include "clar_libgit2.h"
#include "iterator.h"
#include "repository.h"
#include "futils.h"
#include "../submodule/submodule_helpers.h"
#include "../merge/merge_helpers.h"
#include "iterator_helpers.h"
#include <stdarg.h>
static git_repository *g_repo;
void test_iterator_workdir__initialize(void)
{
}
void test_iterator_workdir__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void workdir_iterator_test(
const char *sandbox,
const char *start,
const char *end,
int expected_count,
int expected_ignores,
const char **expected_names,
const char *an_ignored_name)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, count = 0, count_all = 0, count_all_post_reset = 0;
g_repo = cl_git_sandbox_init(sandbox);
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
while (entry != NULL) {
int ignored = git_iterator_current_is_ignored(i);
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
if (expected_names != NULL)
cl_assert_equal_s(expected_names[count_all], entry->path);
if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0)
cl_assert(ignored);
if (!ignored)
count++;
count_all++;
error = git_iterator_advance(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
}
cl_assert_equal_i(expected_count, count);
cl_assert_equal_i(expected_count + expected_ignores, count_all);
cl_git_pass(git_iterator_reset(i));
error = git_iterator_current(&entry, i);
cl_assert((error == 0 && entry != NULL) ||
(error == GIT_ITEROVER && entry == NULL));
while (entry != NULL) {
if (S_ISDIR(entry->mode)) {
cl_git_pass(git_iterator_advance_into(&entry, i));
continue;
}
if (expected_names != NULL)
cl_assert_equal_s(
expected_names[count_all_post_reset], entry->path);
count_all_post_reset++;
error = git_iterator_advance(&entry, i);
cl_assert(error == 0 || error == GIT_ITEROVER);
}
cl_assert_equal_i(count_all, count_all_post_reset);
git_iterator_free(i);
}
void test_iterator_workdir__0(void)
{
workdir_iterator_test("attr", NULL, NULL, 24, 5, NULL, "ign");
}
static const char *status_paths[] = {
"current_file",
"ignored_file",
"modified_file",
"new_file",
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
void test_iterator_workdir__1(void)
{
workdir_iterator_test(
"status", NULL, NULL, 13, 1, status_paths, "ignored_file");
}
static const char *status_paths_range_0[] = {
"staged_changes",
"staged_changes_modified_file",
"staged_delete_modified_file",
"staged_new_file",
"staged_new_file_modified_file",
NULL
};
void test_iterator_workdir__1_ranged_0(void)
{
workdir_iterator_test(
"status", "staged", "staged", 5, 0, status_paths_range_0, NULL);
}
static const char *status_paths_range_1[] = {
"modified_file", NULL
};
void test_iterator_workdir__1_ranged_1(void)
{
workdir_iterator_test(
"status", "modified_file", "modified_file",
1, 0, status_paths_range_1, NULL);
}
static const char *status_paths_range_3[] = {
"subdir.txt",
"subdir/current_file",
"subdir/modified_file",
NULL
};
void test_iterator_workdir__1_ranged_3(void)
{
workdir_iterator_test(
"status", "subdir", "subdir/modified_file",
3, 0, status_paths_range_3, NULL);
}
static const char *status_paths_range_4[] = {
"subdir/current_file",
"subdir/modified_file",
"subdir/new_file",
"\xe8\xbf\x99",
NULL
};
void test_iterator_workdir__1_ranged_4(void)
{
workdir_iterator_test(
"status", "subdir/", NULL, 4, 0, status_paths_range_4, NULL);
}
static const char *status_paths_range_5[] = {
"subdir/modified_file",
NULL
};
void test_iterator_workdir__1_ranged_5(void)
{
workdir_iterator_test(
"status", "subdir/modified_file", "subdir/modified_file",
1, 0, status_paths_range_5, NULL);
}
void test_iterator_workdir__1_ranged_5_1_ranged_empty_0(void)
{
workdir_iterator_test(
"status", "\xff_does_not_exist", NULL,
0, 0, NULL, NULL);
}
void test_iterator_workdir__1_ranged_empty_1(void)
{
workdir_iterator_test(
"status", "empty", "empty",
0, 0, NULL, NULL);
}
void test_iterator_workdir__1_ranged_empty_2(void)
{
workdir_iterator_test(
"status", NULL, "aaaa_empty_before",
0, 0, NULL, NULL);
}
void test_iterator_workdir__builtin_ignores(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int idx;
static struct {
const char *path;
bool ignored;
} expected[] = {
{ "dir/", true },
{ "file", false },
{ "ign", true },
{ "macro_bad", false },
{ "macro_test", false },
{ "root_test1", false },
{ "root_test2", false },
{ "root_test3", false },
{ "root_test4.txt", false },
{ "sub/", false },
{ "sub/.gitattributes", false },
{ "sub/abc", false },
{ "sub/dir/", true },
{ "sub/file", false },
{ "sub/ign/", true },
{ "sub/sub/", false },
{ "sub/sub/.gitattributes", false },
{ "sub/sub/dir", false }, /* file is not actually a dir */
{ "sub/sub/file", false },
{ NULL, false }
};
g_repo = cl_git_sandbox_init("attr");
cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777));
cl_git_mkfile("attr/sub/.git", "whatever");
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "dir";
i_opts.end = "sub/sub/file";
cl_git_pass(git_iterator_for_workdir(
&i, g_repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) {
int ignored = git_iterator_current_is_ignored(i);
cl_assert_equal_s(expected[idx].path, entry->path);
cl_assert_(ignored == expected[idx].ignored, expected[idx].path);
if (!ignored &&
(entry->mode == GIT_FILEMODE_TREE ||
entry->mode == GIT_FILEMODE_COMMIT))
{
/* it is possible to advance "into" a submodule */
cl_git_pass(git_iterator_advance_into(&entry, i));
} else {
int error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
}
cl_assert(expected[idx].path == NULL);
git_iterator_free(i);
}
static void check_wd_first_through_third_range(
git_repository *repo, const char *start, const char *end)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry;
int error, idx;
static const char *expected[] = { "FIRST", "second", "THIRD", NULL };
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = start;
i_opts.end = end;
cl_git_pass(git_iterator_for_workdir(
&i, repo, NULL, NULL, &i_opts));
cl_git_pass(git_iterator_current(&entry, i));
for (idx = 0; entry != NULL; ++idx) {
cl_assert_equal_s(expected[idx], entry->path);
error = git_iterator_advance(&entry, i);
cl_assert(!error || error == GIT_ITEROVER);
}
cl_assert(expected[idx] == NULL);
git_iterator_free(i);
}
void test_iterator_workdir__handles_icase_range(void)
{
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_remove_placeholders(git_repository_path(g_repo), "dummy-marker.txt");
cl_git_mkfile("empty_standard_repo/before", "whatever\n");
cl_git_mkfile("empty_standard_repo/FIRST", "whatever\n");
cl_git_mkfile("empty_standard_repo/second", "whatever\n");
cl_git_mkfile("empty_standard_repo/THIRD", "whatever\n");
cl_git_mkfile("empty_standard_repo/zafter", "whatever\n");
cl_git_mkfile("empty_standard_repo/Zlast", "whatever\n");
check_wd_first_through_third_range(g_repo, "first", "third");
check_wd_first_through_third_range(g_repo, "FIRST", "THIRD");
check_wd_first_through_third_range(g_repo, "first", "THIRD");
check_wd_first_through_third_range(g_repo, "FIRST", "third");
check_wd_first_through_third_range(g_repo, "FirSt", "tHiRd");
}
/*
* The workdir iterator is like the filesystem iterator, but honors
* special git type constructs (ignores, submodules, etc).
*/
void test_iterator_workdir__icase(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 20, NULL, 20, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 22, NULL, 22, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 12, NULL, 22, NULL);
git_iterator_free(i);
}
void test_iterator_workdir__icase_starts_and_ends(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
/* auto expand with no tree entries */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 7, NULL, 7, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 3, NULL, 3, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 8, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 4, NULL, 4, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 5, NULL, 8, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 1, NULL, 4, NULL);
git_iterator_free(i);
/* auto expand with no tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 13, NULL, 13, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 5, NULL, 5, NULL);
git_iterator_free(i);
/* auto expand with tree entries */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 14, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 6, NULL, 6, NULL);
git_iterator_free(i);
/* no auto expand (implies trees included) */
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
i_opts.start = "c";
i_opts.end = "k/D";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 9, NULL, 14, NULL);
git_iterator_free(i);
i_opts.start = "k";
i_opts.end = "k/Z";
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, 1, NULL, 6, NULL);
git_iterator_free(i);
}
static void build_workdir_tree(const char *root, int dirs, int subs)
{
int i, j;
char buf[64], sub[80];
for (i = 0; i < dirs; ++i) {
if (i % 2 == 0) {
p_snprintf(buf, sizeof(buf), "%s/dir%02d", root, i);
cl_git_pass(git_futils_mkdir(buf, 0775, GIT_MKDIR_PATH));
p_snprintf(buf, sizeof(buf), "%s/dir%02d/file", root, i);
cl_git_mkfile(buf, buf);
buf[strlen(buf) - 5] = '\0';
} else {
p_snprintf(buf, sizeof(buf), "%s/DIR%02d", root, i);
cl_git_pass(git_futils_mkdir(buf, 0775, GIT_MKDIR_PATH));
}
for (j = 0; j < subs; ++j) {
switch (j % 4) {
case 0: p_snprintf(sub, sizeof(sub), "%s/sub%02d", buf, j); break;
case 1: p_snprintf(sub, sizeof(sub), "%s/sUB%02d", buf, j); break;
case 2: p_snprintf(sub, sizeof(sub), "%s/Sub%02d", buf, j); break;
case 3: p_snprintf(sub, sizeof(sub), "%s/SUB%02d", buf, j); break;
}
cl_git_pass(git_futils_mkdir(sub, 0775, GIT_MKDIR_PATH));
if (j % 2 == 0) {
size_t sublen = strlen(sub);
memcpy(&sub[sublen], "/file", sizeof("/file"));
cl_git_mkfile(sub, sub);
sub[sublen] = '\0';
}
}
}
}
void test_iterator_workdir__depth(void)
{
git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
build_workdir_tree("icase", 10, 10);
build_workdir_tree("icase/DIR01/sUB01", 50, 0);
build_workdir_tree("icase/dir02/sUB01", 50, 0);
/* auto expand with no tree entries */
cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts));
expect_iterator_items(iter, 125, NULL, 125, NULL);
git_iterator_free(iter);
/* auto expand with tree entries (empty dirs silently skipped) */
iter_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts));
expect_iterator_items(iter, 337, NULL, 337, NULL);
git_iterator_free(iter);
}
/* The filesystem iterator is a workdir iterator without any special
* workdir handling capabilities (ignores, submodules, etc).
*/
void test_iterator_workdir__filesystem(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
static const char *expect_base[] = {
"DIR01/Sub02/file",
"DIR01/sub00/file",
"current_file",
"dir00/Sub02/file",
"dir00/file",
"dir00/sub00/file",
"modified_file",
"new_file",
NULL,
};
static const char *expect_trees[] = {
"DIR01/",
"DIR01/SUB03/",
"DIR01/Sub02/",
"DIR01/Sub02/file",
"DIR01/sUB01/",
"DIR01/sub00/",
"DIR01/sub00/file",
"current_file",
"dir00/",
"dir00/SUB03/",
"dir00/Sub02/",
"dir00/Sub02/file",
"dir00/file",
"dir00/sUB01/",
"dir00/sub00/",
"dir00/sub00/file",
"modified_file",
"new_file",
NULL,
};
static const char *expect_noauto[] = {
"DIR01/",
"current_file",
"dir00/",
"modified_file",
"new_file",
NULL,
};
g_repo = cl_git_sandbox_init("status");
build_workdir_tree("status/subdir", 2, 4);
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", NULL));
expect_iterator_items(i, 8, expect_base, 8, expect_base);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts));
expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts));
expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
git_iterator_free(i);
git__tsort((void **)expect_base, 8, (git__tsort_cmp)git__strcasecmp);
git__tsort((void **)expect_trees, 18, (git__tsort_cmp)git__strcasecmp);
git__tsort((void **)expect_noauto, 5, (git__tsort_cmp)git__strcasecmp);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts));
expect_iterator_items(i, 8, expect_base, 8, expect_base);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts));
expect_iterator_items(i, 18, expect_trees, 18, expect_trees);
git_iterator_free(i);
i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts));
expect_iterator_items(i, 5, expect_noauto, 18, expect_trees);
git_iterator_free(i);
}
void test_iterator_workdir__filesystem2(void)
{
git_iterator *i;
static const char *expect_base[] = {
"heads/br2",
"heads/dir",
"heads/executable",
"heads/ident",
"heads/long-file-name",
"heads/master",
"heads/merge-conflict",
"heads/packed-test",
"heads/subtrees",
"heads/test",
"heads/testrepo-worktree",
"symref",
"tags/e90810b",
"tags/foo/bar",
"tags/foo/foo/bar",
"tags/point_to_blob",
"tags/test",
NULL,
};
g_repo = cl_git_sandbox_init("testrepo");
cl_git_pass(git_iterator_for_filesystem(
&i, "testrepo/.git/refs", NULL));
expect_iterator_items(i, 17, expect_base, 17, expect_base);
git_iterator_free(i);
}
/*
* Lots of empty dirs, or nearly empty ones, make the old workdir
* iterator cry. Also, segfault.
*/
void test_iterator_workdir__filesystem_gunk(void)
{
git_buf parent = GIT_BUF_INIT;
git_iterator *i;
int n;
if (!cl_is_env_set("GITTEST_INVASIVE_SPEED"))
cl_skip();
g_repo = cl_git_sandbox_init("testrepo");
for (n = 0; n < 100000; n++) {
git_buf_clear(&parent);
cl_git_pass(git_buf_printf(&parent, "%s/refs/heads/foo/%d/subdir", git_repository_path(g_repo), n));
cl_git_pass(git_futils_mkdir(parent.ptr, 0775, GIT_MKDIR_PATH));
}
cl_git_pass(git_iterator_for_filesystem(&i, "testrepo/.git/refs", NULL));
/*
* Should only have 17 items, since we're not asking for trees to be
* returned. the goal of this test is simply to not crash.
*/
expect_iterator_items(i, 17, NULL, 16, NULL);
git_iterator_free(i);
git_buf_dispose(&parent);
}
void test_iterator_workdir__skips_unreadable_dirs(void)
{
git_iterator *i;
const git_index_entry *e;
if (!cl_is_chmod_supported())
return;
#ifndef GIT_WIN32
if (geteuid() == 0)
cl_skip();
#endif
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_must_pass(p_mkdir("empty_standard_repo/r", 0777));
cl_git_mkfile("empty_standard_repo/r/a", "hello");
cl_must_pass(p_mkdir("empty_standard_repo/r/b", 0777));
cl_git_mkfile("empty_standard_repo/r/b/problem", "not me");
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0000));
cl_must_pass(p_mkdir("empty_standard_repo/r/c", 0777));
cl_git_mkfile("empty_standard_repo/r/c/foo", "aloha");
cl_git_mkfile("empty_standard_repo/r/d", "final");
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo/r", NULL));
cl_git_pass(git_iterator_advance(&e, i)); /* a */
cl_assert_equal_s("a", e->path);
cl_git_pass(git_iterator_advance(&e, i)); /* c/foo */
cl_assert_equal_s("c/foo", e->path);
cl_git_pass(git_iterator_advance(&e, i)); /* d */
cl_assert_equal_s("d", e->path);
cl_must_pass(p_chmod("empty_standard_repo/r/b", 0777));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
git_iterator_free(i);
}
void test_iterator_workdir__skips_fifos_and_special_files(void)
{
#ifndef GIT_WIN32
git_iterator *i;
const git_index_entry *e;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_must_pass(p_mkdir("empty_standard_repo/dir", 0777));
cl_git_mkfile("empty_standard_repo/file", "not me");
cl_assert(!mkfifo("empty_standard_repo/fifo", 0777));
cl_assert(!access("empty_standard_repo/fifo", F_OK));
i_opts.flags = GIT_ITERATOR_INCLUDE_TREES |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_iterator_for_filesystem(
&i, "empty_standard_repo", &i_opts));
cl_git_pass(git_iterator_advance(&e, i)); /* .git */
cl_assert(S_ISDIR(e->mode));
cl_git_pass(git_iterator_advance(&e, i)); /* dir */
cl_assert(S_ISDIR(e->mode));
/* skips fifo */
cl_git_pass(git_iterator_advance(&e, i)); /* file */
cl_assert(S_ISREG(e->mode));
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&e, i));
git_iterator_free(i);
#else
cl_skip();
#endif
}
void test_iterator_workdir__pathlist(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 100, NULL));
cl_git_pass(git_vector_insert(&filelist, "a"));
cl_git_pass(git_vector_insert(&filelist, "B"));
cl_git_pass(git_vector_insert(&filelist, "c"));
cl_git_pass(git_vector_insert(&filelist, "D"));
cl_git_pass(git_vector_insert(&filelist, "e"));
cl_git_pass(git_vector_insert(&filelist, "k.a"));
cl_git_pass(git_vector_insert(&filelist, "k.b"));
cl_git_pass(git_vector_insert(&filelist, "k/1"));
cl_git_pass(git_vector_insert(&filelist, "k/a"));
cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
cl_git_pass(git_vector_insert(&filelist, "L/1"));
g_repo = cl_git_sandbox_init("icase");
/* Test iterators without returning tree entries (but autoexpanding.) */
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
/* Case sensitive */
{
const char *expected[] = {
"B", "D", "L/1", "a", "c", "e", "k/1", "k/a" };
size_t expected_len = 8;
i_opts.start = NULL;
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Case INsensitive */
{
const char *expected[] = {
"a", "B", "c", "D", "e", "k/1", "k/a", "L/1" };
size_t expected_len = 8;
i_opts.start = NULL;
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set a start, but no end. Case sensitive. */
{
const char *expected[] = { "c", "e", "k/1", "k/a" };
size_t expected_len = 4;
i_opts.start = "c";
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set a start, but no end. Case INsensitive. */
{
const char *expected[] = { "c", "D", "e", "k/1", "k/a", "L/1" };
size_t expected_len = 6;
i_opts.start = "c";
i_opts.end = NULL;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set no start, but an end. Case sensitive. */
{
const char *expected[] = { "B", "D", "L/1", "a", "c", "e" };
size_t expected_len = 6;
i_opts.start = NULL;
i_opts.end = "e";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Set no start, but an end. Case INsensitive. */
{
const char *expected[] = { "a", "B", "c", "D", "e" };
size_t expected_len = 5;
i_opts.start = NULL;
i_opts.end = "e";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case sensitive */
{
const char *expected[] = { "c", "e", "k/1" };
size_t expected_len = 3;
i_opts.start = "c";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case sensitive */
{
const char *expected[] = { "k/1" };
size_t expected_len = 1;
i_opts.start = "k";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case INsensitive */
{
const char *expected[] = { "c", "D", "e", "k/1", "k/a" };
size_t expected_len = 5;
i_opts.start = "c";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Start and an end, case INsensitive */
{
const char *expected[] = { "k/1", "k/a" };
size_t expected_len = 2;
i_opts.start = "k";
i_opts.end = "k/D";
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_vector_free(&filelist);
}
void test_iterator_workdir__pathlist_with_dirs(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = cl_git_sandbox_init("icase");
/* Test that a prefix `k` matches folders, even without trailing slash */
{
const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "k"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that a `k/` matches a folder */
{
const char *expected[] = { "k/1", "k/B", "k/D", "k/a", "k/c" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "k/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* When the iterator is case sensitive, ensure we can't lookup the
* directory with the wrong case.
*/
{
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
}
/* Test that case insensitive matching works. */
{
const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that case insensitive matching works without trailing slash. */
{
const char *expected[] = { "k/1", "k/a", "k/B", "k/c", "k/D" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "K"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_vector_free(&filelist);
}
static void create_paths(const char *root, int depth)
{
git_buf fullpath = GIT_BUF_INIT;
size_t root_len;
int i;
cl_git_pass(git_buf_puts(&fullpath, root));
cl_git_pass(git_path_to_dir(&fullpath));
root_len = fullpath.size;
for (i = 0; i < 8; i++) {
bool file = (depth == 0 || (i % 2) == 0);
git_buf_truncate(&fullpath, root_len);
cl_git_pass(git_buf_printf(&fullpath, "item%d", i));
if (file) {
cl_git_rewritefile(fullpath.ptr, "This is a file!\n");
} else {
cl_must_pass(p_mkdir(fullpath.ptr, 0777));
if (depth > 0)
create_paths(fullpath.ptr, (depth - 1));
}
}
git_buf_dispose(&fullpath);
}
void test_iterator_workdir__pathlist_for_deeply_nested_item(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = cl_git_sandbox_init("icase");
create_paths(git_repository_workdir(g_repo), 3);
/* Ensure that we find the single path we're interested in, and we find
* it efficiently, and don't stat the entire world to get there.
*/
{
const char *expected[] = { "item1/item3/item5/item7" };
size_t expected_len = 1;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/item7"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
cl_assert_equal_i(4, i->stat_calls);
git_iterator_free(i);
}
/* Ensure that we find the single path we're interested in, and we find
* it efficiently, and don't stat the entire world to get there.
*/
{
const char *expected[] = {
"item1/item3/item5/item0", "item1/item3/item5/item1",
"item1/item3/item5/item2", "item1/item3/item5/item3",
"item1/item3/item5/item4", "item1/item3/item5/item5",
"item1/item3/item5/item6", "item1/item3/item5/item7",
};
size_t expected_len = 8;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/item5/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
cl_assert_equal_i(11, i->stat_calls);
git_iterator_free(i);
}
/* Ensure that we find the single path we're interested in, and we find
* it efficiently, and don't stat the entire world to get there.
*/
{
const char *expected[] = {
"item1/item3/item0",
"item1/item3/item1/item0", "item1/item3/item1/item1",
"item1/item3/item1/item2", "item1/item3/item1/item3",
"item1/item3/item1/item4", "item1/item3/item1/item5",
"item1/item3/item1/item6", "item1/item3/item1/item7",
"item1/item3/item2",
"item1/item3/item3/item0", "item1/item3/item3/item1",
"item1/item3/item3/item2", "item1/item3/item3/item3",
"item1/item3/item3/item4", "item1/item3/item3/item5",
"item1/item3/item3/item6", "item1/item3/item3/item7",
"item1/item3/item4",
"item1/item3/item5/item0", "item1/item3/item5/item1",
"item1/item3/item5/item2", "item1/item3/item5/item3",
"item1/item3/item5/item4", "item1/item3/item5/item5",
"item1/item3/item5/item6", "item1/item3/item5/item7",
"item1/item3/item6",
"item1/item3/item7/item0", "item1/item3/item7/item1",
"item1/item3/item7/item2", "item1/item3/item7/item3",
"item1/item3/item7/item4", "item1/item3/item7/item5",
"item1/item3/item7/item6", "item1/item3/item7/item7",
};
size_t expected_len = 36;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item1/item3/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
cl_assert_equal_i(42, i->stat_calls);
git_iterator_free(i);
}
/* Ensure that we find the single path we're interested in, and we find
* it efficiently, and don't stat the entire world to get there.
*/
{
const char *expected[] = {
"item0", "item1/item2", "item5/item7/item4", "item6",
"item7/item3/item1/item6" };
size_t expected_len = 5;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "item7/item3/item1/item6"));
cl_git_pass(git_vector_insert(&filelist, "item6"));
cl_git_pass(git_vector_insert(&filelist, "item5/item7/item4"));
cl_git_pass(git_vector_insert(&filelist, "item1/item2"));
cl_git_pass(git_vector_insert(&filelist, "item0"));
/* also add some things that don't exist or don't match the right type */
cl_git_pass(git_vector_insert(&filelist, "item2/"));
cl_git_pass(git_vector_insert(&filelist, "itemN"));
cl_git_pass(git_vector_insert(&filelist, "item1/itemA"));
cl_git_pass(git_vector_insert(&filelist, "item5/item3/item4/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
cl_assert_equal_i(14, i->stat_calls);
git_iterator_free(i);
}
git_vector_free(&filelist);
}
void test_iterator_workdir__bounded_submodules(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
git_index *index;
git_tree *head;
cl_git_pass(git_vector_init(&filelist, 5, NULL));
g_repo = setup_fixture_submod2();
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_repository_head_tree(&head, g_repo));
/* Test that a submodule matches */
{
const char *expected[] = { "sm_changed_head" };
size_t expected_len = 1;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "sm_changed_head"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that a submodule still matches when suffixed with a '/' */
{
const char *expected[] = { "sm_changed_head" };
size_t expected_len = 1;
git_vector_clear(&filelist);
cl_git_pass(git_vector_insert(&filelist, "sm_changed_head/"));
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that start/end work with a submodule */
{
const char *expected[] = { "sm_changed_head", "sm_changed_index" };
size_t expected_len = 2;
i_opts.start = "sm_changed_head";
i_opts.end = "sm_changed_index";
i_opts.pathlist.strings = NULL;
i_opts.pathlist.count = 0;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
/* Test that start and end allow '/' suffixes of submodules */
{
const char *expected[] = { "sm_changed_head", "sm_changed_index" };
size_t expected_len = 2;
i_opts.start = "sm_changed_head";
i_opts.end = "sm_changed_index";
i_opts.pathlist.strings = NULL;
i_opts.pathlist.count = 0;
i_opts.flags = GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, index, head, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
}
git_vector_free(&filelist);
git_index_free(index);
git_tree_free(head);
}
void test_iterator_workdir__advance_over(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
g_repo = cl_git_sandbox_init("icase");
/* create an empty directory */
cl_must_pass(p_mkdir("icase/empty", 0777));
/* create a directory in which all contents are ignored */
cl_must_pass(p_mkdir("icase/all_ignored", 0777));
cl_git_rewritefile("icase/all_ignored/one", "This is ignored\n");
cl_git_rewritefile("icase/all_ignored/two", "This, too, is ignored\n");
cl_git_rewritefile("icase/all_ignored/.gitignore", ".gitignore\none\ntwo\n");
/* create a directory in which not all contents are ignored */
cl_must_pass(p_mkdir("icase/some_ignored", 0777));
cl_git_rewritefile("icase/some_ignored/one", "This is ignored\n");
cl_git_rewritefile("icase/some_ignored/two", "This is not ignored\n");
cl_git_rewritefile("icase/some_ignored/.gitignore", ".gitignore\none\n");
/* create a directory which has some empty children */
cl_must_pass(p_mkdir("icase/empty_children", 0777));
cl_must_pass(p_mkdir("icase/empty_children/empty1", 0777));
cl_must_pass(p_mkdir("icase/empty_children/empty2", 0777));
cl_must_pass(p_mkdir("icase/empty_children/empty3", 0777));
/* create a directory which will disappear! */
cl_must_pass(p_mkdir("icase/missing_directory", 0777));
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
cl_must_pass(p_rmdir("icase/missing_directory"));
expect_advance_over(i, "B", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "D", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "F", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "H", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "J", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "L/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "a", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "all_ignored/", GIT_ITERATOR_STATUS_IGNORED);
expect_advance_over(i, "c", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "e", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "empty/", GIT_ITERATOR_STATUS_EMPTY);
expect_advance_over(i, "empty_children/", GIT_ITERATOR_STATUS_EMPTY);
expect_advance_over(i, "g", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "i", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "k/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "missing_directory/", GIT_ITERATOR_STATUS_EMPTY);
expect_advance_over(i, "some_ignored/", GIT_ITERATOR_STATUS_NORMAL);
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
}
void test_iterator_workdir__advance_over_with_pathlist(void)
{
git_vector pathlist = GIT_VECTOR_INIT;
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector_insert(&pathlist, "dirA/subdir1/subdir2/file");
git_vector_insert(&pathlist, "dirB/subdir1/subdir2");
git_vector_insert(&pathlist, "dirC/subdir1/nonexistent");
git_vector_insert(&pathlist, "dirD/subdir1/nonexistent");
git_vector_insert(&pathlist, "dirD/subdir1/subdir2");
git_vector_insert(&pathlist, "dirD/nonexistent");
i_opts.pathlist.strings = (char **)pathlist.contents;
i_opts.pathlist.count = pathlist.length;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
g_repo = cl_git_sandbox_init("icase");
/* Create a directory that has a file that is included in our pathlist */
cl_must_pass(p_mkdir("icase/dirA", 0777));
cl_must_pass(p_mkdir("icase/dirA/subdir1", 0777));
cl_must_pass(p_mkdir("icase/dirA/subdir1/subdir2", 0777));
cl_git_rewritefile("icase/dirA/subdir1/subdir2/file", "foo!");
/* Create a directory that has a directory that is included in our pathlist */
cl_must_pass(p_mkdir("icase/dirB", 0777));
cl_must_pass(p_mkdir("icase/dirB/subdir1", 0777));
cl_must_pass(p_mkdir("icase/dirB/subdir1/subdir2", 0777));
cl_git_rewritefile("icase/dirB/subdir1/subdir2/file", "foo!");
/* Create a directory that would contain an entry in our pathlist, but
* that entry does not actually exist. We don't know this until we
* advance_over it. We want to distinguish this from an actually empty
* or ignored directory.
*/
cl_must_pass(p_mkdir("icase/dirC", 0777));
cl_must_pass(p_mkdir("icase/dirC/subdir1", 0777));
cl_must_pass(p_mkdir("icase/dirC/subdir1/subdir2", 0777));
cl_git_rewritefile("icase/dirC/subdir1/subdir2/file", "foo!");
/* Create a directory that has a mix of actual and nonexistent paths */
cl_must_pass(p_mkdir("icase/dirD", 0777));
cl_must_pass(p_mkdir("icase/dirD/subdir1", 0777));
cl_must_pass(p_mkdir("icase/dirD/subdir1/subdir2", 0777));
cl_git_rewritefile("icase/dirD/subdir1/subdir2/file", "foo!");
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_advance_over(i, "dirA/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "dirB/", GIT_ITERATOR_STATUS_NORMAL);
expect_advance_over(i, "dirC/", GIT_ITERATOR_STATUS_FILTERED);
expect_advance_over(i, "dirD/", GIT_ITERATOR_STATUS_NORMAL);
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
git_vector_free(&pathlist);
}
void test_iterator_workdir__advance_into(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
g_repo = cl_git_sandbox_init("icase");
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE |
GIT_ITERATOR_DONT_AUTOEXPAND;
cl_must_pass(p_mkdir("icase/Empty", 0777));
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_advance_into(i, "B");
expect_advance_into(i, "D");
expect_advance_into(i, "Empty/");
expect_advance_into(i, "F");
expect_advance_into(i, "H");
expect_advance_into(i, "J");
expect_advance_into(i, "L/");
expect_advance_into(i, "L/1");
expect_advance_into(i, "L/B");
expect_advance_into(i, "L/D");
expect_advance_into(i, "L/a");
expect_advance_into(i, "L/c");
expect_advance_into(i, "a");
expect_advance_into(i, "c");
expect_advance_into(i, "e");
expect_advance_into(i, "g");
expect_advance_into(i, "i");
expect_advance_into(i, "k/");
expect_advance_into(i, "k/1");
expect_advance_into(i, "k/B");
expect_advance_into(i, "k/D");
expect_advance_into(i, "k/a");
expect_advance_into(i, "k/c");
cl_git_fail_with(GIT_ITEROVER, git_iterator_advance(NULL, i));
git_iterator_free(i);
}
void test_iterator_workdir__pathlist_with_directory(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
const char *expected[] = { "subdir/README", "subdir/new.txt",
"subdir/subdir2/README", "subdir/subdir2/new.txt" };
size_t expected_len = 4;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir/"));
g_repo = cl_git_sandbox_init("testrepo2");
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_vector_free(&filelist);
}
void test_iterator_workdir__pathlist_with_directory_include_trees(void)
{
git_iterator *i;
git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
git_vector filelist;
const char *expected[] = { "subdir/", "subdir/README", "subdir/new.txt",
"subdir/subdir2/", "subdir/subdir2/README", "subdir/subdir2/new.txt", };
size_t expected_len = 6;
cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
cl_git_pass(git_vector_insert(&filelist, "subdir/"));
g_repo = cl_git_sandbox_init("testrepo2");
i_opts.pathlist.strings = (char **)filelist.contents;
i_opts.pathlist.count = filelist.length;
i_opts.flags |= GIT_ITERATOR_DONT_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES;
cl_git_pass(git_iterator_for_workdir(&i, g_repo, NULL, NULL, &i_opts));
expect_iterator_items(i, expected_len, expected, expected_len, expected);
git_iterator_free(i);
git_vector_free(&filelist);
}
void test_iterator_workdir__hash_when_requested(void)
{
git_iterator *iter;
const git_index_entry *entry;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
git_oid expected_id = {{0}};
size_t i;
struct merge_index_entry expected[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "7c7e08f9559d9e1551b91e1cf68f1d0066109add", 0, "oyster.txt" },
{ 0100644, "898d12687fb35be271c27c795a6b32c8b51da79e", 0, "veal.txt" },
};
g_repo = cl_git_sandbox_init("merge-recursive");
/* do the iteration normally, ensure there are no hashes */
cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts));
for (i = 0; i < sizeof(expected) / sizeof(struct merge_index_entry); i++) {
cl_git_pass(git_iterator_advance(&entry, iter));
cl_assert_equal_oid(&expected_id, &entry->id);
cl_assert_equal_s(expected[i].path, entry->path);
}
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&entry, iter));
git_iterator_free(iter);
/* do the iteration requesting hashes */
iter_opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts));
for (i = 0; i < sizeof(expected) / sizeof(struct merge_index_entry); i++) {
cl_git_pass(git_iterator_advance(&entry, iter));
cl_git_pass(git_oid_fromstr(&expected_id, expected[i].oid_str));
cl_assert_equal_oid(&expected_id, &entry->id);
cl_assert_equal_s(expected[i].path, entry->path);
}
cl_assert_equal_i(GIT_ITEROVER, git_iterator_advance(&entry, iter));
git_iterator_free(iter);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/iterator/iterator_helpers.h
|
extern void expect_iterator_items(
git_iterator *i,
size_t expected_flat,
const char **expected_flat_paths,
size_t expected_total,
const char **expected_total_paths);
extern void expect_advance_over(
git_iterator *i,
const char *expected_path,
git_iterator_status_t expected_status);
void expect_advance_into(
git_iterator *i,
const char *expected_path);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/atomic.c
|
#include "clar_libgit2.h"
void test_threads_atomic__atomic32_set(void)
{
git_atomic32 v = {0};
git_atomic32_set(&v, 1);
cl_assert_equal_i(v.val, 1);
}
void test_threads_atomic__atomic32_get(void)
{
git_atomic32 v = {1};
cl_assert_equal_i(git_atomic32_get(&v), 1);
}
void test_threads_atomic__atomic32_inc(void)
{
git_atomic32 v = {0};
cl_assert_equal_i(git_atomic32_inc(&v), 1);
cl_assert_equal_i(v.val, 1);
}
void test_threads_atomic__atomic32_add(void)
{
git_atomic32 v = {0};
cl_assert_equal_i(git_atomic32_add(&v, 1), 1);
cl_assert_equal_i(v.val, 1);
}
void test_threads_atomic__atomic32_dec(void)
{
git_atomic32 v = {1};
cl_assert_equal_i(git_atomic32_dec(&v), 0);
cl_assert_equal_i(v.val, 0);
}
void test_threads_atomic__atomic64_set(void)
{
#ifndef GIT_ARCH_64
cl_skip();
#else
git_atomic64 v = {0};
git_atomic64_set(&v, 1);
cl_assert_equal_i(v.val, 1);
#endif
}
void test_threads_atomic__atomic64_get(void)
{
#ifndef GIT_ARCH_64
cl_skip();
#else
git_atomic64 v = {1};
cl_assert_equal_i(git_atomic64_get(&v), 1);
#endif
}
void test_threads_atomic__atomic64_add(void)
{
#ifndef GIT_ARCH_64
cl_skip();
#else
git_atomic64 v = {0};
cl_assert_equal_i(git_atomic64_add(&v, 1), 1);
cl_assert_equal_i(v.val, 1);
#endif
}
void test_threads_atomic__cas_pointer(void)
{
int *value = NULL;
int newvalue1 = 1, newvalue2 = 2;
/* value is updated */
cl_assert_equal_p(git_atomic_compare_and_swap(&value, NULL, &newvalue1), NULL);
cl_assert_equal_p(value, &newvalue1);
/* value is not updated */
cl_assert_equal_p(git_atomic_compare_and_swap(&value, NULL, &newvalue2), &newvalue1);
cl_assert_equal_p(value, &newvalue1);
}
void test_threads_atomic__cas_intptr(void)
{
intptr_t value = 0;
intptr_t oldvalue;
intptr_t newvalue;
/* value is updated */
oldvalue = 0;
newvalue = 1;
cl_assert_equal_i((intptr_t)git_atomic_compare_and_swap(&value, (void *)oldvalue, (void *)newvalue), 0);
cl_assert_equal_i(value, 1);
/* value is not updated */
oldvalue = 0;
newvalue = 2;
cl_assert_equal_i((intptr_t)git_atomic_compare_and_swap(&value, (void *)oldvalue, (void *)newvalue), 1);
cl_assert_equal_i(value, 1);
}
void test_threads_atomic__swap(void)
{
int *value = NULL;
int newvalue = 1;
cl_assert_equal_p(git_atomic_swap(value, &newvalue), NULL);
cl_assert_equal_p(value, &newvalue);
cl_assert_equal_p(git_atomic_swap(value, NULL), &newvalue);
cl_assert_equal_p(value, NULL);
}
void test_threads_atomic__load_ptr(void)
{
int value = 1;
int *ptr = &value;
cl_assert_equal_p(git_atomic_load(ptr), &value);
}
void test_threads_atomic__load_intptr(void)
{
intptr_t value = 1;
cl_assert_equal_i((intptr_t)git_atomic_load(value), 1);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/diff.c
|
#include "clar_libgit2.h"
#include "thread_helpers.h"
#ifdef GIT_THREADS
# if defined(GIT_WIN32)
# define git_thread_yield() Sleep(0)
# elif defined(__FreeBSD__) || defined(__MidnightBSD__) || defined(__DragonFly__)
# define git_thread_yield() pthread_yield()
# else
# define git_thread_yield() sched_yield()
# endif
#else
# define git_thread_yield() (void)0
#endif
static git_repository *_repo;
static git_tree *_a, *_b;
static git_atomic32 _counts[4];
static int _check_counts;
#ifdef GIT_WIN32
static int _retries;
#endif
#define THREADS 20
void test_threads_diff__initialize(void)
{
#ifdef GIT_WIN32
_retries = git_win32__retries;
git_win32__retries = 1;
#endif
}
void test_threads_diff__cleanup(void)
{
cl_git_sandbox_cleanup();
#ifdef GIT_WIN32
git_win32__retries = _retries;
#endif
}
static void setup_trees(void)
{
git_index *idx;
_repo = cl_git_sandbox_reopen(); /* reopen sandbox to flush caches */
/* avoid competing to load initial index */
cl_git_pass(git_repository_index(&idx, _repo));
git_index_free(idx);
cl_git_pass(git_revparse_single(
(git_object **)&_a, _repo, "0017bd4ab1^{tree}"));
cl_git_pass(git_revparse_single(
(git_object **)&_b, _repo, "26a125ee1b^{tree}"));
memset(_counts, 0, sizeof(_counts));
}
static void free_trees(void)
{
git_tree_free(_a); _a = NULL;
git_tree_free(_b); _b = NULL;
if (_check_counts) {
cl_assert_equal_i(288, git_atomic32_get(&_counts[0]));
cl_assert_equal_i(112, git_atomic32_get(&_counts[1]));
cl_assert_equal_i( 80, git_atomic32_get(&_counts[2]));
cl_assert_equal_i( 96, git_atomic32_get(&_counts[3]));
}
}
static void *run_index_diffs(void *arg)
{
int thread = *(int *)arg;
git_repository *repo;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
size_t i;
int exp[4] = { 0, 0, 0, 0 };
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
switch (thread & 0x03) {
case 0: /* diff index to workdir */;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, NULL, &opts));
break;
case 1: /* diff tree 'a' to index */;
cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, NULL, &opts));
break;
case 2: /* diff tree 'b' to index */;
cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, NULL, &opts));
break;
case 3: /* diff index to workdir (explicit index) */;
{
git_index *idx;
cl_git_pass(git_repository_index(&idx, repo));
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
git_index_free(idx);
break;
}
}
/* keep some diff stats to make sure results are as expected */
i = git_diff_num_deltas(diff);
git_atomic32_add(&_counts[0], (int32_t)i);
exp[0] = (int)i;
while (i > 0) {
switch (git_diff_get_delta(diff, --i)->status) {
case GIT_DELTA_MODIFIED: exp[1]++; git_atomic32_inc(&_counts[1]); break;
case GIT_DELTA_ADDED: exp[2]++; git_atomic32_inc(&_counts[2]); break;
case GIT_DELTA_DELETED: exp[3]++; git_atomic32_inc(&_counts[3]); break;
default: break;
}
}
switch (thread & 0x03) {
case 0: case 3:
cl_assert_equal_i(8, exp[0]); cl_assert_equal_i(4, exp[1]);
cl_assert_equal_i(0, exp[2]); cl_assert_equal_i(4, exp[3]);
break;
case 1:
cl_assert_equal_i(12, exp[0]); cl_assert_equal_i(3, exp[1]);
cl_assert_equal_i(7, exp[2]); cl_assert_equal_i(2, exp[3]);
break;
case 2:
cl_assert_equal_i(8, exp[0]); cl_assert_equal_i(3, exp[1]);
cl_assert_equal_i(3, exp[2]); cl_assert_equal_i(2, exp[3]);
break;
}
git_diff_free(diff);
git_repository_free(repo);
git_error_clear();
return arg;
}
void test_threads_diff__concurrent_diffs(void)
{
_repo = cl_git_sandbox_init("status");
_check_counts = 1;
run_in_parallel(
5, 32, run_index_diffs, setup_trees, free_trees);
}
static void *run_index_diffs_with_modifier(void *arg)
{
int thread = *(int *)arg;
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
git_diff *diff = NULL;
git_index *idx = NULL;
git_repository *repo;
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
cl_git_pass(git_repository_index(&idx, repo));
/* have first thread altering the index as we go */
if (thread == 0) {
int i;
for (i = 0; i < 300; ++i) {
switch (i & 0x03) {
case 0: (void)git_index_add_bypath(idx, "new_file"); break;
case 1: (void)git_index_remove_bypath(idx, "modified_file"); break;
case 2: (void)git_index_remove_bypath(idx, "new_file"); break;
case 3: (void)git_index_add_bypath(idx, "modified_file"); break;
}
git_thread_yield();
}
goto done;
}
/* only use explicit index in this test to prevent reloading */
switch (thread & 0x03) {
case 0: /* diff index to workdir */;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
break;
case 1: /* diff tree 'a' to index */;
cl_git_pass(git_diff_tree_to_index(&diff, repo, _a, idx, &opts));
break;
case 2: /* diff tree 'b' to index */;
cl_git_pass(git_diff_tree_to_index(&diff, repo, _b, idx, &opts));
break;
case 3: /* diff index to workdir reversed */;
opts.flags |= GIT_DIFF_REVERSE;
cl_git_pass(git_diff_index_to_workdir(&diff, repo, idx, &opts));
break;
}
/* results will be unpredictable with index modifier thread running */
git_diff_free(diff);
done:
git_index_free(idx);
git_repository_free(repo);
git_error_clear();
return arg;
}
void test_threads_diff__with_concurrent_index_modified(void)
{
_repo = cl_git_sandbox_init("status");
_check_counts = 0;
run_in_parallel(
5, 16, run_index_diffs_with_modifier, setup_trees, free_trees);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/basic.c
|
#include "clar_libgit2.h"
#include "thread_helpers.h"
#include "cache.h"
static git_repository *g_repo;
void test_threads_basic__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_threads_basic__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_threads_basic__cache(void)
{
/* run several threads polling the cache at the same time */
cl_assert(1 == 1);
}
void test_threads_basic__multiple_init(void)
{
git_repository *nested_repo;
git_libgit2_init();
cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
git_repository_free(nested_repo);
git_libgit2_shutdown();
cl_git_pass(git_repository_open(&nested_repo, cl_fixture("testrepo.git")));
git_repository_free(nested_repo);
}
static void *set_error(void *dummy)
{
git_error_set(GIT_ERROR_INVALID, "oh no, something happened!\n");
return dummy;
}
/* Set errors so we can check that we free it */
void test_threads_basic__set_error(void)
{
run_in_parallel(1, 4, set_error, NULL, NULL);
}
#ifdef GIT_THREADS
static void *return_normally(void *param)
{
return param;
}
static void *exit_abruptly(void *param)
{
git_thread_exit(param);
return NULL;
}
#endif
void test_threads_basic__exit(void)
{
#ifndef GIT_THREADS
clar__skip();
#else
git_thread thread;
void *result;
/* Ensure that the return value of the threadproc is returned. */
cl_git_pass(git_thread_create(&thread, return_normally, (void *)424242));
cl_git_pass(git_thread_join(&thread, &result));
cl_assert_equal_sz(424242, (size_t)result);
/* Ensure that the return value of `git_thread_exit` is returned. */
cl_git_pass(git_thread_create(&thread, exit_abruptly, (void *)232323));
cl_git_pass(git_thread_join(&thread, &result));
cl_assert_equal_sz(232323, (size_t)result);
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/thread_helpers.h
|
#include "thread.h"
void run_in_parallel(
int repeats,
int threads,
void *(*func)(void *),
void (*before_test)(void),
void (*after_test)(void));
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/thread_helpers.c
|
#include "clar_libgit2.h"
#include "thread_helpers.h"
void run_in_parallel(
int repeats,
int threads,
void *(*func)(void *),
void (*before_test)(void),
void (*after_test)(void))
{
int r, t, *id = git__calloc(threads, sizeof(int));
#ifdef GIT_THREADS
git_thread *th = git__calloc(threads, sizeof(git_thread));
cl_assert(th != NULL);
#else
void *th = NULL;
#endif
cl_assert(id != NULL);
for (r = 0; r < repeats; ++r) {
if (before_test) before_test();
for (t = 0; t < threads; ++t) {
id[t] = t;
#ifdef GIT_THREADS
cl_git_pass(git_thread_create(&th[t], func, &id[t]));
#else
cl_assert(func(&id[t]) == &id[t]);
#endif
}
#ifdef GIT_THREADS
for (t = 0; t < threads; ++t)
cl_git_pass(git_thread_join(&th[t], NULL));
memset(th, 0, threads * sizeof(git_thread));
#endif
if (after_test) after_test();
}
git__free(id);
git__free(th);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/refdb.c
|
#include "clar_libgit2.h"
#include "git2/refdb.h"
#include "refdb.h"
static git_repository *g_repo;
static int g_expected = 0;
#ifdef GIT_WIN32
static bool concurrent_compress = false;
#else
static bool concurrent_compress = true;
#endif
void test_threads_refdb__initialize(void)
{
g_repo = NULL;
}
void test_threads_refdb__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
#define REPEAT 20
#define THREADS 20
/* Number of references to create or delete in each thread */
#define NREFS 10
struct th_data {
cl_git_thread_err error;
int id;
const char *path;
};
static void *iterate_refs(void *arg)
{
struct th_data *data = (struct th_data *) arg;
git_reference_iterator *i;
git_reference *ref;
int count = 0, error;
git_repository *repo;
cl_git_thread_pass(data, git_repository_open(&repo, data->path));
do {
error = git_reference_iterator_new(&i, repo);
} while (error == GIT_ELOCKED);
cl_git_thread_pass(data, error);
for (count = 0; !git_reference_next(&ref, i); ++count) {
cl_assert(ref != NULL);
git_reference_free(ref);
}
if (g_expected > 0)
cl_assert_equal_i(g_expected, count);
git_reference_iterator_free(i);
git_repository_free(repo);
git_error_clear();
return arg;
}
static void *create_refs(void *arg)
{
int i, error;
struct th_data *data = (struct th_data *) arg;
git_oid head;
char name[128];
git_reference *ref[NREFS];
git_repository *repo;
cl_git_thread_pass(data, git_repository_open(&repo, data->path));
do {
error = git_reference_name_to_id(&head, repo, "HEAD");
} while (error == GIT_ELOCKED);
cl_git_thread_pass(data, error);
for (i = 0; i < NREFS; ++i) {
p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", data->id, i);
do {
error = git_reference_create(&ref[i], repo, name, &head, 0, NULL);
} while (error == GIT_ELOCKED);
cl_git_thread_pass(data, error);
if (concurrent_compress && i == NREFS/2) {
git_refdb *refdb;
cl_git_thread_pass(data, git_repository_refdb(&refdb, repo));
do {
error = git_refdb_compress(refdb);
} while (error == GIT_ELOCKED);
cl_git_thread_pass(data, error);
git_refdb_free(refdb);
}
}
for (i = 0; i < NREFS; ++i)
git_reference_free(ref[i]);
git_repository_free(repo);
git_error_clear();
return arg;
}
static void *delete_refs(void *arg)
{
int i, error;
struct th_data *data = (struct th_data *) arg;
git_reference *ref;
char name[128];
git_repository *repo;
cl_git_thread_pass(data, git_repository_open(&repo, data->path));
for (i = 0; i < NREFS; ++i) {
p_snprintf(
name, sizeof(name), "refs/heads/thread-%03d-%02d", (data->id) & ~0x3, i);
if (!git_reference_lookup(&ref, repo, name)) {
do {
error = git_reference_delete(ref);
} while (error == GIT_ELOCKED);
/* Sometimes we race with other deleter threads */
if (error == GIT_ENOTFOUND)
error = 0;
cl_git_thread_pass(data, error);
git_reference_free(ref);
}
if (concurrent_compress && i == NREFS/2) {
git_refdb *refdb;
cl_git_thread_pass(data, git_repository_refdb(&refdb, repo));
do {
error = git_refdb_compress(refdb);
} while (error == GIT_ELOCKED);
cl_git_thread_pass(data, error);
git_refdb_free(refdb);
}
}
git_repository_free(repo);
git_error_clear();
return arg;
}
void test_threads_refdb__edit_while_iterate(void)
{
int r, t;
struct th_data th_data[THREADS];
git_oid head;
git_reference *ref;
char name[128];
git_refdb *refdb;
#ifdef GIT_THREADS
git_thread th[THREADS];
#endif
g_repo = cl_git_sandbox_init("testrepo2");
cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD"));
/* make a bunch of references */
for (r = 0; r < 50; ++r) {
p_snprintf(name, sizeof(name), "refs/heads/starter-%03d", r);
cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL));
git_reference_free(ref);
}
cl_git_pass(git_repository_refdb(&refdb, g_repo));
cl_git_pass(git_refdb_compress(refdb));
git_refdb_free(refdb);
g_expected = -1;
g_repo = cl_git_sandbox_reopen(); /* reopen to flush caches */
for (t = 0; t < THREADS; ++t) {
void *(*fn)(void *arg);
switch (t & 0x3) {
case 0: fn = create_refs; break;
case 1: fn = delete_refs; break;
default: fn = iterate_refs; break;
}
th_data[t].id = t;
th_data[t].path = git_repository_path(g_repo);
#ifdef GIT_THREADS
cl_git_pass(git_thread_create(&th[t], fn, &th_data[t]));
#else
fn(&th_data[t]);
#endif
}
#ifdef GIT_THREADS
for (t = 0; t < THREADS; ++t) {
cl_git_pass(git_thread_join(&th[t], NULL));
cl_git_thread_check(&th_data[t]);
}
memset(th, 0, sizeof(th));
for (t = 0; t < THREADS; ++t) {
th_data[t].id = t;
cl_git_pass(git_thread_create(&th[t], iterate_refs, &th_data[t]));
}
for (t = 0; t < THREADS; ++t) {
cl_git_pass(git_thread_join(&th[t], NULL));
cl_git_thread_check(&th_data[t]);
}
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/iterator.c
|
#include "clar_libgit2.h"
#include "thread_helpers.h"
#include "iterator.h"
static git_repository *_repo;
void test_threads_iterator__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void *run_workdir_iterator(void *arg)
{
int error = 0;
git_repository *repo;
git_iterator *iter;
git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT;
const git_index_entry *entry = NULL;
iter_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND;
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
cl_git_pass(git_iterator_for_workdir(
&iter, repo, NULL, NULL, &iter_opts));
while (!error) {
if (entry && entry->mode == GIT_FILEMODE_TREE) {
error = git_iterator_advance_into(&entry, iter);
if (error == GIT_ENOTFOUND)
error = git_iterator_advance(&entry, iter);
} else {
error = git_iterator_advance(&entry, iter);
}
if (!error)
(void)git_iterator_current_is_ignored(iter);
}
cl_assert_equal_i(GIT_ITEROVER, error);
git_iterator_free(iter);
git_repository_free(repo);
git_error_clear();
return arg;
}
void test_threads_iterator__workdir(void)
{
_repo = cl_git_sandbox_init("status");
run_in_parallel(
1, 20, run_workdir_iterator, NULL, NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/threads/tlsdata.c
|
#include "clar_libgit2.h"
#include "thread_helpers.h"
void test_threads_tlsdata__can_set_and_get(void)
{
git_tlsdata_key key_one, key_two, key_three;
cl_git_pass(git_tlsdata_init(&key_one, NULL));
cl_git_pass(git_tlsdata_init(&key_two, NULL));
cl_git_pass(git_tlsdata_init(&key_three, NULL));
cl_git_pass(git_tlsdata_set(key_one, (void *)(size_t)42424242));
cl_git_pass(git_tlsdata_set(key_two, (void *)(size_t)0xdeadbeef));
cl_git_pass(git_tlsdata_set(key_three, (void *)(size_t)98761234));
cl_assert_equal_sz((size_t)42424242, git_tlsdata_get(key_one));
cl_assert_equal_sz((size_t)0xdeadbeef, git_tlsdata_get(key_two));
cl_assert_equal_sz((size_t)98761234, git_tlsdata_get(key_three));
cl_git_pass(git_tlsdata_dispose(key_one));
cl_git_pass(git_tlsdata_dispose(key_two));
cl_git_pass(git_tlsdata_dispose(key_three));
}
#ifdef GIT_THREADS
static void *set_and_get(void *param)
{
git_tlsdata_key *tlsdata_key = (git_tlsdata_key *)param;
int val;
if (git_tlsdata_set(*tlsdata_key, &val) != 0 ||
git_tlsdata_get(*tlsdata_key) != &val)
return (void *)0;
return (void *)1;
}
#endif
#define THREAD_COUNT 10
void test_threads_tlsdata__threads(void)
{
#ifdef GIT_THREADS
git_thread thread[THREAD_COUNT];
git_tlsdata_key tlsdata;
int i;
cl_git_pass(git_tlsdata_init(&tlsdata, NULL));
for (i = 0; i < THREAD_COUNT; i++)
cl_git_pass(git_thread_create(&thread[i], set_and_get, &tlsdata));
for (i = 0; i < THREAD_COUNT; i++) {
void *result;
cl_git_pass(git_thread_join(&thread[i], &result));
cl_assert_equal_sz(1, (size_t)result);
}
cl_git_pass(git_tlsdata_dispose(tlsdata));
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/submodule.c
|
#include "clar_libgit2.h"
#include "git2/checkout.h"
#include "git2/rebase.h"
#include "posix.h"
#include "signature.h"
#include "../submodule/submodule_helpers.h"
#include <fcntl.h>
static git_repository *repo;
static git_signature *signature;
/* 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", "[email protected]", 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(index));
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_OBJECT_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);
}
void test_rebase_submodule__cleanup(void)
{
git_signature_free(signature);
cl_git_sandbox_cleanup();
}
void test_rebase_submodule__init_untracked(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_buf untracked_path = GIT_BUF_INIT;
FILE *fp;
git_submodule *submodule;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_submodule_lookup(&submodule, repo, "my-submodule"));
cl_git_pass(git_submodule_update(submodule, 1, NULL));
git_buf_printf(&untracked_path, "%s/my-submodule/untracked", git_repository_workdir(repo));
fp = fopen(git_buf_cstr(&untracked_path), "w");
fprintf(fp, "An untracked file in a submodule should not block a rebase\n");
fclose(fp);
git_buf_dispose(&untracked_path);
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_submodule_free(submodule);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/merge.c
|
#include "clar_libgit2.h"
#include "git2/checkout.h"
#include "git2/rebase.h"
#include "posix.h"
#include "signature.h"
#include <fcntl.h>
static git_repository *repo;
static git_signature *signature;
static void set_core_autocrlf_to(git_repository *repo, bool value)
{
git_config *cfg;
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_set_bool(cfg, "core.autocrlf", value));
git_config_free(cfg);
}
/* Fixture setup and teardown */
void test_rebase_merge__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_signature_new(&signature,
"Rebaser", "[email protected]", 1405694510, 0));
set_core_autocrlf_to(repo, false);
}
void test_rebase_merge__cleanup(void)
{
git_signature_free(signature);
cl_git_sandbox_cleanup();
}
void test_rebase_merge__next(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_status_list *status_list;
const git_status_entry *status_entry;
git_oid pick_id, file1_id;
git_oid master_id, beef_id;
git_oid_fromstr(&master_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
git_oid_fromstr(&beef_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_s("refs/heads/beef", git_rebase_orig_head_name(rebase));
cl_assert_equal_oid(&beef_id, git_rebase_orig_head_id(rebase));
cl_assert_equal_s("master", git_rebase_onto_name(rebase));
cl_assert_equal_oid(&master_id, git_rebase_onto_id(rebase));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
git_oid_fromstr(&pick_id, "da9c51a23d02d931a486f45ad18cda05cf5d2b94");
cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type);
cl_assert_equal_oid(&pick_id, &rebase_operation->id);
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/current");
cl_assert_equal_file("1\n", 2, "rebase/.git/rebase-merge/msgnum");
cl_git_pass(git_status_list_new(&status_list, repo, NULL));
cl_assert_equal_i(1, git_status_list_entrycount(status_list));
cl_assert(status_entry = git_status_byindex(status_list, 0));
cl_assert_equal_s("beef.txt", status_entry->head_to_index->new_file.path);
git_oid_fromstr(&file1_id, "8d95ea62e621f1d38d230d9e7d206e41096d76af");
cl_assert_equal_oid(&file1_id, &status_entry->head_to_index->new_file.id);
git_status_list_free(status_list);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__next_with_conflicts(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_status_list *status_list;
const git_status_entry *status_entry;
git_oid pick_id, commit_id;
const char *expected_merge =
"ASPARAGUS SOUP.\n"
"\n"
"<<<<<<< master\n"
"TAKE FOUR LARGE BUNCHES of asparagus, scrape it nicely, cut off one inch\n"
"OF THE TOPS, and lay them in water, chop the stalks and put them on the\n"
"FIRE WITH A PIECE OF BACON, a large onion cut up, and pepper and salt;\n"
"ADD TWO QUARTS OF WATER, boil them till the stalks are quite soft, then\n"
"PULP THEM THROUGH A SIEVE, and strain the water to it, which must be put\n"
"=======\n"
"Take four large bunches of asparagus, scrape it nicely, CUT OFF ONE INCH\n"
"of the tops, and lay them in water, chop the stalks and PUT THEM ON THE\n"
"fire with a piece of bacon, a large onion cut up, and pepper and salt;\n"
"add two quarts of water, boil them till the stalks are quite soft, then\n"
"pulp them through a sieve, and strain the water to it, which must be put\n"
">>>>>>> Conflicting modification 1 to asparagus\n"
"back in the pot; put into it a chicken cut up, with the tops of\n"
"asparagus which had been laid by, boil it until these last articles are\n"
"sufficiently done, thicken with flour, butter and milk, and serve it up.\n";
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
git_oid_fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500");
cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type);
cl_assert_equal_oid(&pick_id, &rebase_operation->id);
cl_assert_equal_file("33f915f9e4dbd9f4b24430e48731a59b45b15500\n", 41, "rebase/.git/rebase-merge/current");
cl_assert_equal_file("1\n", 2, "rebase/.git/rebase-merge/msgnum");
cl_git_pass(git_status_list_new(&status_list, repo, NULL));
cl_assert_equal_i(1, git_status_list_entrycount(status_list));
cl_assert(status_entry = git_status_byindex(status_list, 0));
cl_assert_equal_s("asparagus.txt", status_entry->head_to_index->new_file.path);
cl_assert_equal_file(expected_merge, strlen(expected_merge), "rebase/asparagus.txt");
cl_git_fail_with(GIT_EUNMERGED, git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_status_list_free(status_list);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__next_stops_with_iterover(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
int error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(GIT_ITEROVER, error);
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/msgnum");
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__commit(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, tree_id, parent_id;
git_signature *author;
git_commit *commit;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_assert_equal_i(1, git_commit_parentcount(commit));
cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0));
git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992");
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
cl_assert_equal_s(NULL, git_commit_message_encoding(commit));
cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit));
cl_git_pass(git_signature_new(&author,
"Edward Thomson", "[email protected]", 1405621769, 0-(4*60)));
cl_assert(git_signature__equal(author, git_commit_author(commit)));
cl_assert(git_signature__equal(signature, git_commit_committer(commit)));
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_signature_free(author);
git_commit_free(commit);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__commit_with_id(void)
{
git_rebase *rebase;
git_oid branch_id, upstream_id;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, tree_id, parent_id;
git_signature *author;
git_commit *commit;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
cl_git_pass(git_oid_fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_assert_equal_i(1, git_commit_parentcount(commit));
cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0));
git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992");
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
cl_assert_equal_s(NULL, git_commit_message_encoding(commit));
cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit));
cl_git_pass(git_signature_new(&author,
"Edward Thomson", "[email protected]", 1405621769, 0-(4*60)));
cl_assert(git_signature__equal(author, git_commit_author(commit)));
cl_assert(git_signature__equal(signature, git_commit_committer(commit)));
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_signature_free(author);
git_commit_free(commit);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_rebase_free(rebase);
}
void test_rebase_merge__blocked_when_dirty(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
/* Allow untracked files */
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_mkfile("rebase/untracked_file.txt", "This is untracked\n");
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
/* Do not allow unstaged */
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_mkfile("rebase/veal.txt", "This is an unstaged change\n");
cl_git_fail_with(GIT_EUNMERGED, git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__commit_updates_rewritten(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_assert_equal_file(
"da9c51a23d02d931a486f45ad18cda05cf5d2b94 776e4c48922799f903f03f5f6e51da8b01e4cce0\n"
"8d1f13f93c4995760ac07d129246ac1ff64c0be9 ba1f9b4fd5cf8151f7818be2111cc0869f1eb95a\n",
164, "rebase/.git/rebase-merge/rewritten");
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__commit_drops_already_applied(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
int error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/green_pea"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_fail(error = git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_assert_equal_i(GIT_EAPPLIED, error);
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_assert_equal_file(
"8d1f13f93c4995760ac07d129246ac1ff64c0be9 2ac4fb7b74c1287f6c792acad759e1ec01e18dae\n",
82, "rebase/.git/rebase-merge/rewritten");
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__finish(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref, *head_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
int error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(GIT_ITEROVER, error);
cl_git_pass(git_rebase_finish(rebase, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head_ref));
cl_assert_equal_s("refs/heads/gravy", git_reference_symbolic_target(head_ref));
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase finished: returning to refs/heads/gravy", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
cl_git_pass(git_reflog_read(&reflog, repo, "refs/heads/gravy"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(git_annotated_commit_id(branch_head), git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase finished: refs/heads/gravy onto f87d14a4a236582a0278a916340a793714256864", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(head_ref);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__detached_finish(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref, *head_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
int error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_repository_set_head_detached_from_annotated(repo, branch_head));
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
git_checkout_head(repo, &opts);
cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(GIT_ITEROVER, error);
cl_git_pass(git_rebase_finish(rebase, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
cl_assert_equal_i(GIT_REFERENCE_DIRECT, git_reference_type(head_ref));
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(git_annotated_commit_id(upstream_head), git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
git_reflog_free(reflog);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(head_ref);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__finish_with_ids(void)
{
git_rebase *rebase;
git_reference *head_ref;
git_oid branch_id, upstream_id;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
int error;
cl_git_pass(git_oid_fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f"));
cl_git_pass(git_oid_fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(GIT_ITEROVER, error);
cl_git_pass(git_rebase_finish(rebase, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
cl_assert_equal_i(GIT_REFERENCE_DIRECT, git_reference_type(head_ref));
cl_assert_equal_oid(&commit_id, git_reference_target(head_ref));
/* reflogs are not updated as if we were operating on proper
* branches. check that the last reflog entry is the rebase.
*/
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: Modification 3 to gravy", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(head_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__no_common_ancestor(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_final_id;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/barley"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_finish(rebase, signature));
git_oid_fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3");
cl_assert_equal_oid(&expected_final_id, &commit_id);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
static void test_copy_note(
const git_rebase_options *opts,
bool should_exist)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_commit *branch_commit;
git_rebase_operation *rebase_operation;
git_oid note_id, commit_id;
git_note *note = NULL;
int error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_reference_peel((git_object **)&branch_commit,
branch_ref, GIT_OBJECT_COMMIT));
/* Add a note to a commit */
cl_git_pass(git_note_create(¬e_id, repo, "refs/notes/test",
git_commit_author(branch_commit), git_commit_committer(branch_commit),
git_commit_id(branch_commit),
"This is a commit note.", 0));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_finish(rebase, signature));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
if (should_exist) {
cl_git_pass(git_note_read(¬e, repo, "refs/notes/test", &commit_id));
cl_assert_equal_s("This is a commit note.", git_note_message(note));
} else {
cl_git_fail(error =
git_note_read(¬e, repo, "refs/notes/test", &commit_id));
cl_assert_equal_i(GIT_ENOTFOUND, error);
}
git_note_free(note);
git_commit_free(branch_commit);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__copy_notes_off_by_default(void)
{
test_copy_note(NULL, 0);
}
void test_rebase_merge__copy_notes_specified_in_options(void)
{
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
opts.rewrite_notes_ref = "refs/notes/test";
test_copy_note(&opts, 1);
}
void test_rebase_merge__copy_notes_specified_in_config(void)
{
git_config *config;
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config,
"notes.rewriteRef", "refs/notes/test"));
test_copy_note(NULL, 1);
}
void test_rebase_merge__copy_notes_disabled_in_config(void)
{
git_config *config;
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_bool(config, "notes.rewrite.rebase", 0));
cl_git_pass(git_config_set_string(config,
"notes.rewriteRef", "refs/notes/test"));
test_copy_note(NULL, 0);
}
void rebase_checkout_progress_cb(
const char *path,
size_t completed_steps,
size_t total_steps,
void *payload)
{
int *called = payload;
GIT_UNUSED(path);
GIT_UNUSED(completed_steps);
GIT_UNUSED(total_steps);
*called = 1;
}
void test_rebase_merge__custom_checkout_options(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_options rebase_options = GIT_REBASE_OPTIONS_INIT;
git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
git_rebase_operation *rebase_operation;
int called = 0;
checkout_options.progress_cb = rebase_checkout_progress_cb;
checkout_options.progress_payload = &called;
memcpy(&rebase_options.checkout_options, &checkout_options,
sizeof(git_checkout_options));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
called = 0;
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_options));
cl_assert_equal_i(1, called);
called = 0;
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(1, called);
called = 0;
cl_git_pass(git_rebase_abort(rebase));
cl_assert_equal_i(1, called);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__custom_merge_options(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_options rebase_options = GIT_REBASE_OPTIONS_INIT;
git_rebase_operation *rebase_operation;
rebase_options.merge_options.flags |=
GIT_MERGE_FAIL_ON_CONFLICT |
GIT_MERGE_SKIP_REUC;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_options));
cl_git_fail_with(GIT_EMERGECONFLICT, git_rebase_next(&rebase_operation, rebase));
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_merge__with_directories(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, tree_id;
git_commit *commit;
git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57");
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
git_commit_free(commit);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/inmemory.c
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "posix.h"
#include <fcntl.h>
static git_repository *repo;
static git_signature *signature;
/* Fixture setup and teardown */
void test_rebase_inmemory__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_signature_new(&signature,
"Rebaser", "[email protected]", 1405694510, 0));
}
void test_rebase_inmemory__cleanup(void)
{
git_signature_free(signature);
cl_git_sandbox_cleanup();
}
void test_rebase_inmemory__not_in_rebase_state(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
opts.inmemory = true;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
git_rebase_free(rebase);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
}
void test_rebase_inmemory__can_resolve_conflicts(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_status_list *status_list;
git_oid pick_id, commit_id, expected_commit_id;
git_index *rebase_index, *repo_index;
git_index_entry resolution = {{0}};
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
opts.inmemory = true;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
git_oid_fromstr(&pick_id, "33f915f9e4dbd9f4b24430e48731a59b45b15500");
cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, rebase_operation->type);
cl_assert_equal_oid(&pick_id, &rebase_operation->id);
/* ensure that we did not do anything stupid to the workdir or repo index */
cl_git_pass(git_repository_index(&repo_index, repo));
cl_assert(!git_index_has_conflicts(repo_index));
cl_git_pass(git_status_list_new(&status_list, repo, NULL));
cl_assert_equal_i(0, git_status_list_entrycount(status_list));
/* but that the index returned from rebase does have conflicts */
cl_git_pass(git_rebase_inmemory_index(&rebase_index, rebase));
cl_assert(git_index_has_conflicts(rebase_index));
cl_git_fail_with(GIT_EUNMERGED, git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
/* ensure that we can work with the in-memory index to resolve the conflict */
resolution.path = "asparagus.txt";
resolution.mode = GIT_FILEMODE_BLOB;
git_oid_fromstr(&resolution.id, "414dfc71ead79c07acd4ea47fecf91f289afc4b9");
cl_git_pass(git_index_conflict_remove(rebase_index, "asparagus.txt"));
cl_git_pass(git_index_add(rebase_index, &resolution));
/* and finally create a commit for the resolved rebase operation */
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
cl_git_pass(git_oid_fromstr(&expected_commit_id, "db7af47222181e548810da2ab5fec0e9357c5637"));
cl_assert_equal_oid(&commit_id, &expected_commit_id);
git_status_list_free(status_list);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_index_free(repo_index);
git_index_free(rebase_index);
git_rebase_free(rebase);
}
void test_rebase_inmemory__no_common_ancestor(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_final_id;
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
opts.inmemory = true;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/barley"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_finish(rebase, signature));
git_oid_fromstr(&expected_final_id, "71e7ee8d4fe7d8bf0d107355197e0a953dfdb7f3");
cl_assert_equal_oid(&expected_final_id, &commit_id);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_inmemory__with_directories(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, tree_id;
git_commit *commit;
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
opts.inmemory = true;
git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57");
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
git_commit_free(commit);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/iterator.c
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "posix.h"
#include <fcntl.h>
static git_repository *repo;
static git_index *_index;
static git_signature *signature;
/* Fixture setup and teardown */
void test_rebase_iterator__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_repository_index(&_index, repo));
cl_git_pass(git_signature_new(&signature, "Rebaser",
"[email protected]", 1405694510, 0));
}
void test_rebase_iterator__cleanup(void)
{
git_signature_free(signature);
git_index_free(_index);
cl_git_sandbox_cleanup();
}
static void test_operations(git_rebase *rebase, size_t expected_current)
{
size_t i, expected_count = 5;
git_oid expected_oid[5];
git_rebase_operation *operation;
git_oid_fromstr(&expected_oid[0], "da9c51a23d02d931a486f45ad18cda05cf5d2b94");
git_oid_fromstr(&expected_oid[1], "8d1f13f93c4995760ac07d129246ac1ff64c0be9");
git_oid_fromstr(&expected_oid[2], "3069cc907e6294623e5917ef6de663928c1febfb");
git_oid_fromstr(&expected_oid[3], "588e5d2f04d49707fe4aab865e1deacaf7ef6787");
git_oid_fromstr(&expected_oid[4], "b146bd7608eac53d9bf9e1a6963543588b555c64");
cl_assert_equal_i(expected_count, git_rebase_operation_entrycount(rebase));
cl_assert_equal_i(expected_current, git_rebase_operation_current(rebase));
for (i = 0; i < expected_count; i++) {
operation = git_rebase_operation_byindex(rebase, i);
cl_assert_equal_i(GIT_REBASE_OPERATION_PICK, operation->type);
cl_assert_equal_oid(&expected_oid[i], &operation->id);
cl_assert_equal_p(NULL, operation->exec);
}
}
void test_iterator(bool inmemory)
{
git_rebase *rebase;
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
int error;
opts.inmemory = inmemory;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
test_operations(rebase, GIT_REBASE_NO_OPERATION);
if (!inmemory) {
git_rebase_free(rebase);
cl_git_pass(git_rebase_open(&rebase, repo, NULL));
}
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 0);
git_oid_fromstr(&expected_id, "776e4c48922799f903f03f5f6e51da8b01e4cce0");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 1);
git_oid_fromstr(&expected_id, "ba1f9b4fd5cf8151f7818be2111cc0869f1eb95a");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 2);
git_oid_fromstr(&expected_id, "948b12fe18b84f756223a61bece4c307787cd5d4");
cl_assert_equal_oid(&expected_id, &commit_id);
if (!inmemory) {
git_rebase_free(rebase);
cl_git_pass(git_rebase_open(&rebase, repo, NULL));
}
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 3);
git_oid_fromstr(&expected_id, "d9d5d59d72c9968687f9462578d79878cd80e781");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
NULL, NULL));
test_operations(rebase, 4);
git_oid_fromstr(&expected_id, "9cf383c0a125d89e742c5dec58ed277dd07588b3");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_fail(error = git_rebase_next(&rebase_operation, rebase));
cl_assert_equal_i(GIT_ITEROVER, error);
test_operations(rebase, 4);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
void test_rebase_iterator__iterates(void)
{
test_iterator(false);
}
void test_rebase_iterator__iterates_inmemory(void)
{
test_iterator(true);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/setup.c
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "posix.h"
#include <fcntl.h>
static git_repository *repo;
static git_index *_index;
static git_signature *signature;
/* Fixture setup and teardown */
void test_rebase_setup__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_repository_index(&_index, repo));
cl_git_pass(git_signature_now(&signature, "Rebaser", "[email protected]"));
}
void test_rebase_setup__cleanup(void)
{
git_signature_free(signature);
git_index_free(_index);
cl_git_sandbox_cleanup();
}
/* git checkout beef ; git rebase --merge master
* git checkout beef ; git rebase --merge master */
void test_rebase_setup__blocked_when_in_progress(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_rebase_free(rebase);
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_git_fail(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
}
/* git checkout beef ; git rebase --merge master */
void test_rebase_setup__merge(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3069cc907e6294623e5917ef6de663928c1febfb\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("588e5d2f04d49707fe4aab865e1deacaf7ef6787\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
/* git checkout beef && git rebase --merge --root --onto master */
void test_rebase_setup__merge_root(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_annotated_commit *branch_head, *onto_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3069cc907e6294623e5917ef6de663928c1febfb\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("588e5d2f04d49707fe4aab865e1deacaf7ef6787\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
/* git checkout gravy && git rebase --merge --onto master veal */
void test_rebase_setup__merge_onto_and_upstream(void)
{
git_rebase *rebase;
git_reference *branch1_ref, *branch2_ref, *onto_ref;
git_annotated_commit *branch1_head, *branch2_head, *onto_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch1_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&branch2_ref, repo, "refs/heads/veal"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch1_head, repo, branch1_ref));
cl_git_pass(git_annotated_commit_from_ref(&branch2_head, repo, branch2_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch1_head, branch2_head, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("1\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch1_head);
git_annotated_commit_free(branch2_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch1_ref);
git_reference_free(branch2_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
/* git checkout beef && git rebase --merge --onto master gravy veal */
void test_rebase_setup__merge_onto_upstream_and_branch(void)
{
git_rebase *rebase;
git_reference *upstream_ref, *branch_ref, *onto_ref;
git_annotated_commit *upstream_head, *branch_head, *onto_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_repository_set_head(repo, "refs/heads/beef"));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/veal"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_assert_equal_file("3e8989b5a16d5258c935d998ef0e6bb139cc4757\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("4cacc6f6e740a5bc64faa33e04b8ef0733d8a127\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("3\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(upstream_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(upstream_ref);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
/* git checkout beef && git rebase --merge --onto `git rev-parse master`
* `git rev-parse veal` `git rev-parse gravy`
*/
void test_rebase_setup__merge_onto_upstream_and_branch_by_id(void)
{
git_rebase *rebase;
git_oid upstream_id, branch_id, onto_id;
git_annotated_commit *upstream_head, *branch_head, *onto_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_repository_set_head(repo, "refs/heads/beef"));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
cl_git_pass(git_oid_fromstr(&upstream_id, "f87d14a4a236582a0278a916340a793714256864"));
cl_git_pass(git_oid_fromstr(&branch_id, "d616d97082eb7bb2dc6f180a7cca940993b7a56f"));
cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, onto_head, NULL));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("1\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("d616d97082eb7bb2dc6f180a7cca940993b7a56f\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(upstream_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_rebase_free(rebase);
}
/* Ensure merge commits are dropped in a rebase */
/* git checkout veal && git rebase --merge master */
void test_rebase_setup__branch_with_merges(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/veal"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("4bed71df7017283cac61bbf726197ad6a5a18b84\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("2aa3ce842094e08ebac152b3d6d5b0fff39f9c6e\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3e8989b5a16d5258c935d998ef0e6bb139cc4757\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("4cacc6f6e740a5bc64faa33e04b8ef0733d8a127\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("f87d14a4a236582a0278a916340a793714256864\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
/* git checkout barley && git rebase --merge master */
void test_rebase_setup__orphan_branch(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/barley"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("12c084412b952396962eb420716df01022b847cc\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("aa4c42aecdfc7cd989bbc3209934ea7cda3f4d88\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("e4f809f826c1a9fc929874bc0e4644dd2f2a1af4\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("9539b2cc291d6a6b1b266df8474d31fdd344dd79\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("013cc32d341bab0e6f039f50f153c18986f16c58\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("12c084412b952396962eb420716df01022b847cc\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("12c084412b952396962eb420716df01022b847cc\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
/* git checkout beef && git rebase --merge master */
void test_rebase_setup__merge_null_branch_uses_HEAD(void)
{
git_rebase *rebase;
git_reference *upstream_ref;
git_annotated_commit *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_repository_set_head(repo, "refs/heads/beef"));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, NULL, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3069cc907e6294623e5917ef6de663928c1febfb\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("588e5d2f04d49707fe4aab865e1deacaf7ef6787\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(upstream_head);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
/* git checkout b146bd7608eac53d9bf9e1a6963543588b555c64 && git rebase --merge master */
void test_rebase_setup__merge_from_detached(void)
{
git_rebase *rebase;
git_reference *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid branch_id, head_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3069cc907e6294623e5917ef6de663928c1febfb\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("588e5d2f04d49707fe4aab865e1deacaf7ef6787\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("master\n", 7, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
}
/* git checkout beef && git rebase --merge efad0b11c47cb2f0220cbd6f5b0f93bb99064b00 */
void test_rebase_setup__merge_branch_by_id(void)
{
git_rebase *rebase;
git_reference *branch_ref;
git_annotated_commit *branch_head, *upstream_head;
git_reference *head;
git_commit *head_commit;
git_oid head_id, upstream_id;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_oid_fromstr(&upstream_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_lookup(&upstream_head, repo, &upstream_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
git_oid_fromstr(&head_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_reference_peel((git_object **)&head_commit, head, GIT_OBJECT_COMMIT));
cl_assert_equal_oid(&head_id, git_commit_id(head_commit));
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/ORIG_HEAD");
cl_assert_equal_file("da9c51a23d02d931a486f45ad18cda05cf5d2b94\n", 41, "rebase/.git/rebase-merge/cmt.1");
cl_assert_equal_file("8d1f13f93c4995760ac07d129246ac1ff64c0be9\n", 41, "rebase/.git/rebase-merge/cmt.2");
cl_assert_equal_file("3069cc907e6294623e5917ef6de663928c1febfb\n", 41, "rebase/.git/rebase-merge/cmt.3");
cl_assert_equal_file("588e5d2f04d49707fe4aab865e1deacaf7ef6787\n", 41, "rebase/.git/rebase-merge/cmt.4");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/cmt.5");
cl_assert_equal_file("5\n", 2, "rebase/.git/rebase-merge/end");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto");
cl_assert_equal_file("efad0b11c47cb2f0220cbd6f5b0f93bb99064b00\n", 41, "rebase/.git/rebase-merge/onto_name");
cl_assert_equal_file("b146bd7608eac53d9bf9e1a6963543588b555c64\n", 41, "rebase/.git/rebase-merge/orig-head");
git_commit_free(head_commit);
git_reference_free(head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_rebase_free(rebase);
}
static int rebase_is_blocked(void)
{
git_rebase *rebase = NULL;
int error;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
error = git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_rebase_free(rebase);
return error;
}
void test_rebase_setup__blocked_for_staged_change(void)
{
cl_git_rewritefile("rebase/newfile.txt", "Stage an add");
git_index_add_bypath(_index, "newfile.txt");
cl_git_fail(rebase_is_blocked());
}
void test_rebase_setup__blocked_for_unstaged_change(void)
{
cl_git_rewritefile("rebase/asparagus.txt", "Unstaged change");
cl_git_fail(rebase_is_blocked());
}
void test_rebase_setup__not_blocked_for_untracked_add(void)
{
cl_git_rewritefile("rebase/newfile.txt", "Untracked file");
cl_git_pass(rebase_is_blocked());
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/abort.c
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
#include "merge.h"
#include "posix.h"
#include "annotated_commit.h"
#include <fcntl.h>
static git_repository *repo;
/* Fixture setup and teardown */
void test_rebase_abort__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
}
void test_rebase_abort__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void ensure_aborted(
git_annotated_commit *branch,
git_annotated_commit *onto)
{
git_reference *head_ref, *branch_ref = NULL;
git_status_list *statuslist;
git_reflog *reflog;
const git_reflog_entry *reflog_entry;
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
/* Make sure the refs are updated appropriately */
cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD"));
if (branch->ref_name == NULL)
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(head_ref));
else {
cl_assert_equal_s("refs/heads/beef", git_reference_symbolic_target(head_ref));
cl_git_pass(git_reference_lookup(&branch_ref, repo, git_reference_symbolic_target(head_ref)));
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(branch_ref));
}
git_status_list_new(&statuslist, repo, NULL);
cl_assert_equal_i(0, git_status_list_entrycount(statuslist));
git_status_list_free(statuslist);
/* Make sure the reflogs are updated appropriately */
cl_git_pass(git_reflog_read(&reflog, repo, "HEAD"));
cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0));
cl_assert_equal_oid(git_annotated_commit_id(onto), git_reflog_entry_id_old(reflog_entry));
cl_assert_equal_oid(git_annotated_commit_id(branch), git_reflog_entry_id_new(reflog_entry));
cl_assert_equal_s("rebase: aborting", git_reflog_entry_message(reflog_entry));
git_reflog_free(reflog);
git_reference_free(head_ref);
git_reference_free(branch_ref);
}
static void test_abort(
git_annotated_commit *branch, git_annotated_commit *onto)
{
git_rebase *rebase;
cl_git_pass(git_rebase_open(&rebase, repo, NULL));
cl_git_pass(git_rebase_abort(rebase));
ensure_aborted(branch, onto);
git_rebase_free(rebase);
}
void test_rebase_abort__merge(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
void test_rebase_abort__merge_immediately_after_init(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_git_pass(git_rebase_abort(rebase));
ensure_aborted(branch_head, onto_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
void test_rebase_abort__merge_by_id(void)
{
git_rebase *rebase;
git_oid branch_id, onto_id;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_rebase_free(rebase);
}
void test_rebase_abort__merge_by_revspec(void)
{
git_rebase *rebase;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_annotated_commit_from_revspec(&branch_head, repo, "b146bd7"));
cl_git_pass(git_annotated_commit_from_revspec(&onto_head, repo, "efad0b1"));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_rebase_free(rebase);
}
void test_rebase_abort__merge_by_id_immediately_after_init(void)
{
git_rebase *rebase;
git_oid branch_id, onto_id;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"));
cl_git_pass(git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"));
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
cl_git_pass(git_rebase_abort(rebase));
ensure_aborted(branch_head, onto_head);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_rebase_free(rebase);
}
void test_rebase_abort__detached_head(void)
{
git_rebase *rebase;
git_oid branch_id, onto_id;
git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64");
git_oid_fromstr(&onto_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00");
cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id));
cl_git_pass(git_annotated_commit_lookup(&onto_head, repo, &onto_id));
cl_git_pass(git_signature_new(&signature, "Rebaser", "[email protected]", 1404157834, -400));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_rebase_free(rebase);
}
void test_rebase_abort__old_style_head_file(void)
{
git_rebase *rebase;
git_reference *branch_ref, *onto_ref;
git_signature *signature;
git_annotated_commit *branch_head, *onto_head;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef"));
cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref));
cl_git_pass(git_signature_new(&signature, "Rebaser", "[email protected]", 1404157834, -400));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, NULL));
cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo));
p_rename("rebase-merge/.git/rebase-merge/orig-head",
"rebase-merge/.git/rebase-merge/head");
test_abort(branch_head, onto_head);
git_signature_free(signature);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(onto_head);
git_reference_free(branch_ref);
git_reference_free(onto_ref);
git_rebase_free(rebase);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/rebase/sign.c
|
#include "clar_libgit2.h"
#include "git2/rebase.h"
static git_repository *repo;
static git_signature *signature;
/* Fixture setup and teardown */
void test_rebase_sign__initialize(void)
{
repo = cl_git_sandbox_init("rebase");
cl_git_pass(git_signature_new(&signature, "Rebaser",
"[email protected]", 1405694510, 0));
}
void test_rebase_sign__cleanup(void)
{
git_signature_free(signature);
cl_git_sandbox_cleanup();
}
static int create_cb_passthrough(
git_oid *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
size_t parent_count,
const git_commit *parents[],
void *payload)
{
GIT_UNUSED(out);
GIT_UNUSED(author);
GIT_UNUSED(committer);
GIT_UNUSED(message_encoding);
GIT_UNUSED(message);
GIT_UNUSED(tree);
GIT_UNUSED(parent_count);
GIT_UNUSED(parents);
GIT_UNUSED(payload);
return GIT_PASSTHROUGH;
}
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__passthrough_create_cb(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
git_commit *commit;
const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n";
rebase_opts.commit_create_cb = create_cb_passthrough;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_commit_free(commit);
git_rebase_free(rebase);
}
int create_cb_signed_gpg(
git_oid *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
size_t parent_count,
const git_commit *parents[],
void *payload)
{
git_buf commit_content = GIT_BUF_INIT;
const char *gpg_signature = "-----BEGIN PGP SIGNATURE-----\n\
\n\
iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----";
git_repository *repo = (git_repository *)payload;
int error;
if ((error = git_commit_create_buffer(&commit_content,
repo, author, committer, message_encoding, message,
tree, parent_count, parents)) < 0)
goto done;
error = git_commit_create_with_signature(out, repo,
commit_content.ptr,
gpg_signature,
NULL);
done:
git_buf_dispose(&commit_content);
return error;
}
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__create_gpg_signed(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
git_commit *commit;
const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n\
gpgsig -----BEGIN PGP SIGNATURE-----\n\
\n\
iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----\n";
rebase_opts.commit_create_cb = create_cb_signed_gpg;
rebase_opts.payload = repo;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_commit_free(commit);
git_rebase_free(rebase);
}
static int create_cb_error(
git_oid *out,
const git_signature *author,
const git_signature *committer,
const char *message_encoding,
const char *message,
const git_tree *tree,
size_t parent_count,
const git_commit *parents[],
void *payload)
{
GIT_UNUSED(out);
GIT_UNUSED(author);
GIT_UNUSED(committer);
GIT_UNUSED(message_encoding);
GIT_UNUSED(message);
GIT_UNUSED(tree);
GIT_UNUSED(parent_count);
GIT_UNUSED(parents);
GIT_UNUSED(payload);
return GIT_EUSER;
}
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__create_propagates_error(void)
{
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_oid commit_id;
git_rebase_operation *rebase_operation;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
rebase_opts.commit_create_cb = create_cb_error;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_fail_with(GIT_EUSER, git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_rebase_free(rebase);
}
#ifndef GIT_DEPRECATE_HARD
static const char *expected_commit_content = "\
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n\
\n\
Modification 3 to gravy\n";
int signing_cb_passthrough(
git_buf *signature,
git_buf *signature_field,
const char *commit_content,
void *payload)
{
cl_assert_equal_b(false, git_buf_is_allocated(signature));
cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
return GIT_PASSTHROUGH;
}
#endif /* !GIT_DEPRECATE_HARD */
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__passthrough_signing_cb(void)
{
#ifndef GIT_DEPRECATE_HARD
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
git_commit *commit;
const char *expected_commit_raw_header = "tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n";
rebase_opts.signing_cb = signing_cb_passthrough;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_oid_fromstr(&expected_id, "129183968a65abd6c52da35bff43325001bfc630");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_commit_free(commit);
git_rebase_free(rebase);
#endif /* !GIT_DEPRECATE_HARD */
}
#ifndef GIT_DEPRECATE_HARD
int signing_cb_gpg(
git_buf *signature,
git_buf *signature_field,
const char *commit_content,
void *payload)
{
const char *gpg_signature = "\
-----BEGIN PGP SIGNATURE-----\n\
\n\
iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----";
cl_assert_equal_b(false, git_buf_is_allocated(signature));
cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
cl_git_pass(git_buf_set(signature, gpg_signature, strlen(gpg_signature) + 1));
return GIT_OK;
}
#endif /* !GIT_DEPRECATE_HARD */
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__gpg_with_no_field(void)
{
#ifndef GIT_DEPRECATE_HARD
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
git_commit *commit;
const char *expected_commit_raw_header = "\
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n\
gpgsig -----BEGIN PGP SIGNATURE-----\n\
\n\
iQIzBAEBCgAdFiEEgVlDEfSlmKn0fvGgK++h5T2/ctIFAlwZcrAACgkQK++h5T2/\n\
ctIPVhAA42RyZhMdKl5Bm0KtQco2scsukIg2y7tjSwhti91zDu3HQgpusjjo0fQx\n\
ZzB+OrmlvQ9CDcGpZ0THIzXD8GRJoDMPqdrvZVrBWkGcHvw7/YPA8skzsjkauJ8W\n\
7lzF5LCuHSS6OUmPT/+5hEHPin5PB3zhfszyC+Q7aujnIuPJMrKiMnUa+w1HWifM\n\
km49OOygQ9S6NQoVuEQede22+c76DlDL7yFghGoo1f0sKCE/9LW6SEnwI/bWv9eo\n\
nom5vOPrvQeJiYCQk+2DyWo8RdSxINtY+G9bPE4RXm+6ZgcXECPm9TYDIWpL36fC\n\
jvtGLs98woWFElOziBMp5Tb630GMcSI+q5ivHfJ3WS5NKLYLHBNK4iSFN0/dgAnB\n\
dj6GcKXKWnIBWn6ZM4o40pcM5KSRUUCLtA0ZmjJH4c4zx3X5fUxd+enwkf3e9VZO\n\
fNKC/+xfq6NfoPUPK9+UnchHpJaJw7RG5tZS+sWCz2xpQ1y3/o49xImNyM3wnpvB\n\
cRAZabqIHpZa9/DIUkELOtCzln6niqkjRgg3M/YCCNznwV+0RNgz87VtyTPerdef\n\
xrqn0+ROMF6ebVqIs6PPtuPkxnAJu7TMKXVB5rFnAewS24e6cIGFzeIA7810py3l\n\
cttVRsdOoego+fiy08eFE+aJIeYiINRGhqOBTsuqG4jIdpdKxPE=\n\
=KbsY\n\
-----END PGP SIGNATURE-----\n";
rebase_opts.signing_cb = signing_cb_gpg;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_oid_fromstr(&expected_id, "bf78348e45c8286f52b760f1db15cb6da030f2ef");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_commit_free(commit);
git_rebase_free(rebase);
#endif /* !GIT_DEPRECATE_HARD */
}
#ifndef GIT_DEPRECATE_HARD
int signing_cb_magic_field(
git_buf *signature,
git_buf *signature_field,
const char *commit_content,
void *payload)
{
const char *signature_content = "magic word: pretty please";
const char *signature_field_content = "magicsig";
cl_assert_equal_b(false, git_buf_is_allocated(signature));
cl_assert_equal_b(false, git_buf_is_allocated(signature_field));
cl_assert_equal_s(expected_commit_content, commit_content);
cl_assert_equal_p(NULL, payload);
cl_git_pass(git_buf_set(signature, signature_content,
strlen(signature_content) + 1));
cl_git_pass(git_buf_set(signature_field, signature_field_content,
strlen(signature_field_content) + 1));
return GIT_OK;
}
#endif /* !GIT_DEPRECATE_HARD */
/* git checkout gravy ; git rebase --merge veal */
void test_rebase_sign__custom_signature_field(void)
{
#ifndef GIT_DEPRECATE_HARD
git_rebase *rebase;
git_reference *branch_ref, *upstream_ref;
git_annotated_commit *branch_head, *upstream_head;
git_rebase_operation *rebase_operation;
git_oid commit_id, expected_id;
git_rebase_options rebase_opts = GIT_REBASE_OPTIONS_INIT;
git_commit *commit;
const char *expected_commit_raw_header = "\
tree cd99b26250099fc38d30bfaed7797a7275ed3366\n\
parent f87d14a4a236582a0278a916340a793714256864\n\
author Edward Thomson <[email protected]> 1405625055 -0400\n\
committer Rebaser <[email protected]> 1405694510 +0000\n\
magicsig magic word: pretty please\n";
rebase_opts.signing_cb = signing_cb_magic_field;
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy"));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_opts));
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL));
git_oid_fromstr(&expected_id, "f46a4a8d26ae411b02aa61b7d69576627f4a1e1c");
cl_assert_equal_oid(&expected_id, &commit_id);
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
cl_assert_equal_s(expected_commit_raw_header, git_commit_raw_header(commit));
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
git_reference_free(branch_ref);
git_reference_free(upstream_ref);
git_annotated_commit_free(branch_head);
git_annotated_commit_free(upstream_head);
git_commit_free(commit);
git_rebase_free(rebase);
#endif /* !GIT_DEPRECATE_HARD */
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/message/trailer.c
|
#include "clar_libgit2.h"
#include "message.h"
static void assert_trailers(const char *message, git_message_trailer *trailers)
{
git_message_trailer_array arr;
size_t i;
int rc = git_message_trailers(&arr, message);
cl_assert_equal_i(0, rc);
for(i=0; i<arr.count; i++) {
cl_assert_equal_s(arr.trailers[i].key, trailers[i].key);
cl_assert_equal_s(arr.trailers[i].value, trailers[i].value);
}
cl_assert_equal_i(0, rc);
git_message_trailer_array_free(&arr);
}
void test_message_trailer__simple(void)
{
git_message_trailer trailers[] = {
{"Signed-off-by", "[email protected]"},
{"Signed-off-by", "[email protected]"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Signed-off-by: [email protected]\n"
"Signed-off-by: [email protected]\n"
, trailers);
}
void test_message_trailer__no_whitespace(void)
{
git_message_trailer trailers[] = {
{"Key", "value"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key:value\n"
, trailers);
}
void test_message_trailer__extra_whitespace(void)
{
git_message_trailer trailers[] = {
{"Key", "value"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key : value\n"
, trailers);
}
void test_message_trailer__no_newline(void)
{
git_message_trailer trailers[] = {
{"Key", "value"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key: value"
, trailers);
}
void test_message_trailer__not_last_paragraph(void)
{
git_message_trailer trailers[] = {
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key: value\n"
"\n"
"More stuff\n"
, trailers);
}
void test_message_trailer__conflicts(void)
{
git_message_trailer trailers[] = {
{"Key", "value"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key: value\n"
"\n"
"Conflicts:\n"
"\tfoo.c\n"
, trailers);
}
void test_message_trailer__patch(void)
{
git_message_trailer trailers[] = {
{"Key", "value"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Key: value\n"
"\n"
"---\n"
"More: stuff\n"
, trailers);
}
void test_message_trailer__continuation(void)
{
git_message_trailer trailers[] = {
{"A", "b\n c"},
{"D", "e\n f: g h"},
{"I", "j"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"A: b\n"
" c\n"
"D: e\n"
" f: g h\n"
"I: j\n"
, trailers);
}
void test_message_trailer__invalid(void)
{
git_message_trailer trailers[] = {
{"Signed-off-by", "[email protected]"},
{"Another", "trailer"},
{NULL, NULL},
};
assert_trailers(
"Message\n"
"\n"
"Signed-off-by: [email protected]\n"
"Not a trailer\n"
"Another: trailer\n"
, trailers);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/commit/parent.c
|
#include "clar_libgit2.h"
static git_repository *_repo;
static git_commit *commit;
void test_commit_parent__initialize(void)
{
git_oid oid;
cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git")));
git_oid_fromstr(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
}
void test_commit_parent__cleanup(void)
{
git_commit_free(commit);
commit = NULL;
git_repository_free(_repo);
_repo = NULL;
}
static void assert_nth_gen_parent(unsigned int gen, const char *expected_oid)
{
git_commit *parent = NULL;
int error;
error = git_commit_nth_gen_ancestor(&parent, commit, gen);
if (expected_oid != NULL) {
cl_assert_equal_i(0, error);
cl_assert_equal_i(0, git_oid_streq(git_commit_id(parent), expected_oid));
} else
cl_assert_equal_i(GIT_ENOTFOUND, error);
git_commit_free(parent);
}
/*
* $ git show be35~0
* commit be3563ae3f795b2b4353bcce3a527ad0a4f7f644
*
* $ git show be35~1
* commit 9fd738e8f7967c078dceed8190330fc8648ee56a
*
* $ git show be35~3
* commit 5b5b025afb0b4c913b4c338a42934a3863bf3644
*
* $ git show be35~42
* fatal: ambiguous argument 'be35~42': unknown revision or path not in the working tree.
*/
void test_commit_parent__can_retrieve_nth_generation_parent(void)
{
assert_nth_gen_parent(0, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644");
assert_nth_gen_parent(1, "9fd738e8f7967c078dceed8190330fc8648ee56a");
assert_nth_gen_parent(3, "5b5b025afb0b4c913b4c338a42934a3863bf3644");
assert_nth_gen_parent(42, NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/commit/write.c
|
#include "clar_libgit2.h"
#include "git2/sys/commit.h"
static const char *committer_name = "Vicent Marti";
static const char *committer_email = "[email protected]";
static const char *commit_message = "This commit has been created in memory\n\
This is a commit created in memory and it will be written back to disk\n";
static const char *tree_id_str = "1810dff58d8a660512d4832e740f692884338ccd";
static const char *parent_id_str = "8496071c1b46c854b31185ea97743be6a8774479";
static const char *root_commit_message = "This is a root commit\n\
This is a root commit and should be the only one in this branch\n";
static const char *root_reflog_message = "commit (initial): This is a root commit \
This is a root commit and should be the only one in this branch";
static char *head_old;
static git_reference *head, *branch;
static git_commit *commit;
/* Fixture setup */
static git_repository *g_repo;
void test_commit_write__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_commit_write__cleanup(void)
{
git_reference_free(head);
head = NULL;
git_reference_free(branch);
branch = NULL;
git_commit_free(commit);
commit = NULL;
git__free(head_old);
head_old = NULL;
cl_git_sandbox_cleanup();
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 1));
}
/* write a new commit object from memory to disk */
void test_commit_write__from_memory(void)
{
git_oid tree_id, parent_id, commit_id;
git_signature *author, *committer;
const git_signature *author1, *committer1;
git_commit *parent;
git_tree *tree;
git_oid_fromstr(&tree_id, tree_id_str);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
git_oid_fromstr(&parent_id, parent_id_str);
cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id));
/* create signatures */
cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60));
cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90));
cl_git_pass(git_commit_create_v(
&commit_id, /* out id */
g_repo,
NULL, /* do not update the HEAD */
author,
committer,
NULL,
commit_message,
tree,
1, parent));
git_object_free((git_object *)parent);
git_object_free((git_object *)tree);
git_signature_free(committer);
git_signature_free(author);
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
/* Check attributes were set correctly */
author1 = git_commit_author(commit);
cl_assert(author1 != NULL);
cl_assert_equal_s(committer_name, author1->name);
cl_assert_equal_s(committer_email, author1->email);
cl_assert(author1->when.time == 987654321);
cl_assert(author1->when.offset == 90);
committer1 = git_commit_committer(commit);
cl_assert(committer1 != NULL);
cl_assert_equal_s(committer_name, committer1->name);
cl_assert_equal_s(committer_email, committer1->email);
cl_assert(committer1->when.time == 123456789);
cl_assert(committer1->when.offset == 60);
cl_assert_equal_s(commit_message, git_commit_message(commit));
}
void test_commit_write__into_buf(void)
{
git_oid tree_id;
git_signature *author, *committer;
git_tree *tree;
git_commit *parent;
git_oid parent_id;
git_buf commit = GIT_BUF_INIT;
git_oid_fromstr(&tree_id, tree_id_str);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
/* create signatures */
cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60));
cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90));
git_oid_fromstr(&parent_id, parent_id_str);
cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id));
cl_git_pass(git_commit_create_buffer(&commit, g_repo, author, committer,
NULL, root_commit_message, tree, 1, (const git_commit **) &parent));
cl_assert_equal_s(commit.ptr,
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
parent 8496071c1b46c854b31185ea97743be6a8774479\n\
author Vicent Marti <[email protected]> 987654321 +0130\n\
committer Vicent Marti <[email protected]> 123456789 +0100\n\
\n\
This is a root commit\n\
This is a root commit and should be the only one in this branch\n\
");
git_buf_dispose(&commit);
git_tree_free(tree);
git_commit_free(parent);
git_signature_free(author);
git_signature_free(committer);
}
/* create a root commit */
void test_commit_write__root(void)
{
git_oid tree_id, commit_id;
const git_oid *branch_oid;
git_signature *author, *committer;
const char *branch_name = "refs/heads/root-commit-branch";
git_tree *tree;
git_reflog *log;
const git_reflog_entry *entry;
git_oid_fromstr(&tree_id, tree_id_str);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
/* create signatures */
cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60));
cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90));
/* First we need to update HEAD so it points to our non-existant branch */
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert(git_reference_type(head) == GIT_REFERENCE_SYMBOLIC);
head_old = git__strdup(git_reference_symbolic_target(head));
cl_assert(head_old != NULL);
git_reference_free(head);
cl_git_pass(git_reference_symbolic_create(&head, g_repo, "HEAD", branch_name, 1, NULL));
cl_git_pass(git_commit_create_v(
&commit_id, /* out id */
g_repo,
"HEAD",
author,
committer,
NULL,
root_commit_message,
tree,
0));
git_object_free((git_object *)tree);
git_signature_free(author);
/*
* The fact that creating a commit works has already been
* tested. Here we just make sure it's our commit and that it was
* written as a root commit.
*/
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
cl_assert(git_commit_parentcount(commit) == 0);
cl_git_pass(git_reference_lookup(&branch, g_repo, branch_name));
branch_oid = git_reference_target(branch);
cl_assert_equal_oid(branch_oid, &commit_id);
cl_assert_equal_s(root_commit_message, git_commit_message(commit));
cl_git_pass(git_reflog_read(&log, g_repo, branch_name));
cl_assert_equal_i(1, git_reflog_entrycount(log));
entry = git_reflog_entry_byindex(log, 0);
cl_assert_equal_s(committer->email, git_reflog_entry_committer(entry)->email);
cl_assert_equal_s(committer->name, git_reflog_entry_committer(entry)->name);
cl_assert_equal_s(root_reflog_message, git_reflog_entry_message(entry));
git_signature_free(committer);
git_reflog_free(log);
}
static int create_commit_from_ids(
git_oid *result,
const git_oid *tree_id,
const git_oid *parent_id)
{
git_signature *author, *committer;
const git_oid *parent_ids[1];
int ret;
cl_git_pass(git_signature_new(
&committer, committer_name, committer_email, 123456789, 60));
cl_git_pass(git_signature_new(
&author, committer_name, committer_email, 987654321, 90));
parent_ids[0] = parent_id;
ret = git_commit_create_from_ids(
result,
g_repo,
NULL,
author,
committer,
NULL,
root_commit_message,
tree_id,
1,
parent_ids);
git_signature_free(committer);
git_signature_free(author);
return ret;
}
void test_commit_write__can_write_invalid_objects(void)
{
git_oid expected_id, tree_id, parent_id, commit_id;
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0));
/* this is a valid tree and parent */
git_oid_fromstr(&tree_id, tree_id_str);
git_oid_fromstr(&parent_id, parent_id_str);
git_oid_fromstr(&expected_id, "c8571bbec3a72c4bcad31648902e5a453f1adece");
cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
cl_assert_equal_oid(&expected_id, &commit_id);
/* this is a wholly invented tree id */
git_oid_fromstr(&tree_id, "1234567890123456789012345678901234567890");
git_oid_fromstr(&parent_id, parent_id_str);
git_oid_fromstr(&expected_id, "996008340b8e68d69bf3c28d7c57fb7ec3c8e202");
cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
cl_assert_equal_oid(&expected_id, &commit_id);
/* this is a wholly invented parent id */
git_oid_fromstr(&tree_id, tree_id_str);
git_oid_fromstr(&parent_id, "1234567890123456789012345678901234567890");
git_oid_fromstr(&expected_id, "d78f660cab89d9791ca6714b57978bf2a7e709fd");
cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
cl_assert_equal_oid(&expected_id, &commit_id);
/* these are legitimate objects, but of the wrong type */
git_oid_fromstr(&tree_id, parent_id_str);
git_oid_fromstr(&parent_id, tree_id_str);
git_oid_fromstr(&expected_id, "5d80c07414e3f18792949699dfcacadf7748f361");
cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
cl_assert_equal_oid(&expected_id, &commit_id);
}
void test_commit_write__can_validate_objects(void)
{
git_oid tree_id, parent_id, commit_id;
/* this is a valid tree and parent */
git_oid_fromstr(&tree_id, tree_id_str);
git_oid_fromstr(&parent_id, parent_id_str);
cl_git_pass(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
/* this is a wholly invented tree id */
git_oid_fromstr(&tree_id, "1234567890123456789012345678901234567890");
git_oid_fromstr(&parent_id, parent_id_str);
cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
/* this is a wholly invented parent id */
git_oid_fromstr(&tree_id, tree_id_str);
git_oid_fromstr(&parent_id, "1234567890123456789012345678901234567890");
cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
/* these are legitimate objects, but of the wrong type */
git_oid_fromstr(&tree_id, parent_id_str);
git_oid_fromstr(&parent_id, tree_id_str);
cl_git_fail(create_commit_from_ids(&commit_id, &tree_id, &parent_id));
}
void test_commit_write__attach_signature_checks_objects(void)
{
const char *sig = "magic word: pretty please";
const char *badtree = "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
\n\
a simple commit which does not work\n";
const char *badparent = "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\
parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
\n\
a simple commit which does not work\n";
git_oid id;
cl_git_fail_with(-1, git_commit_create_with_signature(&id, g_repo, badtree, sig, "magicsig"));
cl_git_fail_with(-1, git_commit_create_with_signature(&id, g_repo, badparent, sig, "magicsig"));
}
void test_commit_write__attach_singleline_signature(void)
{
const char *sig = "magic word: pretty please";
const char *data = "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\
parent 8496071c1b46c854b31185ea97743be6a8774479\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
\n\
a simple commit which works\n";
const char *complete = "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\
parent 8496071c1b46c854b31185ea97743be6a8774479\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
magicsig magic word: pretty please\n\
\n\
a simple commit which works\n";
git_oid id;
git_odb *odb;
git_odb_object *obj;
cl_git_pass(git_commit_create_with_signature(&id, g_repo, data, sig, "magicsig"));
cl_git_pass(git_repository_odb(&odb, g_repo));
cl_git_pass(git_odb_read(&obj, odb, &id));
cl_assert_equal_s(complete, git_odb_object_data(obj));
git_odb_object_free(obj);
git_odb_free(odb);
}
void test_commit_write__attach_multiline_signature(void)
{
const char *gpgsig = "-----BEGIN PGP SIGNATURE-----\n\
Version: GnuPG v1.4.12 (Darwin)\n\
\n\
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
cpxtDQQMGYFpXK/71stq\n\
=ozeK\n\
-----END PGP SIGNATURE-----";
const char *data = "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\
parent 8496071c1b46c854b31185ea97743be6a8774479\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
\n\
a simple commit which works\n";
const char *complete = "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n\
parent 8496071c1b46c854b31185ea97743be6a8774479\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
gpgsig -----BEGIN PGP SIGNATURE-----\n\
Version: GnuPG v1.4.12 (Darwin)\n\
\n\
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
cpxtDQQMGYFpXK/71stq\n\
=ozeK\n\
-----END PGP SIGNATURE-----\n\
\n\
a simple commit which works\n";
git_oid one, two;
git_odb *odb;
git_odb_object *obj;
cl_git_pass(git_commit_create_with_signature(&one, g_repo, data, gpgsig, "gpgsig"));
cl_git_pass(git_commit_create_with_signature(&two, g_repo, data, gpgsig, NULL));
cl_assert(!git_oid_cmp(&one, &two));
cl_git_pass(git_repository_odb(&odb, g_repo));
cl_git_pass(git_odb_read(&obj, odb, &one));
cl_assert_equal_s(complete, git_odb_object_data(obj));
git_odb_object_free(obj);
git_odb_free(odb);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/commit/parse.c
|
#include "clar_libgit2.h"
#include <git2/types.h>
#include "commit.h"
#include "signature.h"
/* Fixture setup */
static git_repository *g_repo;
void test_commit_parse__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_commit_parse__cleanup(void)
{
cl_git_sandbox_cleanup();
}
/* Header parsing */
typedef struct {
const char *line;
const char *header;
} parse_test_case;
static parse_test_case passing_header_cases[] = {
{ "parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
{ "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
{ "random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading " },
{ "stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading" },
{ "tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree " },
{ "tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree " },
{ "tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree " },
{ "tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree " },
{ NULL, NULL }
};
static parse_test_case failing_header_cases[] = {
{ "parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent " },
{ "05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
{ "parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent " },
{ "parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent " },
{ "tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree " },
{ "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent " },
{ "parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent " },
{ "", "tree " },
{ "", "" },
{ NULL, NULL }
};
void test_commit_parse__header(void)
{
git_oid oid;
parse_test_case *testcase;
for (testcase = passing_header_cases; testcase->line != NULL; testcase++)
{
const char *line = testcase->line;
const char *line_end = line + strlen(line);
cl_git_pass(git_oid__parse(&oid, &line, line_end, testcase->header));
cl_assert(line == line_end);
}
for (testcase = failing_header_cases; testcase->line != NULL; testcase++)
{
const char *line = testcase->line;
const char *line_end = line + strlen(line);
cl_git_fail(git_oid__parse(&oid, &line, line_end, testcase->header));
}
}
/* Signature parsing */
typedef struct {
const char *string;
const char *header;
const char *name;
const char *email;
git_time_t time;
int offset;
} passing_signature_test_case;
passing_signature_test_case passing_signature_cases[] = {
{"author Vicent Marti <[email protected]> 12345 \n", "author ", "Vicent Marti", "[email protected]", 12345, 0},
{"author Vicent Marti <> 12345 \n", "author ", "Vicent Marti", "", 12345, 0},
{"author Vicent Marti <[email protected]> 231301 +1020\n", "author ", "Vicent Marti", "[email protected]", 231301, 620},
{"author Vicent Marti with an outrageously long name which will probably overflow the buffer <[email protected]> 12345 \n", "author ", "Vicent Marti with an outrageously long name which will probably overflow the buffer", "[email protected]", 12345, 0},
{"author Vicent Marti <tanokuwithaveryveryverylongemailwhichwillprobablyvoverflowtheemailbuffer@gmail.com> 12345 \n", "author ", "Vicent Marti", "tanokuwithaveryveryverylongemailwhichwillprobablyvoverflowtheemailbuffer@gmail.com", 12345, 0},
{"committer Vicent Marti <[email protected]> 123456 +0000 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
{"committer Vicent Marti <[email protected]> 123456 +0100 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 60},
{"committer Vicent Marti <[email protected]> 123456 -0100 \n", "committer ", "Vicent Marti", "[email protected]", 123456, -60},
/* Parse a signature without an author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
/* Parse a signature without an author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
/* Parse a signature with an empty author field */
{"committer <[email protected]> 123456 -0100 \n", "committer ", "", "[email protected]", 123456, -60},
/* Parse a signature with an empty email field */
{"committer Vicent Marti <> 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
/* Parse a signature with an empty email field */
{"committer Vicent Marti < > 123456 -0100 \n", "committer ", "Vicent Marti", "", 123456, -60},
/* Parse a signature with empty name and email */
{"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
/* Parse a signature with empty name and email */
{"committer <> 123456 -0100 \n", "committer ", "", "", 123456, -60},
/* Parse a signature with empty name and email */
{"committer < > 123456 -0100 \n", "committer ", "", "", 123456, -60},
/* Parse an obviously invalid signature */
{"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
/* Parse an obviously invalid signature */
{"committer foo<@bar> 123456 -0100 \n", "committer ", "foo", "@bar", 123456, -60},
/* Parse an obviously invalid signature */
{"committer <>\n", "committer ", "", "", 0, 0},
{"committer Vicent Marti <[email protected]> 123456 -1500 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
{"committer Vicent Marti <[email protected]> 123456 +0163 \n", "committer ", "Vicent Marti", "[email protected]", 123456, 0},
{"author Vicent Marti <[email protected]>\n", "author ", "Vicent Marti", "[email protected]", 0, 0},
/* a variety of dates */
{"author Vicent Marti <[email protected]> 0 \n", "author ", "Vicent Marti", "[email protected]", 0, 0},
{"author Vicent Marti <[email protected]> 1234567890 \n", "author ", "Vicent Marti", "[email protected]", 1234567890, 0},
{"author Vicent Marti <[email protected]> 2147483647 \n", "author ", "Vicent Marti", "[email protected]", 0x7fffffff, 0},
{"author Vicent Marti <[email protected]> 4294967295 \n", "author ", "Vicent Marti", "[email protected]", 0xffffffff, 0},
{"author Vicent Marti <[email protected]> 4294967296 \n", "author ", "Vicent Marti", "[email protected]", 4294967296, 0},
{"author Vicent Marti <[email protected]> 8589934592 \n", "author ", "Vicent Marti", "[email protected]", 8589934592, 0},
{NULL,NULL,NULL,NULL,0,0}
};
typedef struct {
const char *string;
const char *header;
} failing_signature_test_case;
failing_signature_test_case failing_signature_cases[] = {
{"committer Vicent Marti [email protected]> 123456 -0100 \n", "committer "},
{"author Vicent Marti <[email protected]> 12345 \n", "author "},
{"author Vicent Marti <[email protected]> 12345 \n", "committer "},
{"author Vicent Marti 12345 \n", "author "},
{"author Vicent Marti <broken@email 12345 \n", "author "},
{"committer Vicent Marti ><\n", "committer "},
{"author ", "author "},
{NULL, NULL,}
};
void test_commit_parse__signature(void)
{
passing_signature_test_case *passcase;
failing_signature_test_case *failcase;
for (passcase = passing_signature_cases; passcase->string != NULL; passcase++)
{
const char *str = passcase->string;
size_t len = strlen(passcase->string);
struct git_signature person = {0};
cl_git_pass(git_signature__parse(&person, &str, str + len, passcase->header, '\n'));
cl_assert_equal_s(passcase->name, person.name);
cl_assert_equal_s(passcase->email, person.email);
cl_assert_equal_i((int)passcase->time, (int)person.when.time);
cl_assert_equal_i(passcase->offset, person.when.offset);
git__free(person.name); git__free(person.email);
}
for (failcase = failing_signature_cases; failcase->string != NULL; failcase++)
{
const char *str = failcase->string;
size_t len = strlen(failcase->string);
git_signature person = {0};
cl_git_fail(git_signature__parse(&person, &str, str + len, failcase->header, '\n'));
git__free(person.name); git__free(person.email);
}
}
static char *failing_commit_cases[] = {
/* empty commit */
"",
/* random garbage */
"asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n",
/* broken endlines 1 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\
author Vicent Marti <[email protected]> 1273848544 +0200\r\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\r\n\
\r\n\
a test commit with broken endlines\r\n",
/* broken endlines 2 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\
author Vicent Marti <[email protected]> 1273848544 +0200\
committer Vicent Marti <[email protected]> 1273848544 +0200\
\
another test commit with broken endlines",
/* starting endlines */
"\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a test commit with a starting endline\n",
/* corrupted commit 1 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent 05452d6349abcd67aa396df",
/* corrupted commit 2 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent ",
/* corrupted commit 3 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
parent ",
/* corrupted commit 4 */
"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\
par",
};
static char *passing_commit_cases[] = {
/* simple commit with no message */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n",
/* simple commit, no parent */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works\n",
/* simple commit, no parent, no newline in message */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works",
/* simple commit, 1 parent */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
parent e90810b8df3e80c413d903f631643c716887138d\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works\n",
/* simple commit with GPG signature */
"tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
gpgsig -----BEGIN PGP SIGNATURE-----\n\
Version: GnuPG v1.4.12 (Darwin)\n\
\n\
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
cpxtDQQMGYFpXK/71stq\n\
=ozeK\n\
-----END PGP SIGNATURE-----\n\
\n\
a simple commit which works\n",
/* some tools create two author entries */
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
author Helpful Coworker <helpful@coworker> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
a simple commit which works",
};
static int parse_commit(git_commit **out, const char *buffer)
{
git_commit *commit;
git_odb_object fake_odb_object;
int error;
commit = (git_commit*)git__malloc(sizeof(git_commit));
memset(commit, 0x0, sizeof(git_commit));
commit->object.repo = g_repo;
memset(&fake_odb_object, 0x0, sizeof(git_odb_object));
fake_odb_object.buffer = (char *)buffer;
fake_odb_object.cached.size = strlen(fake_odb_object.buffer);
error = git_commit__parse(commit, &fake_odb_object);
*out = commit;
return error;
}
void test_commit_parse__entire_commit(void)
{
const int failing_commit_count = ARRAY_SIZE(failing_commit_cases);
const int passing_commit_count = ARRAY_SIZE(passing_commit_cases);
int i;
git_commit *commit;
for (i = 0; i < failing_commit_count; ++i) {
cl_git_fail(parse_commit(&commit, failing_commit_cases[i]));
git_commit__free(commit);
}
for (i = 0; i < passing_commit_count; ++i) {
cl_git_pass(parse_commit(&commit, passing_commit_cases[i]));
if (!i)
cl_assert_equal_s("", git_commit_message(commit));
else
cl_assert(git__prefixcmp(
git_commit_message(commit), "a simple commit which works") == 0);
git_commit__free(commit);
}
}
/* query the details on a parsed commit */
void test_commit_parse__details0(void) {
static const char *commit_ids[] = {
"a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */
"9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */
"4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */
"c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */
"8496071c1b46c854b31185ea97743be6a8774479", /* 4 */
"5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */
"a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */
};
const size_t commit_count = sizeof(commit_ids) / sizeof(const char *);
unsigned int i;
for (i = 0; i < commit_count; ++i) {
git_oid id;
git_commit *commit;
const git_signature *author, *committer;
const char *message;
git_time_t commit_time;
unsigned int parents, p;
git_commit *parent = NULL, *old_parent = NULL;
git_oid_fromstr(&id, commit_ids[i]);
cl_git_pass(git_commit_lookup(&commit, g_repo, &id));
message = git_commit_message(commit);
author = git_commit_author(commit);
committer = git_commit_committer(commit);
commit_time = git_commit_time(commit);
parents = git_commit_parentcount(commit);
cl_assert_equal_s("Scott Chacon", author->name);
cl_assert_equal_s("[email protected]", author->email);
cl_assert_equal_s("Scott Chacon", committer->name);
cl_assert_equal_s("[email protected]", committer->email);
cl_assert(message != NULL);
cl_assert(commit_time > 0);
cl_assert(parents <= 2);
for (p = 0;p < parents;p++) {
if (old_parent != NULL)
git_commit_free(old_parent);
old_parent = parent;
cl_git_pass(git_commit_parent(&parent, commit, p));
cl_assert(parent != NULL);
cl_assert(git_commit_author(parent) != NULL); /* is it really a commit? */
}
git_commit_free(old_parent);
git_commit_free(parent);
cl_git_fail(git_commit_parent(&parent, commit, parents));
git_commit_free(commit);
}
}
void test_commit_parse__leading_lf(void)
{
git_commit *commit;
const char *buffer =
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
parent e90810b8df3e80c413d903f631643c716887138d\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
\n\
\n\
This commit has a few LF at the start of the commit message";
const char *message =
"This commit has a few LF at the start of the commit message";
const char *raw_message =
"\n\
\n\
This commit has a few LF at the start of the commit message";
cl_git_pass(parse_commit(&commit, buffer));
cl_assert_equal_s(message, git_commit_message(commit));
cl_assert_equal_s(raw_message, git_commit_message_raw(commit));
git_commit__free(commit);
}
void test_commit_parse__only_lf(void)
{
git_commit *commit;
const char *buffer =
"tree 1810dff58d8a660512d4832e740f692884338ccd\n\
parent e90810b8df3e80c413d903f631643c716887138d\n\
author Vicent Marti <[email protected]> 1273848544 +0200\n\
committer Vicent Marti <[email protected]> 1273848544 +0200\n\
\n\
\n\
\n";
const char *message = "";
const char *raw_message = "\n\n";
cl_git_pass(parse_commit(&commit, buffer));
cl_assert_equal_s(message, git_commit_message(commit));
cl_assert_equal_s(raw_message, git_commit_message_raw(commit));
git_commit__free(commit);
}
void test_commit_parse__arbitrary_field(void)
{
git_commit *commit;
git_buf buf = GIT_BUF_INIT;
const char *gpgsig = "-----BEGIN PGP SIGNATURE-----\n\
Version: GnuPG v1.4.12 (Darwin)\n\
\n\
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
cpxtDQQMGYFpXK/71stq\n\
=ozeK\n\
-----END PGP SIGNATURE-----";
cl_git_pass(parse_commit(&commit, passing_commit_cases[4]));
cl_git_pass(git_commit_header_field(&buf, commit, "tree"));
cl_assert_equal_s("6b79e22d69bf46e289df0345a14ca059dfc9bdf6", buf.ptr);
git_buf_clear(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "parent"));
cl_assert_equal_s("34734e478d6cf50c27c9d69026d93974d052c454", buf.ptr);
git_buf_clear(&buf);
cl_git_pass(git_commit_header_field(&buf, commit, "gpgsig"));
cl_assert_equal_s(gpgsig, buf.ptr);
git_buf_clear(&buf);
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "awesomeness"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_header_field(&buf, commit, "par"));
git_commit__free(commit);
cl_git_pass(parse_commit(&commit, passing_commit_cases[0]));
cl_git_pass(git_commit_header_field(&buf, commit, "committer"));
cl_assert_equal_s("Vicent Marti <[email protected]> 1273848544 +0200", buf.ptr);
git_buf_dispose(&buf);
git_commit__free(commit);
}
void test_commit_parse__extract_signature(void)
{
git_odb *odb;
git_oid commit_id;
git_buf signature = GIT_BUF_INIT, signed_data = GIT_BUF_INIT;
const char *gpgsig = "-----BEGIN PGP SIGNATURE-----\n\
Version: GnuPG v1.4.12 (Darwin)\n\
\n\
iQIcBAABAgAGBQJQ+FMIAAoJEH+LfPdZDSs1e3EQAJMjhqjWF+WkGLHju7pTw2al\n\
o6IoMAhv0Z/LHlWhzBd9e7JeCnanRt12bAU7yvYp9+Z+z+dbwqLwDoFp8LVuigl8\n\
JGLcnwiUW3rSvhjdCp9irdb4+bhKUnKUzSdsR2CK4/hC0N2i/HOvMYX+BRsvqweq\n\
AsAkA6dAWh+gAfedrBUkCTGhlNYoetjdakWqlGL1TiKAefEZrtA1TpPkGn92vbLq\n\
SphFRUY9hVn1ZBWrT3hEpvAIcZag3rTOiRVT1X1flj8B2vGCEr3RrcwOIZikpdaW\n\
who/X3xh/DGbI2RbuxmmJpxxP/8dsVchRJJzBwG+yhwU/iN3MlV2c5D69tls/Dok\n\
6VbyU4lm/ae0y3yR83D9dUlkycOnmmlBAHKIZ9qUts9X7mWJf0+yy2QxJVpjaTGG\n\
cmnQKKPeNIhGJk2ENnnnzjEve7L7YJQF6itbx5VCOcsGh3Ocb3YR7DMdWjt7f8pu\n\
c6j+q1rP7EpE2afUN/geSlp5i3x8aXZPDj67jImbVCE/Q1X9voCtyzGJH7MXR0N9\n\
ZpRF8yzveRfMH8bwAJjSOGAFF5XkcR/RNY95o+J+QcgBLdX48h+ZdNmUf6jqlu3J\n\
7KmTXXQcOVpN6dD3CmRFsbjq+x6RHwa8u1iGn+oIkX908r97ckfB/kHKH7ZdXIJc\n\
cpxtDQQMGYFpXK/71stq\n\
=ozeK\n\
-----END PGP SIGNATURE-----";
const char *data = "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n\
parent 34734e478d6cf50c27c9d69026d93974d052c454\n\
author Ben Burkert <[email protected]> 1358451456 -0800\n\
committer Ben Burkert <[email protected]> 1358451456 -0800\n\
\n\
a simple commit which works\n";
const char *oneline_signature = "tree 51832e6397b30309c8bcad9c55fa6ae67778f378\n\
parent a1b6decaaac768b5e01e1b5dbf5b2cc081bed1eb\n\
author Some User <[email protected]> 1454537944 -0700\n\
committer Some User <[email protected]> 1454537944 -0700\n\
gpgsig bad\n\
\n\
corrupt signature\n";
const char *oneline_data = "tree 51832e6397b30309c8bcad9c55fa6ae67778f378\n\
parent a1b6decaaac768b5e01e1b5dbf5b2cc081bed1eb\n\
author Some User <[email protected]> 1454537944 -0700\n\
committer Some User <[email protected]> 1454537944 -0700\n\
\n\
corrupt signature\n";
cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
cl_git_pass(git_odb_write(&commit_id, odb, passing_commit_cases[4], strlen(passing_commit_cases[4]), GIT_OBJECT_COMMIT));
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
git_buf_clear(&signature);
git_buf_clear(&signed_data);
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, "gpgsig"));
cl_assert_equal_s(gpgsig, signature.ptr);
cl_assert_equal_s(data, signed_data.ptr);
/* Try to parse a tree */
cl_git_pass(git_oid_fromstr(&commit_id, "45dd856fdd4d89b884c340ba0e047752d9b085d6"));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_i(GIT_ERROR_INVALID, git_error_last()->klass);
/* Try to parse an unsigned commit */
cl_git_pass(git_odb_write(&commit_id, odb, passing_commit_cases[1], strlen(passing_commit_cases[1]), GIT_OBJECT_COMMIT));
cl_git_fail_with(GIT_ENOTFOUND, git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_i(GIT_ERROR_OBJECT, git_error_last()->klass);
/* Parse the commit with a single-line signature */
git_buf_clear(&signature);
git_buf_clear(&signed_data);
cl_git_pass(git_odb_write(&commit_id, odb, oneline_signature, strlen(oneline_signature), GIT_OBJECT_COMMIT));
cl_git_pass(git_commit_extract_signature(&signature, &signed_data, g_repo, &commit_id, NULL));
cl_assert_equal_s("bad", signature.ptr);
cl_assert_equal_s(oneline_data, signed_data.ptr);
git_buf_dispose(&signature);
git_buf_dispose(&signed_data);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/commit/commit.c
|
#include "clar_libgit2.h"
#include "commit.h"
#include "git2/commit.h"
static git_repository *_repo;
void test_commit_commit__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
}
void test_commit_commit__cleanup(void)
{
git_repository_free(_repo);
_repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
void test_commit_commit__create_unexisting_update_ref(void)
{
git_oid oid;
git_tree *tree;
git_commit *commit;
git_signature *s;
git_reference *ref;
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
cl_git_pass(git_signature_now(&s, "alice", "[email protected]"));
cl_git_fail(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
cl_git_pass(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
NULL, "some msg", tree, 1, (const git_commit **) &commit));
/* fail because the parent isn't the tip of the branch anymore */
cl_git_fail(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
NULL, "some msg", tree, 1, (const git_commit **) &commit));
cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
cl_assert_equal_oid(&oid, git_reference_target(ref));
git_tree_free(tree);
git_commit_free(commit);
git_signature_free(s);
git_reference_free(ref);
}
void test_commit_commit__create_initial_commit(void)
{
git_oid oid;
git_tree *tree;
git_commit *commit;
git_signature *s;
git_reference *ref;
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
cl_git_pass(git_signature_now(&s, "alice", "[email protected]"));
cl_git_fail(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
cl_git_pass(git_commit_create(&oid, _repo, "refs/heads/foo/bar", s, s,
NULL, "initial commit", tree, 0, NULL));
cl_git_pass(git_reference_lookup(&ref, _repo, "refs/heads/foo/bar"));
cl_assert_equal_oid(&oid, git_reference_target(ref));
git_tree_free(tree);
git_commit_free(commit);
git_signature_free(s);
git_reference_free(ref);
}
void test_commit_commit__create_initial_commit_parent_not_current(void)
{
git_oid oid;
git_oid original_oid;
git_tree *tree;
git_commit *commit;
git_signature *s;
git_oid_fromstr(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_git_pass(git_commit_lookup(&commit, _repo, &oid));
git_oid_fromstr(&oid, "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
cl_git_pass(git_tree_lookup(&tree, _repo, &oid));
cl_git_pass(git_signature_now(&s, "alice", "[email protected]"));
cl_git_pass(git_reference_name_to_id(&original_oid, _repo, "HEAD"));
cl_git_fail(git_commit_create(&oid, _repo, "HEAD", s, s,
NULL, "initial commit", tree, 0, NULL));
cl_git_pass(git_reference_name_to_id(&oid, _repo, "HEAD"));
cl_assert_equal_oid(&oid, &original_oid);
git_tree_free(tree);
git_commit_free(commit);
git_signature_free(s);
}
void assert_commit_summary(const char *expected, const char *given)
{
git_commit *dummy;
cl_assert(dummy = git__calloc(1, sizeof(struct git_commit)));
dummy->raw_message = git__strdup(given);
cl_assert_equal_s(expected, git_commit_summary(dummy));
git_commit__free(dummy);
}
void assert_commit_body(const char *expected, const char *given)
{
git_commit *dummy;
cl_assert(dummy = git__calloc(1, sizeof(struct git_commit)));
dummy->raw_message = git__strdup(given);
cl_assert_equal_s(expected, git_commit_body(dummy));
git_commit__free(dummy);
}
void test_commit_commit__summary(void)
{
assert_commit_summary("One-liner with no trailing newline", "One-liner with no trailing newline");
assert_commit_summary("One-liner with trailing newline", "One-liner with trailing newline\n");
assert_commit_summary("Trimmed leading&trailing newlines", "\n\nTrimmed leading&trailing newlines\n\n");
assert_commit_summary("First paragraph only", "\nFirst paragraph only\n\n(There are more!)");
assert_commit_summary("First paragraph with unwrapped trailing\tlines", "\nFirst paragraph\nwith unwrapped\ntrailing\tlines\n\n(Yes, unwrapped!)");
assert_commit_summary("\tLeading tabs", "\tLeading\n\ttabs\n\nare preserved"); /* tabs around newlines are collapsed down to a single space */
assert_commit_summary(" Leading Spaces", " Leading\n Spaces\n\nare preserved"); /* spaces around newlines are collapsed down to a single space */
assert_commit_summary("Trailing tabs\tare removed", "Trailing tabs\tare removed\t\t");
assert_commit_summary("Trailing spaces are removed", "Trailing spaces are removed ");
assert_commit_summary("Trailing tabs", "Trailing tabs\t\n\nare removed");
assert_commit_summary("Trailing spaces", "Trailing spaces \n\nare removed");
assert_commit_summary("Newlines are replaced by spaces", "Newlines\nare\nreplaced by spaces\n");
assert_commit_summary(" Spaces after newlines are collapsed", "\n Spaces after newlines\n are\n collapsed\n "); /* newlines at the very beginning are ignored and not collapsed */
assert_commit_summary(" Spaces before newlines are collapsed", " \nSpaces before newlines \nare \ncollapsed \n");
assert_commit_summary(" Spaces around newlines are collapsed", " \n Spaces around newlines \n are \n collapsed \n ");
assert_commit_summary(" Trailing newlines are" , " \n Trailing newlines \n are \n\n collapsed \n ");
assert_commit_summary(" Trailing spaces are stripped", " \n Trailing spaces \n are stripped \n\n \n \t ");
assert_commit_summary("", "");
assert_commit_summary("", " ");
assert_commit_summary("", "\n");
assert_commit_summary("", "\n \n");
}
void test_commit_commit__body(void)
{
assert_commit_body(NULL, "One-liner with no trailing newline");
assert_commit_body(NULL, "One-liner with trailing newline\n");
assert_commit_body(NULL, "\n\nTrimmed leading&trailing newlines\n\n");
assert_commit_body("(There are more!)", "\nFirst paragraph only\n\n(There are more!)");
assert_commit_body("(Yes, unwrapped!)", "\nFirst paragraph\nwith unwrapped\ntrailing\tlines\n\n(Yes, unwrapped!)");
assert_commit_body("are preserved", "\tLeading\n\ttabs\n\nare preserved"); /* tabs around newlines are collapsed down to a single space */
assert_commit_body("are preserved", " Leading\n Spaces\n\nare preserved"); /* spaces around newlines are collapsed down to a single space */
assert_commit_body(NULL, "Trailing tabs\tare removed\t\t");
assert_commit_body(NULL, "Trailing spaces are removed ");
assert_commit_body("are removed", "Trailing tabs\t\n\nare removed");
assert_commit_body("are removed", "Trailing spaces \n\nare removed");
assert_commit_body(NULL,"Newlines\nare\nreplaced by spaces\n");
assert_commit_body(NULL , "\n Spaces after newlines\n are\n collapsed\n "); /* newlines at the very beginning are ignored and not collapsed */
assert_commit_body(NULL , " \nSpaces before newlines \nare \ncollapsed \n");
assert_commit_body(NULL , " \n Spaces around newlines \n are \n collapsed \n ");
assert_commit_body("collapsed" , " \n Trailing newlines \n are \n\n collapsed \n ");
assert_commit_body(NULL, " \n Trailing spaces \n are stripped \n\n \n \t ");
assert_commit_body(NULL , "");
assert_commit_body(NULL , " ");
assert_commit_body(NULL , "\n");
assert_commit_body(NULL , "\n \n");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/commit/signature.c
|
#include "clar_libgit2.h"
#include "signature.h"
static int try_build_signature(const char *name, const char *email, git_time_t time, int offset)
{
git_signature *sign;
int error = 0;
if ((error = git_signature_new(&sign, name, email, time, offset)) < 0)
return error;
git_signature_free((git_signature *)sign);
return error;
}
static void assert_name_and_email(
const char *expected_name,
const char *expected_email,
const char *name,
const char *email)
{
git_signature *sign;
cl_git_pass(git_signature_new(&sign, name, email, 1234567890, 60));
cl_assert_equal_s(expected_name, sign->name);
cl_assert_equal_s(expected_email, sign->email);
git_signature_free(sign);
}
void test_commit_signature__leading_and_trailing_spaces_are_trimmed(void)
{
assert_name_and_email("nulltoken", "[email protected]", " nulltoken ", " [email protected] ");
assert_name_and_email("nulltoken", "[email protected]", " nulltoken ", " [email protected] \n");
assert_name_and_email("nulltoken", "[email protected]", " \t nulltoken \n", " \n [email protected] \n");
}
void test_commit_signature__leading_and_trailing_crud_is_trimmed(void)
{
assert_name_and_email("nulltoken", "[email protected]", "\"nulltoken\"", "\"[email protected]\"");
assert_name_and_email("nulltoken w", "[email protected]", "nulltoken w.", "[email protected]");
assert_name_and_email("nulltoken \xe2\x98\xba", "[email protected]", "nulltoken \xe2\x98\xba", "[email protected]");
}
void test_commit_signature__timezone_does_not_read_oob(void)
{
const char *header = "A <[email protected]> 1461698487 +1234", *header_end;
git_signature *sig;
/* Let the buffer end midway between the timezone offeset's "+12" and "34" */
header_end = header + strlen(header) - 2;
sig = git__calloc(1, sizeof(git_signature));
cl_assert(sig);
cl_git_pass(git_signature__parse(sig, &header, header_end, NULL, '\0'));
cl_assert_equal_s(sig->name, "A");
cl_assert_equal_s(sig->email, "[email protected]");
cl_assert_equal_i(sig->when.time, 1461698487);
cl_assert_equal_i(sig->when.offset, 12);
git_signature_free(sig);
}
void test_commit_signature__angle_brackets_in_names_are_not_supported(void)
{
cl_git_fail(try_build_signature("<Phil Haack", "phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil>Haack", "phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("<Phil Haack>", "phil@haack", 1234567890, 60));
}
void test_commit_signature__angle_brackets_in_email_are_not_supported(void)
{
cl_git_fail(try_build_signature("Phil Haack", ">phil@haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil Haack", "phil@>haack", 1234567890, 60));
cl_git_fail(try_build_signature("Phil Haack", "<phil@haack>", 1234567890, 60));
}
void test_commit_signature__create_empties(void)
{
/* can not create a signature with empty name or email */
cl_git_pass(try_build_signature("nulltoken", "[email protected]", 1234567890, 60));
cl_git_fail(try_build_signature("", "[email protected]", 1234567890, 60));
cl_git_fail(try_build_signature(" ", "[email protected]", 1234567890, 60));
cl_git_fail(try_build_signature("nulltoken", "", 1234567890, 60));
cl_git_fail(try_build_signature("nulltoken", " ", 1234567890, 60));
}
void test_commit_signature__create_one_char(void)
{
/* creating a one character signature */
assert_name_and_email("x", "[email protected]", "x", "[email protected]");
}
void test_commit_signature__create_two_char(void)
{
/* creating a two character signature */
assert_name_and_email("xx", "[email protected]", "xx", "[email protected]");
}
void test_commit_signature__create_zero_char(void)
{
/* creating a zero character signature */
git_signature *sign;
cl_git_fail(git_signature_new(&sign, "", "[email protected]", 1234567890, 60));
cl_assert(sign == NULL);
}
void test_commit_signature__from_buf(void)
{
git_signature *sign;
cl_git_pass(git_signature_from_buffer(&sign, "Test User <[email protected]> 1461698487 +0200"));
cl_assert_equal_s("Test User", sign->name);
cl_assert_equal_s("[email protected]", sign->email);
cl_assert_equal_i(1461698487, sign->when.time);
cl_assert_equal_i(120, sign->when.offset);
git_signature_free(sign);
}
void test_commit_signature__from_buf_with_neg_zero_offset(void)
{
git_signature *sign;
cl_git_pass(git_signature_from_buffer(&sign, "Test User <[email protected]> 1461698487 -0000"));
cl_assert_equal_s("Test User", sign->name);
cl_assert_equal_s("[email protected]", sign->email);
cl_assert_equal_i(1461698487, sign->when.time);
cl_assert_equal_i(0, sign->when.offset);
cl_assert_equal_i('-', sign->when.sign);
git_signature_free(sign);
}
void test_commit_signature__pos_and_neg_zero_offsets_dont_match(void)
{
git_signature *with_neg_zero;
git_signature *with_pos_zero;
cl_git_pass(git_signature_from_buffer(&with_neg_zero, "Test User <[email protected]> 1461698487 -0000"));
cl_git_pass(git_signature_from_buffer(&with_pos_zero, "Test User <[email protected]> 1461698487 +0000"));
cl_assert(!git_signature__equal(with_neg_zero, with_pos_zero));
git_signature_free((git_signature *)with_neg_zero);
git_signature_free((git_signature *)with_pos_zero);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/remote/create.c
|
#include "clar_libgit2.h"
#include "config/config_helpers.h"
static git_repository *_repo;
static git_config *_config;
#define TEST_URL "http://github.com/libgit2/libgit2.git"
void test_remote_create__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&_repo, "testrepo.git"));
cl_git_pass(git_repository_config(&_config, _repo));
}
void test_remote_create__cleanup(void)
{
git_config_free(_config);
git_repository_free(_repo);
cl_fixture_cleanup("testrepo.git");
}
void test_remote_create__manual(void)
{
git_remote *remote;
cl_git_pass(git_config_set_string(_config, "remote.origin.fetch", "+refs/heads/*:refs/remotes/origin/*"));
cl_git_pass(git_config_set_string(_config, "remote.origin.url", TEST_URL));
cl_git_pass(git_remote_lookup(&remote, _repo, "origin"));
cl_assert_equal_s(git_remote_name(remote), "origin");
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
git_remote_free(remote);
}
void test_remote_create__named(void)
{
git_remote *remote;
git_config *cfg;
const char *cfg_val;
size_t section_count = count_config_entries_match(_repo, "remote\\.");
cl_git_pass(git_remote_create(&remote, _repo, "valid-name", TEST_URL));
cl_assert_equal_s(git_remote_name(remote), "valid-name");
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_repository_config_snapshot(&cfg, _repo));
cl_git_pass(git_config_get_string(&cfg_val, cfg, "remote.valid-name.fetch"));
cl_assert_equal_s(cfg_val, "+refs/heads/*:refs/remotes/valid-name/*");
cl_git_pass(git_config_get_string(&cfg_val, cfg, "remote.valid-name.url"));
cl_assert_equal_s(cfg_val, TEST_URL);
cl_assert_equal_i(section_count + 2, count_config_entries_match(_repo, "remote\\."));
git_config_free(cfg);
git_remote_free(remote);
}
void test_remote_create__named_fail_on_invalid_name(void)
{
const char *names[] = {
NULL,
"Inv@{id",
"",
"/",
"//",
".lock",
"a.lock",
};
size_t i;
for (i = 0; i < ARRAY_SIZE(names); i++) {
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_create(&remote, _repo, names[i], TEST_URL));
cl_assert_equal_p(remote, NULL);
}
}
void test_remote_create__named_fail_on_invalid_url(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_ERROR, git_remote_create(&remote, _repo, "bad-url", ""));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__named_fail_on_conflicting_name(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EEXISTS, git_remote_create(&remote, _repo, "test", TEST_URL));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__with_fetchspec(void)
{
git_remote *remote;
git_strarray array;
size_t section_count = count_config_entries_match(_repo, "remote\\.");
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", "+refs/*:refs/*"));
cl_assert_equal_s(git_remote_name(remote), "test-new");
cl_assert_equal_s(git_remote_url(remote), "git://github.com/libgit2/libgit2");
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
cl_assert_equal_i(1, array.count);
cl_assert_equal_i(section_count + 2, count_config_entries_match(_repo, "remote\\."));
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_empty_fetchspec(void)
{
git_remote *remote;
git_strarray array;
size_t section_count = count_config_entries_match(_repo, "remote\\.");
cl_git_pass(git_remote_create_with_fetchspec(&remote, _repo, "test-new", "git://github.com/libgit2/libgit2", NULL));
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
cl_assert_equal_i(section_count + 1, count_config_entries_match(_repo, "remote\\."));
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_fetchspec_invalid_name(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_create_with_fetchspec(&remote, _repo, NULL, TEST_URL, NULL));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__with_fetchspec_invalid_url(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_create_with_fetchspec(&remote, _repo, NULL, "", NULL));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__anonymous(void)
{
git_remote *remote;
git_strarray array;
size_t section_count = count_config_entries_match(_repo, "remote\\.");
cl_git_pass(git_remote_create_anonymous(&remote, _repo, TEST_URL));
cl_assert_equal_s(git_remote_name(remote), NULL);
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
cl_assert_equal_i(section_count, count_config_entries_match(_repo, "remote\\."));
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__anonymous_invalid_url(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_create_anonymous(&remote, _repo, ""));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__detached(void)
{
git_remote *remote;
git_strarray array;
size_t section_count = count_config_entries_match(_repo, "remote\\.");
cl_git_pass(git_remote_create_detached(&remote, TEST_URL));
cl_assert_equal_s(git_remote_name(remote), NULL);
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), NULL);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
cl_assert_equal_i(section_count, count_config_entries_match(_repo, "remote\\."));
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__detached_invalid_url(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, git_remote_create_detached(&remote, ""));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__with_opts_named(void)
{
git_remote *remote;
git_strarray array;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.name = "test-new";
opts.repository = _repo;
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts));
cl_assert_equal_s(git_remote_name(remote), "test-new");
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(1, array.count);
cl_assert_equal_s("+refs/heads/*:refs/remotes/test-new/*", array.strings[0]);
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_opts_named_and_fetchspec(void)
{
git_remote *remote;
git_strarray array;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.name = "test-new";
opts.repository = _repo;
opts.fetchspec = "+refs/*:refs/*";
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts));
cl_assert_equal_s(git_remote_name(remote), "test-new");
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(1, array.count);
cl_assert_equal_s("+refs/*:refs/*", array.strings[0]);
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_opts_named_no_fetchspec(void)
{
git_remote *remote;
git_strarray array;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.name = "test-new";
opts.repository = _repo;
opts.flags = GIT_REMOTE_CREATE_SKIP_DEFAULT_FETCHSPEC;
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts));
cl_assert_equal_s(git_remote_name(remote), "test-new");
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_opts_anonymous(void)
{
git_remote *remote;
git_strarray array;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.repository = _repo;
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts));
cl_assert_equal_s(git_remote_name(remote), NULL);
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), _repo);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_opts_detached(void)
{
git_remote *remote;
git_strarray array;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, &opts));
cl_assert_equal_s(git_remote_name(remote), NULL);
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), NULL);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
git_strarray_dispose(&array);
git_remote_free(remote);
cl_git_pass(git_remote_create_with_opts(&remote, TEST_URL, NULL));
cl_assert_equal_s(git_remote_name(remote), NULL);
cl_assert_equal_s(git_remote_url(remote), TEST_URL);
cl_assert_equal_p(git_remote_owner(remote), NULL);
cl_git_pass(git_remote_get_fetch_refspecs(&array, remote));
cl_assert_equal_i(0, array.count);
git_strarray_dispose(&array);
git_remote_free(remote);
}
void test_remote_create__with_opts_insteadof_disabled(void)
{
git_remote *remote;
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.repository = _repo;
opts.flags = GIT_REMOTE_CREATE_SKIP_INSTEADOF;
cl_git_pass(git_remote_create_with_opts(&remote, "http://example.com/libgit2/libgit2", &opts));
cl_assert_equal_s(git_remote_url(remote), "http://example.com/libgit2/libgit2");
cl_assert_equal_p(git_remote_pushurl(remote), NULL);
git_remote_free(remote);
}
static int create_with_name(git_remote **remote, git_repository *repo, const char *name, const char *url)
{
git_remote_create_options opts = GIT_REMOTE_CREATE_OPTIONS_INIT;
opts.repository = repo;
opts.name = name;
return git_remote_create_with_opts(remote, url, &opts);
}
void test_remote_create__with_opts_invalid_name(void)
{
const char *names[] = {
"Inv@{id",
"",
"/",
"//",
".lock",
"a.lock",
};
size_t i;
for (i = 0; i < ARRAY_SIZE(names); i++) {
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, create_with_name(&remote, _repo, names[i], TEST_URL));
cl_assert_equal_p(remote, NULL);
}
}
void test_remote_create__with_opts_conflicting_name(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EEXISTS, create_with_name(&remote, _repo, "test", TEST_URL));
cl_assert_equal_p(remote, NULL);
}
void test_remote_create__with_opts_invalid_url(void)
{
git_remote *remote = NULL;
cl_git_fail_with(GIT_EINVALIDSPEC, create_with_name(&remote, _repo, "test-new", ""));
cl_assert_equal_p(remote, NULL);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/remote/insteadof.c
|
#include "clar_libgit2.h"
#include "remote.h"
#include "repository.h"
#define REPO_PATH "testrepo2/.gitted"
#define REMOTE_ORIGIN "origin"
#define REMOTE_INSTEADOF "insteadof-test"
static git_repository *g_repo;
static git_remote *g_remote;
void test_remote_insteadof__initialize(void)
{
g_repo = NULL;
g_remote = NULL;
}
void test_remote_insteadof__cleanup(void)
{
git_repository_free(g_repo);
git_remote_free(g_remote);
}
void test_remote_insteadof__url_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_s(
git_remote_url(g_remote),
"https://github.com/libgit2/false.git");
}
void test_remote_insteadof__url_insteadof_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_INSTEADOF));
cl_assert_equal_s(
git_remote_url(g_remote),
"http://github.com/libgit2/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);
}
void test_remote_insteadof__pushurl_insteadof_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_INSTEADOF));
cl_assert_equal_s(
git_remote_pushurl(g_remote),
"[email protected]:libgit2/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);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/remote/httpproxy.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "net.h"
#include "remote.h"
static git_repository *repo;
static git_net_url url = GIT_NET_URL_INIT;
static int orig_proxies_need_reset = 0;
static char *orig_http_proxy = NULL;
static char *orig_https_proxy = NULL;
static char *orig_no_proxy = NULL;
void test_remote_httpproxy__initialize(void)
{
git_remote *remote;
repo = cl_git_sandbox_init("testrepo");
cl_git_pass(git_remote_create(&remote, repo, "lg2", "https://github.com/libgit2/libgit2"));
cl_git_pass(git_net_url_parse(&url, "https://github.com/libgit2/libgit2"));
git_remote_free(remote);
orig_proxies_need_reset = 0;
}
void test_remote_httpproxy__cleanup(void)
{
if (orig_proxies_need_reset) {
cl_setenv("HTTP_PROXY", orig_http_proxy);
cl_setenv("HTTPS_PROXY", orig_https_proxy);
cl_setenv("NO_PROXY", orig_no_proxy);
git__free(orig_http_proxy);
git__free(orig_https_proxy);
git__free(orig_no_proxy);
}
git_net_url_dispose(&url);
cl_git_sandbox_cleanup();
}
void assert_proxy_is(const char *expected)
{
git_remote *remote;
char *proxy;
cl_git_pass(git_remote_lookup(&remote, repo, "lg2"));
cl_git_pass(git_remote__http_proxy(&proxy, remote, &url));
if (expected)
cl_assert_equal_s(proxy, expected);
else
cl_assert_equal_p(proxy, expected);
git_remote_free(remote);
git__free(proxy);
}
void assert_config_match(const char *config, const char *expected)
{
git_remote *remote;
char *proxy;
if (config)
cl_repo_set_string(repo, config, expected);
cl_git_pass(git_remote_lookup(&remote, repo, "lg2"));
cl_git_pass(git_remote__http_proxy(&proxy, remote, &url));
if (expected)
cl_assert_equal_s(proxy, expected);
else
cl_assert_equal_p(proxy, expected);
git_remote_free(remote);
git__free(proxy);
}
void test_remote_httpproxy__config_overrides(void)
{
/*
* http.proxy should be honored, then http.<url>.proxy should
* be honored in increasing specificity of the url. finally,
* remote.<name>.proxy is the most specific.
*/
assert_config_match(NULL, NULL);
assert_config_match("http.proxy", "http://localhost:1/");
assert_config_match("http.https://github.com.proxy", "http://localhost:2/");
assert_config_match("http.https://github.com/.proxy", "http://localhost:3/");
assert_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/");
assert_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/");
assert_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/");
assert_config_match("remote.lg2.proxy", "http://localhost:7/");
}
void test_remote_httpproxy__config_empty_overrides(void)
{
/*
* with greater specificity, an empty config entry overrides
* a set one
*/
assert_config_match("http.proxy", "http://localhost:1/");
assert_config_match("http.https://github.com.proxy", "");
assert_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:2/");
assert_config_match("remote.lg2.proxy", "");
}
void assert_global_config_match(const char *config, const char *expected)
{
git_remote *remote;
char *proxy;
git_config* cfg;
if (config) {
cl_git_pass(git_config_open_default(&cfg));
git_config_set_string(cfg, config, expected);
git_config_free(cfg);
}
cl_git_pass(git_remote_create_detached(&remote, "https://github.com/libgit2/libgit2"));
cl_git_pass(git_remote__http_proxy(&proxy, remote, &url));
if (expected)
cl_assert_equal_s(proxy, expected);
else
cl_assert_equal_p(proxy, expected);
git_remote_free(remote);
git__free(proxy);
}
void test_remote_httpproxy__config_overrides_detached_remote(void)
{
cl_fake_home();
assert_global_config_match(NULL, NULL);
assert_global_config_match("http.proxy", "http://localhost:1/");
assert_global_config_match("http.https://github.com.proxy", "http://localhost:2/");
assert_global_config_match("http.https://github.com/.proxy", "http://localhost:3/");
assert_global_config_match("http.https://github.com/libgit2.proxy", "http://localhost:4/");
assert_global_config_match("http.https://github.com/libgit2/.proxy", "http://localhost:5/");
assert_global_config_match("http.https://github.com/libgit2/libgit2.proxy", "http://localhost:6/");
cl_git_pass(git_futils_rmdir_r("home", NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_remote_httpproxy__env(void)
{
orig_http_proxy = cl_getenv("HTTP_PROXY");
orig_https_proxy = cl_getenv("HTTPS_PROXY");
orig_no_proxy = cl_getenv("NO_PROXY");
orig_proxies_need_reset = 1;
/* Clear everything for a fresh start */
cl_setenv("HTTP_PROXY", NULL);
cl_setenv("HTTPS_PROXY", NULL);
cl_setenv("NO_PROXY", NULL);
/* HTTP proxy is ignored for HTTPS */
cl_setenv("HTTP_PROXY", "http://localhost:9/");
assert_proxy_is(NULL);
/* HTTPS proxy is honored for HTTPS */
cl_setenv("HTTPS_PROXY", "http://localhost:10/");
assert_proxy_is("http://localhost:10/");
/* NO_PROXY is honored */
cl_setenv("NO_PROXY", "github.com:443");
assert_proxy_is(NULL);
cl_setenv("NO_PROXY", "github.com:80");
assert_proxy_is("http://localhost:10/");
cl_setenv("NO_PROXY", "github.com");
assert_proxy_is(NULL);
cl_setenv("NO_PROXY", "github.dev,github.com,github.foo");
assert_proxy_is(NULL);
cl_setenv("HTTPS_PROXY", "");
assert_proxy_is(NULL);
/* configuration overrides environment variables */
cl_setenv("HTTPS_PROXY", "http://localhost:10/");
cl_setenv("NO_PROXY", "github.none");
assert_config_match("http.https://github.com.proxy", "http://localhost:11/");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/remote/fetch.c
|
#include "../clar_libgit2.h"
#include "remote.h"
#include "repository.h"
static git_repository *repo1;
static git_repository *repo2;
static char* repo1_path;
static char* repo2_path;
static const char *REPO1_REFNAME = "refs/heads/main";
static const char *REPO2_REFNAME = "refs/remotes/repo1/main";
static char *FORCE_FETCHSPEC = "+refs/heads/main:refs/remotes/repo1/main";
static char *NON_FORCE_FETCHSPEC = "refs/heads/main:refs/remotes/repo1/main";
void test_remote_fetch__initialize(void) {
git_config *c;
git_buf repo1_path_buf = GIT_BUF_INIT;
git_buf repo2_path_buf = GIT_BUF_INIT;
const char *sandbox = clar_sandbox_path();
cl_git_pass(git_buf_joinpath(&repo1_path_buf, sandbox, "fetchtest_repo1"));
repo1_path = git_buf_detach(&repo1_path_buf);
cl_git_pass(git_repository_init(&repo1, repo1_path, true));
cl_git_pass(git_buf_joinpath(&repo2_path_buf, sandbox, "fetchtest_repo2"));
repo2_path = git_buf_detach(&repo2_path_buf);
cl_git_pass(git_repository_init(&repo2, repo2_path, true));
cl_git_pass(git_repository_config(&c, repo1));
cl_git_pass(git_config_set_string(c, "user.email", "some@email"));
cl_git_pass(git_config_set_string(c, "user.name", "some@name"));
git_config_free(c);
git_buf_dispose(&repo1_path_buf);
git_buf_dispose(&repo2_path_buf);
}
void test_remote_fetch__cleanup(void) {
git_repository_free(repo1);
git_repository_free(repo2);
cl_git_pass(git_futils_rmdir_r(repo1_path, NULL, GIT_RMDIR_REMOVE_FILES));
free(repo1_path);
cl_git_pass(git_futils_rmdir_r(repo2_path, NULL, GIT_RMDIR_REMOVE_FILES));
free(repo2_path);
}
/**
* This checks that the '+' flag on fetchspecs is respected. We create a
* repository that has a reference to two commits, one a child of the other.
* We fetch this repository into a second repository. Then we reset the
* reference in the first repository and run the fetch again. If the '+' flag
* is used then the reference in the second repository will change, but if it
* is not then it should stay the same.
*
* @param commit1id A pointer to an OID which will be populated with the first
* commit.
* @param commit2id A pointer to an OID which will be populated with the second
* commit, which is a descendant of the first.
* @param force Whether to use a spec with '+' prefixed to force the refs
* to update
*/
void do_time_travelling_fetch(git_oid *commit1id, git_oid *commit2id,
bool force) {
char *refspec_strs = {
force ? FORCE_FETCHSPEC : NON_FORCE_FETCHSPEC,
};
git_strarray refspecs = {
.count = 1,
.strings = &refspec_strs,
};
/* create two commits in repo 1 and a reference to them */
{
git_oid empty_tree_id;
git_tree *empty_tree;
git_signature *sig;
git_treebuilder *tb;
cl_git_pass(git_treebuilder_new(&tb, repo1, NULL));
cl_git_pass(git_treebuilder_write(&empty_tree_id, tb));
cl_git_pass(git_tree_lookup(&empty_tree, repo1, &empty_tree_id));
cl_git_pass(git_signature_default(&sig, repo1));
cl_git_pass(git_commit_create(commit1id, repo1, REPO1_REFNAME, sig,
sig, NULL, "one", empty_tree, 0, NULL));
cl_git_pass(git_commit_create_v(commit2id, repo1, REPO1_REFNAME, sig,
sig, NULL, "two", empty_tree, 1, commit1id));
git_tree_free(empty_tree);
git_signature_free(sig);
git_treebuilder_free(tb);
}
/* fetch the reference via the remote */
{
git_remote *remote;
cl_git_pass(git_remote_create_anonymous(&remote, repo2,
git_repository_path(repo1)));
cl_git_pass(git_remote_fetch(remote, &refspecs, NULL, "some message"));
git_remote_free(remote);
}
/* assert that repo2 references the second commit */
{
const git_oid *target;
git_reference *ref;
cl_git_pass(git_reference_lookup(&ref, repo2, REPO2_REFNAME));
target = git_reference_target(ref);
cl_assert_equal_b(git_oid_cmp(target, commit2id), 0);
git_reference_free(ref);
}
/* set the reference in repo1 to point to the older commit */
{
git_reference *ref;
git_reference *ref2;
cl_git_pass(git_reference_lookup(&ref, repo1, REPO1_REFNAME));
cl_git_pass(git_reference_set_target(&ref2, ref, commit1id,
"rollback"));
git_reference_free(ref);
git_reference_free(ref2);
}
/* fetch the reference again */
{
git_remote *remote;
cl_git_pass(git_remote_create_anonymous(&remote, repo2,
git_repository_path(repo1)));
cl_git_pass(git_remote_fetch(remote, &refspecs, NULL, "some message"));
git_remote_free(remote);
}
}
void test_remote_fetch__dont_update_refs_if_not_descendant_and_not_force(void) {
const git_oid *target;
git_oid commit1id;
git_oid commit2id;
git_reference *ref;
do_time_travelling_fetch(&commit1id, &commit2id, false);
/* assert that the reference in repo2 has not changed */
cl_git_pass(git_reference_lookup(&ref, repo2, REPO2_REFNAME));
target = git_reference_target(ref);
cl_assert_equal_b(git_oid_cmp(target, &commit2id), 0);
git_reference_free(ref);
}
void test_remote_fetch__do_update_refs_if_not_descendant_and_force(void) {
const git_oid *target;
git_oid commit1id;
git_oid commit2id;
git_reference *ref;
do_time_travelling_fetch(&commit1id, &commit2id, true);
/* assert that the reference in repo2 has changed */
cl_git_pass(git_reference_lookup(&ref, repo2, REPO2_REFNAME));
target = git_reference_target(ref);
cl_assert_equal_b(git_oid_cmp(target, &commit1id), 0);
git_reference_free(ref);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/remote/list.c
|
#include "clar_libgit2.h"
#include "config/config_helpers.h"
static git_repository *_repo;
#define TEST_URL "http://github.com/libgit2/libgit2.git"
void test_remote_list__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo");
}
void test_remote_list__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_remote_list__always_checks_disk_config(void)
{
git_repository *repo;
git_strarray remotes;
git_remote *remote;
cl_git_pass(git_repository_open(&repo, git_repository_path(_repo)));
cl_git_pass(git_remote_list(&remotes, _repo));
cl_assert_equal_sz(remotes.count, 1);
git_strarray_dispose(&remotes);
cl_git_pass(git_remote_create(&remote, _repo, "valid-name", TEST_URL));
cl_git_pass(git_remote_list(&remotes, _repo));
cl_assert_equal_sz(remotes.count, 2);
git_strarray_dispose(&remotes);
cl_git_pass(git_remote_list(&remotes, repo));
cl_assert_equal_sz(remotes.count, 2);
git_strarray_dispose(&remotes);
git_repository_free(repo);
git_remote_free(remote);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/date/rfc2822.c
|
#include "clar_libgit2.h"
#include "util.h"
void test_date_rfc2822__format_rfc2822_no_offset(void)
{
git_time t = {1397031663, 0};
char buf[GIT_DATE_RFC2822_SZ];
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 08:21:03 +0000") == 0);
}
void test_date_rfc2822__format_rfc2822_positive_offset(void)
{
git_time t = {1397031663, 120};
char buf[GIT_DATE_RFC2822_SZ];
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 10:21:03 +0200") == 0);
}
void test_date_rfc2822__format_rfc2822_negative_offset(void)
{
git_time t = {1397031663, -120};
char buf[GIT_DATE_RFC2822_SZ];
cl_git_pass(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
cl_assert(strcmp(buf, "Wed, 9 Apr 2014 06:21:03 -0200") == 0);
}
void test_date_rfc2822__format_rfc2822_buffer_too_small(void)
{
/* "Wed, 10 Apr 2014 08:21:03 +0000" */
git_time t = {1397031663 + 86400, 0};
char buf[GIT_DATE_RFC2822_SZ-1];
cl_git_fail(git__date_rfc2822_fmt(buf, sizeof(buf), &t));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/date/date.c
|
#include "clar_libgit2.h"
#include "util.h"
void test_date_date__overflow(void)
{
#ifdef __LP64__
git_time_t d2038, d2039;
/* This is expected to fail on a 32-bit machine. */
cl_git_pass(git__date_parse(&d2038, "2038-1-1"));
cl_git_pass(git__date_parse(&d2039, "2039-1-1"));
cl_assert(d2038 < d2039);
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/bare.c
|
#include "clar_libgit2.h"
#include "crlf.h"
static git_repository *g_repo = NULL;
static git_blob_filter_options filter_opts = GIT_BLOB_FILTER_OPTIONS_INIT;
void test_filter_bare__initialize(void)
{
cl_fixture_sandbox("crlf.git");
cl_git_pass(git_repository_open(&g_repo, "crlf.git"));
filter_opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
filter_opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_HEAD;
}
void test_filter_bare__cleanup(void)
{
git_repository_free(g_repo);
cl_fixture_cleanup("crlf.git");
}
void test_filter_bare__all_crlf(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "a9a2e89")); /* all-crlf */
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
/* in this case, raw content has crlf in it already */
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
/* we never convert CRLF -> LF on platforms that have LF */
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.txt", &filter_opts));
/* in this case, raw content has crlf in it already */
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_bare__from_lf(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
/* in this case, raw content has crlf in it already */
cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
/* we never convert CRLF -> LF on platforms that have LF */
cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_bare__nested_attributes(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "raw/file.bin", &filter_opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "raw/file.crlf", &filter_opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "raw/file.lf", &filter_opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_bare__sanitizes(void)
{
git_blob *blob;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "e69de29")); /* zero-byte */
cl_assert_equal_i(0, git_blob_rawsize(blob));
cl_assert_equal_s("", git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &filter_opts));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &filter_opts));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &filter_opts));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_bare__from_specific_commit_one(void)
{
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_blob *blob;
git_buf buf = { 0 };
opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "b8986fec0f7bde90f78ac72706e782d82f24f2f0"));
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "055c872")); /* ident */
cl_assert_equal_s("$Id$\n", git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "ident.bin", &opts));
cl_assert_equal_s("$Id$\n", buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "ident.identlf", &opts));
cl_assert_equal_s("$Id: 055c8729cdcc372500a08db659c045e16c4409fb $\n", buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_bare__from_specific_commit_with_no_attributes_file(void)
{
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
git_blob *blob;
git_buf buf = { 0 };
opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
opts.flags |= GIT_BLOB_FILTER_ATTRIBUTES_FROM_COMMIT;
cl_git_pass(git_oid_fromstr(&opts.attr_commit_id, "5afb6a14a864e30787857dd92af837e8cdd2cb1b"));
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
/* we never convert CRLF -> LF on platforms that have LF */
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
/* we never convert CRLF -> LF on platforms that have LF */
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/wildcard.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "blob.h"
#include "filter.h"
#include "git2/sys/filter.h"
#include "git2/sys/repository.h"
#include "custom_helpers.h"
static git_repository *g_repo = NULL;
static git_filter *create_wildcard_filter(void);
#define DATA_LEN 32
static unsigned char input[] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
};
static unsigned char reversed[] = {
0x1f, 0x1e, 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18,
0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10,
0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00,
};
static unsigned char flipped[] = {
0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
0xef, 0xee, 0xed, 0xec, 0xeb, 0xea, 0xe9, 0xe8,
0xe7, 0xe6, 0xe5, 0xe4, 0xe3, 0xe2, 0xe1, 0xe0,
};
void test_filter_wildcard__initialize(void)
{
cl_git_pass(git_filter_register(
"wildcard", create_wildcard_filter(), GIT_FILTER_DRIVER_PRIORITY));
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_rewritefile(
"empty_standard_repo/.gitattributes",
"* binary\n"
"hero-flip-* filter=wcflip\n"
"hero-reverse-* filter=wcreverse\n"
"none-* filter=unregistered\n");
}
void test_filter_wildcard__cleanup(void)
{
cl_git_pass(git_filter_unregister("wildcard"));
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static int wildcard_filter_check(
git_filter *self,
void **payload,
const git_filter_source *src,
const char **attr_values)
{
GIT_UNUSED(self);
GIT_UNUSED(src);
if (strcmp(attr_values[0], "wcflip") == 0 ||
strcmp(attr_values[0], "wcreverse") == 0) {
*payload = git__strdup(attr_values[0]);
GIT_ERROR_CHECK_ALLOC(*payload);
return 0;
}
return GIT_PASSTHROUGH;
}
static int wildcard_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
const git_buf *from,
const git_filter_source *source)
{
const char *filtername = *payload;
if (filtername && strcmp(filtername, "wcflip") == 0)
return bitflip_filter_apply(self, payload, to, from, source);
else if (filtername && strcmp(filtername, "wcreverse") == 0)
return reverse_filter_apply(self, payload, to, from, source);
cl_fail("Unexpected attribute");
return GIT_PASSTHROUGH;
}
static int wildcard_filter_stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
return git_filter_buffered_stream_new(out,
self, wildcard_filter_apply, NULL, payload, src, next);
}
static void wildcard_filter_cleanup(git_filter *self, void *payload)
{
GIT_UNUSED(self);
git__free(payload);
}
static void wildcard_filter_free(git_filter *f)
{
git__free(f);
}
static git_filter *create_wildcard_filter(void)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
cl_assert(filter);
filter->version = GIT_FILTER_VERSION;
filter->attributes = "filter=*";
filter->check = wildcard_filter_check;
filter->stream = wildcard_filter_stream;
filter->cleanup = wildcard_filter_cleanup;
filter->shutdown = wildcard_filter_free;
return filter;
}
void test_filter_wildcard__reverse(void)
{
git_filter_list *fl;
git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "hero-reverse-foo", GIT_FILTER_TO_ODB, 0));
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
cl_assert_equal_i(
0, memcmp(reversed, out.ptr, out.size));
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_wildcard__flip(void)
{
git_filter_list *fl;
git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "hero-flip-foo", GIT_FILTER_TO_ODB, 0));
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
cl_assert_equal_i(
0, memcmp(flipped, out.ptr, out.size));
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_wildcard__none(void)
{
git_filter_list *fl;
git_buf out = GIT_BUF_INIT;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "none-foo", GIT_FILTER_TO_ODB, 0));
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, (char *)input, DATA_LEN));
cl_assert_equal_i(DATA_LEN, out.size);
cl_assert_equal_i(
0, memcmp(input, out.ptr, out.size));
git_filter_list_free(fl);
git_buf_dispose(&out);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/crlf.c
|
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "buffer.h"
static git_repository *g_repo = NULL;
void test_filter_crlf__initialize(void)
{
g_repo = cl_git_sandbox_init("crlf");
cl_git_mkfile("crlf/.gitattributes",
"*.txt text\n*.bin binary\n*.crlf text eol=crlf\n*.lf text eol=lf\n");
cl_repo_set_bool(g_repo, "core.autocrlf", true);
}
void test_filter_crlf__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_filter_crlf__to_worktree(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_WORKTREE, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
in = "Some text\nRight here\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Some text\r\nRight here\r\n", out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_crlf__to_odb(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
in = "Some text\r\nRight here\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Some text\nRight here\n", out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_crlf__with_safecrlf(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_repo_set_bool(g_repo, "core.safecrlf", true);
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
in = "Normal\r\nCRLF\r\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf */
in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
in_len = strlen(in);
cl_git_fail(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(git_error_last()->klass, GIT_ERROR_FILTER);
/* Normalized \n fails for autocrlf=true when safecrlf=true */
in = "Normal\nLF\nonly\nline-endings.\n";
in_len = strlen(in);
cl_git_fail(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(git_error_last()->klass, GIT_ERROR_FILTER);
/* String with \r but without \r\n does not fail with safecrlf */
in = "Normal\nCR only\rand some more\nline-endings.\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCR only\rand some more\nline-endings.\n", out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_crlf__with_safecrlf_and_unsafe_allowed(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_repo_set_bool(g_repo, "core.safecrlf", true);
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, GIT_FILTER_ALLOW_UNSAFE));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
in = "Normal\r\nCRLF\r\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf, but allowed to pass */
in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n fails with safecrlf, but allowed to pass */
in = "Normal\nLF\nonly\nline-endings.\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Normal\nLF\nonly\nline-endings.\n", out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_crlf__no_safecrlf(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf */
in = "Normal\r\nCRLF\r\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings fails with safecrlf */
in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n fails with safecrlf */
in = "Normal\nLF\nonly\nline-endings.\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nLF\nonly\nline-endings.\n", out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_crlf__safecrlf_warn(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_repo_set_string(g_repo, "core.safecrlf", "warn");
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
/* Normalized \r\n succeeds with safecrlf=warn */
in = "Normal\r\nCRLF\r\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s("Normal\nCRLF\nline-endings.\n", out.ptr);
/* Mix of line endings succeeds with safecrlf=warn */
in = "Mixed\nup\r\nLF\nand\r\nCRLF\nline-endings.\r\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
/* TODO: check for warning */
cl_assert_equal_s("Mixed\nup\nLF\nand\nCRLF\nline-endings.\n", out.ptr);
/* Normalized \n is reversible, so does not fail with safecrlf=warn */
in = "Normal\nLF\nonly\nline-endings.\n";
in_len = strlen(in);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_s(in, out.ptr);
git_filter_list_free(fl);
git_buf_dispose(&out);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/custom_helpers.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "filter.h"
#include "git2/sys/filter.h"
#define VERY_SECURE_ENCRYPTION(b) ((b) ^ 0xff)
int bitflip_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
const git_buf *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
unsigned char *dst;
size_t i;
GIT_UNUSED(self); GIT_UNUSED(payload);
/* verify that attribute path match worked as expected */
cl_assert_equal_i(
0, git__strncmp("hero", git_filter_source_path(source), 4));
if (!from->size)
return 0;
cl_git_pass(git_buf_grow(to, from->size));
dst = (unsigned char *)to->ptr;
for (i = 0; i < from->size; i++)
dst[i] = VERY_SECURE_ENCRYPTION(src[i]);
to->size = from->size;
return 0;
}
static int bitflip_filter_stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
return git_filter_buffered_stream_new(out,
self, bitflip_filter_apply, NULL, payload, src, next);
}
static void bitflip_filter_free(git_filter *f)
{
git__free(f);
}
git_filter *create_bitflip_filter(void)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
cl_assert(filter);
filter->version = GIT_FILTER_VERSION;
filter->attributes = "+bitflip";
filter->shutdown = bitflip_filter_free;
filter->stream = bitflip_filter_stream;
return filter;
}
int reverse_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
const git_buf *from,
const git_filter_source *source)
{
const unsigned char *src = (const unsigned char *)from->ptr;
const unsigned char *end = src + from->size;
unsigned char *dst;
GIT_UNUSED(self); GIT_UNUSED(payload); GIT_UNUSED(source);
/* verify that attribute path match worked as expected */
cl_assert_equal_i(
0, git__strncmp("hero", git_filter_source_path(source), 4));
if (!from->size)
return 0;
cl_git_pass(git_buf_grow(to, from->size));
dst = (unsigned char *)to->ptr + from->size - 1;
while (src < end)
*dst-- = *src++;
to->size = from->size;
return 0;
}
static int reverse_filter_stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
return git_filter_buffered_stream_new(out,
self, reverse_filter_apply, NULL, payload, src, next);
}
static void reverse_filter_free(git_filter *f)
{
git__free(f);
}
git_filter *create_reverse_filter(const char *attrs)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
cl_assert(filter);
filter->version = GIT_FILTER_VERSION;
filter->attributes = attrs;
filter->shutdown = reverse_filter_free;
filter->stream = reverse_filter_stream;
return filter;
}
int erroneous_filter_stream(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
GIT_UNUSED(out);
GIT_UNUSED(self);
GIT_UNUSED(payload);
GIT_UNUSED(src);
GIT_UNUSED(next);
return -1;
}
static void erroneous_filter_free(git_filter *f)
{
git__free(f);
}
git_filter *create_erroneous_filter(const char *attrs)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
cl_assert(filter);
filter->version = GIT_FILTER_VERSION;
filter->attributes = attrs;
filter->stream = erroneous_filter_stream;
filter->shutdown = erroneous_filter_free;
return filter;
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/systemattrs.c
|
#include "clar_libgit2.h"
#include "crlf.h"
#include "path.h"
static git_repository *g_repo = NULL;
static git_buf system_attr_path = GIT_BUF_INIT;
void test_filter_systemattrs__initialize(void)
{
g_repo = cl_git_sandbox_init("crlf");
cl_must_pass(p_unlink("crlf/.gitattributes"));
cl_git_pass(git_libgit2_opts(
GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, &system_attr_path));
cl_git_pass(git_buf_joinpath(&system_attr_path,
system_attr_path.ptr, "gitattributes"));
cl_git_mkfile(system_attr_path.ptr,
"*.txt text\n"
"*.bin binary\n"
"*.crlf text eol=crlf\n"
"*.lf text eol=lf\n");
}
void test_filter_systemattrs__cleanup(void)
{
cl_must_pass(p_unlink(system_attr_path.ptr));
git_buf_dispose(&system_attr_path);
cl_git_sandbox_cleanup();
}
void test_filter_systemattrs__reads_system_attributes(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_systemattrs__disables_system_attributes(void)
{
git_blob *blob;
git_buf buf = { 0 };
git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT;
opts.flags |= GIT_BLOB_FILTER_NO_SYSTEM_ATTRIBUTES;
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
/* No attributes mean these are all treated literally */
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", &opts));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/file.c
|
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
#include "buffer.h"
static git_repository *g_repo = NULL;
void test_filter_file__initialize(void)
{
git_reference *head_ref;
git_commit *head;
g_repo = cl_git_sandbox_init("crlf");
cl_git_mkfile("crlf/.gitattributes",
"*.txt text\n*.bin binary\n*.crlf text eol=crlf\n*.lf text eol=lf\n");
cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_git_pass(git_repository_head(&head_ref, g_repo));
cl_git_pass(git_reference_peel((git_object **)&head, head_ref, GIT_OBJECT_COMMIT));
cl_git_pass(git_reset(g_repo, (git_object *)head, GIT_RESET_HARD, NULL));
git_commit_free(head);
git_reference_free(head_ref);
}
void test_filter_file__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_filter_file__apply(void)
{
git_filter_list *fl;
git_filter *crlf;
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
cl_git_pass(git_filter_list_apply_to_file(&buf, fl, g_repo, "all-crlf"));
cl_assert_equal_s("crlf\ncrlf\ncrlf\ncrlf\n", buf.ptr);
git_buf_dispose(&buf);
git_filter_list_free(fl);
}
struct buf_writestream {
git_writestream base;
git_buf buf;
};
int buf_writestream_write(git_writestream *s, const char *buf, size_t len)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
return git_buf_put(&stream->buf, buf, len);
}
int buf_writestream_close(git_writestream *s)
{
GIT_UNUSED(s);
return 0;
}
void buf_writestream_free(git_writestream *s)
{
struct buf_writestream *stream = (struct buf_writestream *)s;
git_buf_dispose(&stream->buf);
}
void test_filter_file__apply_stream(void)
{
git_filter_list *fl;
git_filter *crlf;
struct buf_writestream write_target = { {
buf_writestream_write,
buf_writestream_close,
buf_writestream_free } };
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
crlf = git_filter_lookup(GIT_FILTER_CRLF);
cl_assert(crlf != NULL);
cl_git_pass(git_filter_list_push(fl, crlf, NULL));
cl_git_pass(git_filter_list_stream_file(fl, g_repo, "all-crlf", &write_target.base));
cl_assert_equal_s("crlf\ncrlf\ncrlf\ncrlf\n", write_target.buf.ptr);
git_filter_list_free(fl);
write_target.base.free(&write_target.base);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/custom_helpers.h
|
#include "git2/sys/filter.h"
extern git_filter *create_bitflip_filter(void);
extern git_filter *create_reverse_filter(const char *attr);
extern git_filter *create_erroneous_filter(const char *attr);
extern int bitflip_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
const git_buf *from,
const git_filter_source *source);
extern int reverse_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
const git_buf *from,
const git_filter_source *source);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/stream.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "blob.h"
#include "filter.h"
#include "git2/sys/filter.h"
#include "git2/sys/repository.h"
static git_repository *g_repo = NULL;
static git_filter *create_compress_filter(void);
static git_filter *compress_filter;
void test_filter_stream__initialize(void)
{
compress_filter = create_compress_filter();
cl_git_pass(git_filter_register("compress", compress_filter, 50));
g_repo = cl_git_sandbox_init("empty_standard_repo");
}
void test_filter_stream__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
git_filter_unregister("compress");
git__free(compress_filter);
}
#define CHUNKSIZE 10240
struct compress_stream {
git_writestream parent;
git_writestream *next;
git_filter_mode_t mode;
char current;
size_t current_chunk;
};
static int compress_stream_write__deflated(struct compress_stream *stream, const char *buffer, size_t len)
{
size_t idx = 0;
while (len > 0) {
size_t chunkremain, chunksize;
if (stream->current_chunk == 0)
stream->current = buffer[idx];
chunkremain = CHUNKSIZE - stream->current_chunk;
chunksize = min(chunkremain, len);
stream->current_chunk += chunksize;
len -= chunksize;
idx += chunksize;
if (stream->current_chunk == CHUNKSIZE) {
cl_git_pass(stream->next->write(stream->next, &stream->current, 1));
stream->current_chunk = 0;
}
}
return 0;
}
static int compress_stream_write__inflated(struct compress_stream *stream, const char *buffer, size_t len)
{
char inflated[CHUNKSIZE];
size_t i, j;
for (i = 0; i < len; i++) {
for (j = 0; j < CHUNKSIZE; j++)
inflated[j] = buffer[i];
cl_git_pass(stream->next->write(stream->next, inflated, CHUNKSIZE));
}
return 0;
}
static int compress_stream_write(git_writestream *s, const char *buffer, size_t len)
{
struct compress_stream *stream = (struct compress_stream *)s;
return (stream->mode == GIT_FILTER_TO_ODB) ?
compress_stream_write__deflated(stream, buffer, len) :
compress_stream_write__inflated(stream, buffer, len);
}
static int compress_stream_close(git_writestream *s)
{
struct compress_stream *stream = (struct compress_stream *)s;
cl_assert_equal_i(0, stream->current_chunk);
stream->next->close(stream->next);
return 0;
}
static void compress_stream_free(git_writestream *stream)
{
git__free(stream);
}
static int compress_filter_stream_init(
git_writestream **out,
git_filter *self,
void **payload,
const git_filter_source *src,
git_writestream *next)
{
struct compress_stream *stream = git__calloc(1, sizeof(struct compress_stream));
cl_assert(stream);
GIT_UNUSED(self);
GIT_UNUSED(payload);
stream->parent.write = compress_stream_write;
stream->parent.close = compress_stream_close;
stream->parent.free = compress_stream_free;
stream->next = next;
stream->mode = git_filter_source_mode(src);
*out = (git_writestream *)stream;
return 0;
}
git_filter *create_compress_filter(void)
{
git_filter *filter = git__calloc(1, sizeof(git_filter));
cl_assert(filter);
filter->version = GIT_FILTER_VERSION;
filter->attributes = "+compress";
filter->stream = compress_filter_stream_init;
return filter;
}
static void writefile(const char *filename, size_t numchunks)
{
git_buf path = GIT_BUF_INIT;
char buf[CHUNKSIZE];
size_t i = 0, j = 0;
int fd;
cl_git_pass(git_buf_joinpath(&path, "empty_standard_repo", filename));
fd = p_open(path.ptr, O_RDWR|O_CREAT, 0666);
cl_assert(fd >= 0);
for (i = 0; i < numchunks; i++) {
for (j = 0; j < CHUNKSIZE; j++) {
buf[j] = i % 256;
}
cl_git_pass(p_write(fd, buf, CHUNKSIZE));
}
p_close(fd);
git_buf_dispose(&path);
}
static void test_stream(size_t numchunks)
{
git_index *index;
const git_index_entry *entry;
git_blob *blob;
struct stat st;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
cl_git_mkfile(
"empty_standard_repo/.gitattributes",
"* compress\n");
/* write a file to disk */
writefile("streamed_file", numchunks);
/* place it in the index */
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_add_bypath(index, "streamed_file"));
cl_git_pass(git_index_write(index));
/* ensure it was appropriately compressed */
cl_assert(entry = git_index_get_bypath(index, "streamed_file", 0));
cl_git_pass(git_blob_lookup(&blob, g_repo, &entry->id));
cl_assert_equal_i(numchunks, git_blob_rawsize(blob));
/* check the file back out */
cl_must_pass(p_unlink("empty_standard_repo/streamed_file"));
cl_git_pass(git_checkout_index(g_repo, index, &checkout_opts));
/* ensure it was decompressed */
cl_must_pass(p_stat("empty_standard_repo/streamed_file", &st));
cl_assert_equal_sz((numchunks * CHUNKSIZE), st.st_size);
git_index_free(index);
git_blob_free(blob);
}
/* write a 50KB file through the "compression" stream */
void test_filter_stream__smallfile(void)
{
test_stream(5);
}
/* optionally write a 500 MB file through the compression stream */
void test_filter_stream__bigfile(void)
{
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
cl_skip();
test_stream(51200);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/custom.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "blob.h"
#include "filter.h"
#include "git2/sys/filter.h"
#include "git2/sys/repository.h"
#include "custom_helpers.h"
/* going TO_WORKDIR, filters are executed low to high
* going TO_ODB, filters are executed high to low
*/
#define BITFLIP_FILTER_PRIORITY -1
#define REVERSE_FILTER_PRIORITY -2
#ifdef GIT_WIN32
# define NEWLINE "\r\n"
#else
# define NEWLINE "\n"
#endif
static char workdir_data[] =
"some simple" NEWLINE
"data" NEWLINE
"that will be" NEWLINE
"trivially" NEWLINE
"scrambled." NEWLINE;
#define REVERSED_DATA_LEN 51
/* Represents the data above scrambled (bits flipped) after \r\n -> \n
* conversion, then bytewise reversed
*/
static unsigned char bitflipped_and_reversed_data[] =
{ 0xf5, 0xd1, 0x9b, 0x9a, 0x93, 0x9d, 0x92, 0x9e, 0x8d, 0x9c, 0x8c,
0xf5, 0x86, 0x93, 0x93, 0x9e, 0x96, 0x89, 0x96, 0x8d, 0x8b, 0xf5,
0x9a, 0x9d, 0xdf, 0x93, 0x93, 0x96, 0x88, 0xdf, 0x8b, 0x9e, 0x97,
0x8b, 0xf5, 0x9e, 0x8b, 0x9e, 0x9b, 0xf5, 0x9a, 0x93, 0x8f, 0x92,
0x96, 0x8c, 0xdf, 0x9a, 0x92, 0x90, 0x8c };
#define BITFLIPPED_AND_REVERSED_DATA_LEN 51
static git_repository *g_repo = NULL;
static void register_custom_filters(void);
void test_filter_custom__initialize(void)
{
register_custom_filters();
g_repo = cl_git_sandbox_init("empty_standard_repo");
cl_git_mkfile(
"empty_standard_repo/.gitattributes",
"hero* bitflip reverse\n"
"herofile text\n"
"heroflip -reverse binary\n"
"villain erroneous\n"
"*.bin binary\n");
}
void test_filter_custom__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static void register_custom_filters(void)
{
static int filters_registered = 0;
if (!filters_registered) {
cl_git_pass(git_filter_register(
"bitflip", create_bitflip_filter(), BITFLIP_FILTER_PRIORITY));
cl_git_pass(git_filter_register(
"reverse", create_reverse_filter("+reverse"),
REVERSE_FILTER_PRIORITY));
/* re-register reverse filter with standard filter=xyz priority */
cl_git_pass(git_filter_register(
"pre-reverse",
create_reverse_filter("+prereverse"),
GIT_FILTER_DRIVER_PRIORITY));
cl_git_pass(git_filter_register(
"erroneous",
create_erroneous_filter("+erroneous"),
GIT_FILTER_DRIVER_PRIORITY));
filters_registered = 1;
}
}
void test_filter_custom__to_odb(void)
{
git_filter_list *fl;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herofile", GIT_FILTER_TO_ODB, 0));
in = workdir_data;
in_len = strlen(workdir_data);
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(BITFLIPPED_AND_REVERSED_DATA_LEN, out.size);
cl_assert_equal_i(
0, memcmp(bitflipped_and_reversed_data, out.ptr, out.size));
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_custom__to_workdir(void)
{
git_filter_list *fl;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE, 0));
in = (char *)bitflipped_and_reversed_data;
in_len = BITFLIPPED_AND_REVERSED_DATA_LEN;
cl_git_pass(git_filter_list_apply_to_buffer(&out, fl, in, in_len));
cl_assert_equal_i(strlen(workdir_data), out.size);
cl_assert_equal_i(
0, memcmp(workdir_data, out.ptr, out.size));
git_filter_list_free(fl);
git_buf_dispose(&out);
}
void test_filter_custom__can_register_a_custom_filter_in_the_repository(void)
{
git_filter_list *fl;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herofile", GIT_FILTER_TO_WORKTREE, 0));
/* expect: bitflip, reverse, crlf */
cl_assert_equal_sz(3, git_filter_list_length(fl));
git_filter_list_free(fl);
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "herocorp", GIT_FILTER_TO_WORKTREE, 0));
/* expect: bitflip, reverse - possibly crlf depending on global config */
{
size_t flen = git_filter_list_length(fl);
cl_assert(flen == 2 || flen == 3);
}
git_filter_list_free(fl);
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "hero.bin", GIT_FILTER_TO_WORKTREE, 0));
/* expect: bitflip, reverse */
cl_assert_equal_sz(2, git_filter_list_length(fl));
git_filter_list_free(fl);
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "heroflip", GIT_FILTER_TO_WORKTREE, 0));
/* expect: bitflip (because of -reverse) */
cl_assert_equal_sz(1, git_filter_list_length(fl));
git_filter_list_free(fl);
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "doesntapplytome.bin",
GIT_FILTER_TO_WORKTREE, 0));
/* expect: none */
cl_assert_equal_sz(0, git_filter_list_length(fl));
git_filter_list_free(fl);
}
void test_filter_custom__order_dependency(void)
{
git_index *index;
git_blob *blob;
git_buf buf = { 0 };
/* so if ident and reverse are used together, an interesting thing
* happens - a reversed "$Id$" string is no longer going to trigger
* ident correctly. When checking out, the filters should be applied
* in order CLRF, then ident, then reverse, so ident expansion should
* work correctly. On check in, the content should be reversed, then
* ident, then CRLF filtered. Let's make sure that works...
*/
cl_git_mkfile(
"empty_standard_repo/.gitattributes",
"hero.*.rev-ident text ident prereverse eol=lf\n");
cl_git_mkfile(
"empty_standard_repo/hero.1.rev-ident",
"This is a test\n$Id$\nHave fun!\n");
cl_git_mkfile(
"empty_standard_repo/hero.2.rev-ident",
"Another test\n$dI$\nCrazy!\n");
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_add_bypath(index, "hero.1.rev-ident"));
cl_git_pass(git_index_add_bypath(index, "hero.2.rev-ident"));
cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "Filter chains\n");
git_index_free(index);
cl_git_pass(git_blob_lookup(&blob, g_repo,
& git_index_get_bypath(index, "hero.1.rev-ident", 0)->id));
cl_assert_equal_s(
"\n!nuf evaH\n$dI$\ntset a si sihT", git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "hero.1.rev-ident", NULL));
/* no expansion because id was reversed at checkin and now at ident
* time, reverse is not applied yet */
cl_assert_equal_s(
"This is a test\n$Id$\nHave fun!\n", buf.ptr);
git_blob_free(blob);
cl_git_pass(git_blob_lookup(&blob, g_repo,
& git_index_get_bypath(index, "hero.2.rev-ident", 0)->id));
cl_assert_equal_s(
"\n!yzarC\n$Id$\ntset rehtonA", git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "hero.2.rev-ident", NULL));
/* expansion because reverse was applied at checkin and at ident time,
* reverse is not applied yet */
cl_assert_equal_s(
"Another test\n$ 59001fe193103b1016b27027c0c827d036fd0ac8 :dI$\nCrazy!\n", buf.ptr);
cl_assert_equal_i(0, git_oid_strcmp(
git_blob_id(blob), "8ca0df630d728c0c72072b6101b301391ef10095"));
git_blob_free(blob);
git_buf_dispose(&buf);
}
void test_filter_custom__filter_registry_failure_cases(void)
{
git_filter fake = { GIT_FILTER_VERSION, 0 };
cl_assert_equal_i(GIT_EEXISTS, git_filter_register("bitflip", &fake, 0));
cl_git_fail(git_filter_unregister(GIT_FILTER_CRLF));
cl_git_fail(git_filter_unregister(GIT_FILTER_IDENT));
cl_assert_equal_i(GIT_ENOTFOUND, git_filter_unregister("not-a-filter"));
}
void test_filter_custom__erroneous_filter_fails(void)
{
git_filter_list *filters;
git_buf out = GIT_BUF_INIT;
const char *in;
size_t in_len;
cl_git_pass(git_filter_list_load(
&filters, g_repo, NULL, "villain", GIT_FILTER_TO_WORKTREE, 0));
in = workdir_data;
in_len = strlen(workdir_data);
cl_git_fail(git_filter_list_apply_to_buffer(&out, filters, in, in_len));
git_filter_list_free(filters);
git_buf_dispose(&out);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/ident.c
|
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
static git_repository *g_repo = NULL;
void test_filter_ident__initialize(void)
{
g_repo = cl_git_sandbox_init("crlf");
}
void test_filter_ident__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void add_blob_and_filter(
const char *data,
git_filter_list *fl,
const char *expected)
{
git_oid id;
git_blob *blob;
git_buf out = { 0 };
cl_git_mkfile("crlf/identtest", data);
cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "identtest"));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
cl_assert_equal_s(expected, out.ptr);
git_blob_free(blob);
git_buf_dispose(&out);
}
void test_filter_ident__to_worktree(void)
{
git_filter_list *fl;
git_filter *ident;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_WORKTREE, 0));
ident = git_filter_lookup(GIT_FILTER_IDENT);
cl_assert(ident != NULL);
cl_git_pass(git_filter_list_push(fl, ident, NULL));
add_blob_and_filter(
"Hello\n$Id$\nFun stuff\n", fl,
"Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30 $\nFun stuff\n");
add_blob_and_filter(
"Hello\n$Id: Junky$\nFun stuff\n", fl,
"Hello\n$Id: 45cd107a7102911cb2a7df08404674327fa050b9 $\nFun stuff\n");
add_blob_and_filter(
"$Id$\nAt the start\n", fl,
"$Id: b13415c767abc196fb95bd17070e8c1113e32160 $\nAt the start\n");
add_blob_and_filter(
"At the end\n$Id$", fl,
"At the end\n$Id: 1344925c6bc65b34c5a7b50f86bf688e48e9a272 $");
add_blob_and_filter(
"$Id$", fl,
"$Id: b3f5ebfb5843bc43ceecff6d4f26bb37c615beb1 $");
add_blob_and_filter(
"$Id: Some sort of junk goes here$", fl,
"$Id: ab2dd3853c7c9a4bff55aca2bea077a73c32ac06 $");
add_blob_and_filter("$Id: ", fl, "$Id: ");
add_blob_and_filter("$Id", fl, "$Id");
add_blob_and_filter("$I", fl, "$I");
add_blob_and_filter("Id$", fl, "Id$");
git_filter_list_free(fl);
}
void test_filter_ident__to_odb(void)
{
git_filter_list *fl;
git_filter *ident;
cl_git_pass(git_filter_list_new(
&fl, g_repo, GIT_FILTER_TO_ODB, 0));
ident = git_filter_lookup(GIT_FILTER_IDENT);
cl_assert(ident != NULL);
cl_git_pass(git_filter_list_push(fl, ident, NULL));
add_blob_and_filter(
"Hello\n$Id$\nFun stuff\n",
fl, "Hello\n$Id$\nFun stuff\n");
add_blob_and_filter(
"Hello\n$Id: b69e2387aafcaf73c4de5b9ab59abe27fdadee30$\nFun stuff\n",
fl, "Hello\n$Id$\nFun stuff\n");
add_blob_and_filter(
"Hello\n$Id: Any junk you may have left here$\nFun stuff\n",
fl, "Hello\n$Id$\nFun stuff\n");
add_blob_and_filter(
"Hello\n$Id:$\nFun stuff\n",
fl, "Hello\n$Id$\nFun stuff\n");
add_blob_and_filter(
"Hello\n$Id:x$\nFun stuff\n",
fl, "Hello\n$Id$\nFun stuff\n");
add_blob_and_filter(
"$Id$\nAt the start\n", fl, "$Id$\nAt the start\n");
add_blob_and_filter(
"$Id: lots of random text that should be removed from here$\nAt the start\n", fl, "$Id$\nAt the start\n");
add_blob_and_filter(
"$Id: lots of random text that should not be removed without a terminator\nAt the start\n", fl, "$Id: lots of random text that should not be removed without a terminator\nAt the start\n");
add_blob_and_filter(
"At the end\n$Id$", fl, "At the end\n$Id$");
add_blob_and_filter(
"At the end\n$Id:$", fl, "At the end\n$Id$");
add_blob_and_filter(
"At the end\n$Id:asdfasdf$", fl, "At the end\n$Id$");
add_blob_and_filter(
"At the end\n$Id", fl, "At the end\n$Id");
add_blob_and_filter(
"At the end\n$IddI", fl, "At the end\n$IddI");
add_blob_and_filter("$Id$", fl, "$Id$");
add_blob_and_filter("$Id: any$", fl, "$Id$");
add_blob_and_filter("$Id: any long stuff goes here you see$", fl, "$Id$");
add_blob_and_filter("$Id: ", fl, "$Id: ");
add_blob_and_filter("$Id", fl, "$Id");
add_blob_and_filter("$I", fl, "$I");
add_blob_and_filter("Id$", fl, "Id$");
git_filter_list_free(fl);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/blob.c
|
#include "clar_libgit2.h"
#include "crlf.h"
static git_repository *g_repo = NULL;
void test_filter_blob__initialize(void)
{
g_repo = cl_git_sandbox_init("crlf");
cl_git_mkfile("crlf/.gitattributes",
"*.txt text\n*.bin binary\n"
"*.crlf text eol=crlf\n"
"*.lf text eol=lf\n"
"*.ident text ident\n"
"*.identcrlf ident text eol=crlf\n"
"*.identlf ident text eol=lf\n");
}
void test_filter_blob__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_filter_blob__all_crlf(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "a9a2e891")); /* all-crlf */
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
cl_assert_equal_s(ALL_CRLF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
/* in this case, raw content has crlf in it already */
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
/* we never convert CRLF -> LF on platforms that have LF */
cl_assert_equal_s(ALL_CRLF_TEXT_AS_CRLF, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_blob__from_lf(void)
{
git_blob *blob;
git_buf buf = { 0 };
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "799770d")); /* all-lf */
cl_assert_equal_s(ALL_LF_TEXT_RAW, git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
cl_assert_equal_s(ALL_LF_TEXT_RAW, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
/* in this case, raw content has crlf in it already */
cl_assert_equal_s(ALL_LF_TEXT_AS_CRLF, buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
/* we never convert CRLF -> LF on platforms that have LF */
cl_assert_equal_s(ALL_LF_TEXT_AS_LF, buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_blob__sanitizes(void)
{
git_blob *blob;
git_buf buf;
cl_git_pass(git_revparse_single(
(git_object **)&blob, g_repo, "e69de29")); /* zero-byte */
cl_assert_equal_i(0, git_blob_rawsize(blob));
cl_assert_equal_s("", git_blob_rawcontent(blob));
memset(&buf, 0, sizeof(git_buf));
cl_git_pass(git_blob_filter(&buf, blob, "file.bin", NULL));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
memset(&buf, 0, sizeof(git_buf));
cl_git_pass(git_blob_filter(&buf, blob, "file.crlf", NULL));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
memset(&buf, 0, sizeof(git_buf));
cl_git_pass(git_blob_filter(&buf, blob, "file.lf", NULL));
cl_assert_equal_sz(0, buf.size);
cl_assert_equal_s("", buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
void test_filter_blob__ident(void)
{
git_oid id;
git_blob *blob;
git_buf buf = { 0 };
cl_git_mkfile("crlf/test.ident", "Some text\n$Id$\nGoes there\n");
cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "test.ident"));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_assert_equal_s(
"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
git_blob_free(blob);
cl_git_mkfile("crlf/test.ident", "Some text\n$Id: Any old just you want$\nGoes there\n");
cl_git_pass(git_blob_create_from_workdir(&id, g_repo, "test.ident"));
cl_git_pass(git_blob_lookup(&blob, g_repo, &id));
cl_assert_equal_s(
"Some text\n$Id$\nGoes there\n", git_blob_rawcontent(blob));
cl_git_pass(git_blob_filter(&buf, blob, "filter.bin", NULL));
cl_assert_equal_s(
"Some text\n$Id$\nGoes there\n", buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "filter.identcrlf", NULL));
cl_assert_equal_s(
"Some text\r\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\r\nGoes there\r\n", buf.ptr);
cl_git_pass(git_blob_filter(&buf, blob, "filter.identlf", NULL));
cl_assert_equal_s(
"Some text\n$Id: 3164f585d548ac68027d22b104f2d8100b2b6845 $\nGoes there\n", buf.ptr);
git_buf_dispose(&buf);
git_blob_free(blob);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/query.c
|
#include "clar_libgit2.h"
#include "git2/sys/filter.h"
#include "crlf.h"
#include "buffer.h"
static git_repository *g_repo = NULL;
void test_filter_query__initialize(void)
{
g_repo = cl_git_sandbox_init("crlf");
cl_git_mkfile("crlf/.gitattributes",
"*.txt text\n"
"*.bin binary\n"
"*.crlf text eol=crlf\n"
"*.lf text eol=lf\n"
"*.binident binary ident\n"
"*.ident text ident\n"
"*.identcrlf ident text eol=crlf\n"
"*.identlf ident text eol=lf\n"
"*.custom custom ident text\n");
}
void test_filter_query__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static int filter_for(const char *filename, const char *filter)
{
git_filter_list *fl;
int filtered;
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, filename, GIT_FILTER_TO_WORKTREE, 0));
filtered = git_filter_list_contains(fl, filter);
git_filter_list_free(fl);
return filtered;
}
void test_filter_query__filters(void)
{
cl_assert_equal_i(1, filter_for("text.txt", "crlf"));
cl_assert_equal_i(0, filter_for("binary.bin", "crlf"));
cl_assert_equal_i(1, filter_for("foo.lf", "crlf"));
cl_assert_equal_i(0, filter_for("foo.lf", "ident"));
cl_assert_equal_i(1, filter_for("id.ident", "crlf"));
cl_assert_equal_i(1, filter_for("id.ident", "ident"));
cl_assert_equal_i(0, filter_for("id.binident", "crlf"));
cl_assert_equal_i(1, filter_for("id.binident", "ident"));
}
void test_filter_query__autocrlf_true_implies_crlf(void)
{
cl_repo_set_bool(g_repo, "core.autocrlf", true);
cl_assert_equal_i(1, filter_for("not_in_gitattributes", "crlf"));
cl_assert_equal_i(1, filter_for("foo.txt", "crlf"));
cl_assert_equal_i(0, filter_for("foo.bin", "crlf"));
cl_assert_equal_i(1, filter_for("foo.lf", "crlf"));
cl_repo_set_bool(g_repo, "core.autocrlf", false);
cl_assert_equal_i(0, filter_for("not_in_gitattributes", "crlf"));
cl_assert_equal_i(1, filter_for("foo.txt", "crlf"));
cl_assert_equal_i(0, filter_for("foo.bin", "crlf"));
cl_assert_equal_i(1, filter_for("foo.lf", "crlf"));
}
void test_filter_query__unknown(void)
{
cl_assert_equal_i(1, filter_for("foo.custom", "crlf"));
cl_assert_equal_i(1, filter_for("foo.custom", "ident"));
cl_assert_equal_i(0, filter_for("foo.custom", "custom"));
}
void test_filter_query__custom(void)
{
git_filter custom = { GIT_FILTER_VERSION };
cl_git_pass(git_filter_register(
"custom", &custom, 42));
cl_assert_equal_i(1, filter_for("foo.custom", "crlf"));
cl_assert_equal_i(1, filter_for("foo.custom", "ident"));
cl_assert_equal_i(1, filter_for("foo.custom", "custom"));
git_filter_unregister("custom");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/filter/crlf.h
|
#ifndef INCLUDE_filter_crlf_h__
#define INCLUDE_filter_crlf_h__
/*
* file content for files in the resources/crlf repository
*/
#define UTF8_BOM "\xEF\xBB\xBF"
#define ALL_CRLF_TEXT_RAW "crlf\r\ncrlf\r\ncrlf\r\ncrlf\r\n"
#define ALL_LF_TEXT_RAW "lf\nlf\nlf\nlf\nlf\n"
#define MORE_CRLF_TEXT_RAW "crlf\r\ncrlf\r\nlf\ncrlf\r\ncrlf\r\n"
#define MORE_LF_TEXT_RAW "lf\nlf\ncrlf\r\nlf\nlf\n"
#define ALL_CRLF_TEXT_AS_CRLF ALL_CRLF_TEXT_RAW
#define ALL_LF_TEXT_AS_CRLF "lf\r\nlf\r\nlf\r\nlf\r\nlf\r\n"
#define MORE_CRLF_TEXT_AS_CRLF "crlf\r\ncrlf\r\nlf\r\ncrlf\r\ncrlf\r\n"
#define MORE_LF_TEXT_AS_CRLF "lf\r\nlf\r\ncrlf\r\nlf\r\nlf\r\n"
#define ALL_CRLF_TEXT_AS_LF "crlf\ncrlf\ncrlf\ncrlf\n"
#define ALL_LF_TEXT_AS_LF ALL_LF_TEXT_RAW
#define MORE_CRLF_TEXT_AS_LF "crlf\ncrlf\nlf\ncrlf\ncrlf\n"
#define MORE_LF_TEXT_AS_LF "lf\nlf\ncrlf\nlf\nlf\n"
#define FEW_UTF8_CRLF_RAW "\xe2\x9a\xbdThe rest is ASCII01.\r\nThe rest is ASCII02.\r\nThe rest is ASCII03.\r\nThe rest is ASCII04.\r\nThe rest is ASCII05.\r\nThe rest is ASCII06.\r\nThe rest is ASCII07.\r\nThe rest is ASCII08.\r\nThe rest is ASCII09.\r\nThe rest is ASCII10.\r\nThe rest is ASCII11.\r\nThe rest is ASCII12.\r\nThe rest is ASCII13.\r\nThe rest is ASCII14.\r\nThe rest is ASCII15.\r\nThe rest is ASCII16.\r\nThe rest is ASCII17.\r\nThe rest is ASCII18.\r\nThe rest is ASCII19.\r\nThe rest is ASCII20.\r\nThe rest is ASCII21.\r\nThe rest is ASCII22.\r\n"
#define FEW_UTF8_LF_RAW "\xe2\x9a\xbdThe rest is ASCII01.\nThe rest is ASCII02.\nThe rest is ASCII03.\nThe rest is ASCII04.\nThe rest is ASCII05.\nThe rest is ASCII06.\nThe rest is ASCII07.\nThe rest is ASCII08.\nThe rest is ASCII09.\nThe rest is ASCII10.\nThe rest is ASCII11.\nThe rest is ASCII12.\nThe rest is ASCII13.\nThe rest is ASCII14.\nThe rest is ASCII15.\nThe rest is ASCII16.\nThe rest is ASCII17.\nThe rest is ASCII18.\nThe rest is ASCII19.\nThe rest is ASCII20.\nThe rest is ASCII21.\nThe rest is ASCII22.\n"
#define MANY_UTF8_CRLF_RAW "Lets sing!\r\n\xe2\x99\xab\xe2\x99\xaa\xe2\x99\xac\xe2\x99\xa9\r\nEat food\r\n\xf0\x9f\x8d\x85\xf0\x9f\x8d\x95\r\n"
#define MANY_UTF8_LF_RAW "Lets sing!\n\xe2\x99\xab\xe2\x99\xaa\xe2\x99\xac\xe2\x99\xa9\nEat food\n\xf0\x9f\x8d\x85\xf0\x9f\x8d\x95\n"
#endif
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/peel.c
|
#include "clar_libgit2.h"
static git_repository *g_repo;
void test_object_peel__initialize(void)
{
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
}
void test_object_peel__cleanup(void)
{
git_repository_free(g_repo);
g_repo = NULL;
}
static void assert_peel(
const char *sha,
git_object_t requested_type,
const char* expected_sha,
git_object_t expected_type)
{
git_oid oid, expected_oid;
git_object *obj;
git_object *peeled;
cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_git_pass(git_object_peel(&peeled, obj, requested_type));
cl_git_pass(git_oid_fromstr(&expected_oid, expected_sha));
cl_assert_equal_oid(&expected_oid, git_object_id(peeled));
cl_assert_equal_i(expected_type, git_object_type(peeled));
git_object_free(peeled);
git_object_free(obj);
}
static void assert_peel_error(int error, const char *sha, git_object_t requested_type)
{
git_oid oid;
git_object *obj;
git_object *peeled;
cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert_equal_i(error, git_object_peel(&peeled, obj, requested_type));
git_object_free(obj);
}
void test_object_peel__peeling_an_object_into_its_own_type_returns_another_instance_of_it(void)
{
assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT,
"e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT);
assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_TAG,
"7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_TAG);
assert_peel("53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
assert_peel("0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_BLOB,
"0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_BLOB);
}
void test_object_peel__tag(void)
{
assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_COMMIT,
"e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT);
assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_TREE,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
assert_peel_error(GIT_EPEEL, "7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_BLOB);
assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_ANY,
"e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT);
}
void test_object_peel__commit(void)
{
assert_peel_error(GIT_EINVALIDSPEC, "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_BLOB);
assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_TREE,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT,
"e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT);
assert_peel_error(GIT_EINVALIDSPEC, "e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_TAG);
assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_ANY,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
}
void test_object_peel__tree(void)
{
assert_peel_error(GIT_EINVALIDSPEC, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_BLOB);
assert_peel("53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
assert_peel_error(GIT_EINVALIDSPEC, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_COMMIT);
assert_peel_error(GIT_EINVALIDSPEC, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TAG);
assert_peel_error(GIT_EINVALIDSPEC, "53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_ANY);
}
void test_object_peel__blob(void)
{
assert_peel("0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_BLOB,
"0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_BLOB);
assert_peel_error(GIT_EINVALIDSPEC, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_TREE);
assert_peel_error(GIT_EINVALIDSPEC, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_COMMIT);
assert_peel_error(GIT_EINVALIDSPEC, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_TAG);
assert_peel_error(GIT_EINVALIDSPEC, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", GIT_OBJECT_ANY);
}
void test_object_peel__target_any_object_for_type_change(void)
{
/* tag to commit */
assert_peel("7b4384978d2493e851f9cca7858815fac9b10980", GIT_OBJECT_ANY,
"e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_COMMIT);
/* commit to tree */
assert_peel("e90810b8df3e80c413d903f631643c716887138d", GIT_OBJECT_ANY,
"53fc32d17276939fc79ed05badaef2db09990016", GIT_OBJECT_TREE);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/lookupbypath.c
|
#include "clar_libgit2.h"
#include "repository.h"
static git_repository *g_repo;
static git_tree *g_root_tree;
static git_commit *g_head_commit;
static git_object *g_expectedobject,
*g_actualobject;
void test_object_lookupbypath__initialize(void)
{
git_reference *head;
git_tree_entry *tree_entry;
cl_git_pass(git_repository_open(&g_repo, cl_fixture("attr/.gitted")));
cl_git_pass(git_repository_head(&head, g_repo));
cl_git_pass(git_reference_peel((git_object**)&g_head_commit, head, GIT_OBJECT_COMMIT));
cl_git_pass(git_commit_tree(&g_root_tree, g_head_commit));
cl_git_pass(git_tree_entry_bypath(&tree_entry, g_root_tree, "subdir/subdir_test2.txt"));
cl_git_pass(git_object_lookup(&g_expectedobject, g_repo, git_tree_entry_id(tree_entry),
GIT_OBJECT_ANY));
git_tree_entry_free(tree_entry);
git_reference_free(head);
g_actualobject = NULL;
}
void test_object_lookupbypath__cleanup(void)
{
git_object_free(g_actualobject);
git_object_free(g_expectedobject);
git_tree_free(g_root_tree);
git_commit_free(g_head_commit);
g_expectedobject = NULL;
git_repository_free(g_repo);
g_repo = NULL;
}
void test_object_lookupbypath__errors(void)
{
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_object_lookup_bypath(&g_actualobject, (git_object*)g_root_tree,
"subdir/subdir_test2.txt", GIT_OBJECT_TREE)); /* It's not a tree */
cl_assert_equal_i(GIT_ENOTFOUND,
git_object_lookup_bypath(&g_actualobject, (git_object*)g_root_tree,
"file/doesnt/exist", GIT_OBJECT_ANY));
}
void test_object_lookupbypath__from_root_tree(void)
{
cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)g_root_tree,
"subdir/subdir_test2.txt", GIT_OBJECT_BLOB));
cl_assert_equal_oid(git_object_id(g_expectedobject),
git_object_id(g_actualobject));
}
void test_object_lookupbypath__from_head_commit(void)
{
cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)g_head_commit,
"subdir/subdir_test2.txt", GIT_OBJECT_BLOB));
cl_assert_equal_oid(git_object_id(g_expectedobject),
git_object_id(g_actualobject));
}
void test_object_lookupbypath__from_subdir_tree(void)
{
git_tree_entry *entry = NULL;
git_tree *tree = NULL;
cl_git_pass(git_tree_entry_bypath(&entry, g_root_tree, "subdir"));
cl_git_pass(git_tree_lookup(&tree, g_repo, git_tree_entry_id(entry)));
cl_git_pass(git_object_lookup_bypath(&g_actualobject, (git_object*)tree,
"subdir_test2.txt", GIT_OBJECT_BLOB));
cl_assert_equal_oid(git_object_id(g_expectedobject),
git_object_id(g_actualobject));
git_tree_entry_free(entry);
git_tree_free(tree);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/cache.c
|
#include "clar_libgit2.h"
#include "repository.h"
static git_repository *g_repo;
static size_t cache_limit;
static int object_type;
void test_object_cache__initialize_cache_no_blobs(void)
{
g_repo = NULL;
object_type = GIT_OBJECT_BLOB;
cache_limit = 0;
}
void test_object_cache__initialize_cache_tiny_blobs(void)
{
g_repo = NULL;
object_type = GIT_OBJECT_BLOB;
cache_limit = 10;
}
void test_object_cache__initialize_cache_all_blobs(void)
{
g_repo = NULL;
object_type = GIT_OBJECT_BLOB;
cache_limit = 32767;
}
void test_object_cache__initialize_cache_no_trees(void)
{
g_repo = NULL;
object_type = GIT_OBJECT_TREE;
cache_limit = 0;
}
void test_object_cache__cleanup(void)
{
git_repository_free(g_repo);
g_repo = NULL;
git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_BLOB, (size_t)0);
git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_TREE, (size_t)4096);
git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJECT_COMMIT, (size_t)4096);
}
static struct {
git_object_t type;
const char *sha;
size_t size;
} g_data[] = {
/* HEAD */
{ GIT_OBJECT_BLOB, "a8233120f6ad708f843d861ce2b7228ec4e3dec6", 10 }, /* README */
{ GIT_OBJECT_BLOB, "3697d64be941a53d4ae8f6a271e4e3fa56b022cc", 8 }, /* branch_file.txt */
{ GIT_OBJECT_BLOB, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", 12 }, /* new.txt */
/* refs/heads/subtrees */
{ GIT_OBJECT_BLOB, "1385f264afb75a56a5bec74243be9b367ba4ca08", 4 }, /* README */
{ GIT_OBJECT_TREE, "f1425cef211cc08caa31e7b545ffb232acb098c3", 90 }, /* ab */
{ GIT_OBJECT_BLOB, "d6c93164c249c8000205dd4ec5cbca1b516d487f", 6 }, /* ab/4.txt */
{ GIT_OBJECT_TREE, "9a03079b8a8ee85a0bee58bf9be3da8b62414ed4", 33 }, /* ab/c */
{ GIT_OBJECT_BLOB, "270b8ea76056d5cad83af921837702d3e3c2924d", 6 }, /* ab/c/3.txt */
{ GIT_OBJECT_TREE, "b6361fc6a97178d8fc8639fdeed71c775ab52593", 63 }, /* ab/de */
{ GIT_OBJECT_BLOB, "e7b4ad382349ff96dd8199000580b9b1e2042eb0", 6 }, /* ab/de/2.txt */
{ GIT_OBJECT_TREE, "3259a6bd5b57fb9c1281bb7ed3167b50f224cb54", 33 }, /* ab/de/fgh */
{ GIT_OBJECT_BLOB, "1f67fc4386b2d171e0d21be1c447e12660561f9b", 6 }, /* ab/de/fgh/1.txt */
{ GIT_OBJECT_BLOB, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057", 3 }, /* branch_file.txt */
{ GIT_OBJECT_BLOB, "fa49b077972391ad58037050f2a75f74e3671e92", 9 }, /* new.txt */
/* refs/heads/chomped */
{ GIT_OBJECT_BLOB, "0266163a49e280c4f5ed1e08facd36a2bd716bcf", 51 }, /* readme.txt */
{ 0, NULL, 0 },
{ 0, NULL, 0 }
};
void test_object_cache__cache_counts(void)
{
int i, start, nonmatching = 0;
git_oid oid;
git_odb_object *odb_obj;
git_object *obj;
git_odb *odb;
git_libgit2_opts(GIT_OPT_SET_CACHE_OBJECT_LIMIT, object_type, cache_limit);
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_odb(&odb, g_repo));
start = (int)git_cache_size(&g_repo->objects);
for (i = 0; g_data[i].sha != NULL; ++i) {
int count = (int)git_cache_size(&g_repo->objects);
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
/* alternate between loading raw and parsed objects */
if ((i & 1) == 0) {
cl_git_pass(git_odb_read(&odb_obj, odb, &oid));
cl_assert(g_data[i].type == git_odb_object_type(odb_obj));
git_odb_object_free(odb_obj);
} else {
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert(g_data[i].type == git_object_type(obj));
git_object_free(obj);
}
if ((g_data[i].type == object_type && g_data[i].size >= cache_limit) ||
(g_data[i].type != object_type && g_data[i].type == GIT_OBJECT_BLOB))
cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects));
else {
cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects));
nonmatching++;
}
}
cl_assert_equal_i(nonmatching, (int)git_cache_size(&g_repo->objects) - start);
for (i = 0; g_data[i].sha != NULL; ++i) {
int count = (int)git_cache_size(&g_repo->objects);
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert(g_data[i].type == git_object_type(obj));
git_object_free(obj);
cl_assert_equal_i(count, (int)git_cache_size(&g_repo->objects));
}
git_odb_free(odb);
}
static void *cache_parsed(void *arg)
{
int i;
git_oid oid;
git_object *obj;
for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) {
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert(g_data[i].type == git_object_type(obj));
git_object_free(obj);
}
for (i = 0; i < ((int *)arg)[1]; i += 2) {
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert(g_data[i].type == git_object_type(obj));
git_object_free(obj);
}
return arg;
}
static void *cache_raw(void *arg)
{
int i;
git_oid oid;
git_odb *odb;
git_odb_object *odb_obj;
cl_git_pass(git_repository_odb(&odb, g_repo));
for (i = ((int *)arg)[1]; g_data[i].sha != NULL; i += 2) {
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
cl_git_pass(git_odb_read(&odb_obj, odb, &oid));
cl_assert(g_data[i].type == git_odb_object_type(odb_obj));
git_odb_object_free(odb_obj);
}
for (i = 0; i < ((int *)arg)[1]; i += 2) {
cl_git_pass(git_oid_fromstr(&oid, g_data[i].sha));
cl_git_pass(git_odb_read(&odb_obj, odb, &oid));
cl_assert(g_data[i].type == git_odb_object_type(odb_obj));
git_odb_object_free(odb_obj);
}
git_odb_free(odb);
return arg;
}
#define REPEAT 20
#define THREADCOUNT 50
void test_object_cache__threadmania(void)
{
int try, th, max_i;
void *data;
void *(*fn)(void *);
#ifdef GIT_THREADS
git_thread t[THREADCOUNT];
#endif
for (max_i = 0; g_data[max_i].sha != NULL; ++max_i)
/* count up */;
for (try = 0; try < REPEAT; ++try) {
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
for (th = 0; th < THREADCOUNT; ++th) {
data = git__malloc(2 * sizeof(int));
((int *)data)[0] = th;
((int *)data)[1] = th % max_i;
fn = (th & 1) ? cache_parsed : cache_raw;
#ifdef GIT_THREADS
cl_git_pass(git_thread_create(&t[th], fn, data));
#else
cl_assert(fn(data) == data);
git__free(data);
#endif
}
#ifdef GIT_THREADS
for (th = 0; th < THREADCOUNT; ++th) {
cl_git_pass(git_thread_join(&t[th], &data));
cl_assert_equal_i(th, ((int *)data)[0]);
git__free(data);
}
#endif
git_repository_free(g_repo);
g_repo = NULL;
}
}
static void *cache_quick(void *arg)
{
git_oid oid;
git_object *obj;
cl_git_pass(git_oid_fromstr(&oid, g_data[4].sha));
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJECT_ANY));
cl_assert(g_data[4].type == git_object_type(obj));
git_object_free(obj);
return arg;
}
void test_object_cache__fast_thread_rush(void)
{
int try, th, data[THREADCOUNT];
#ifdef GIT_THREADS
git_thread t[THREADCOUNT];
#endif
for (try = 0; try < REPEAT; ++try) {
cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));
for (th = 0; th < THREADCOUNT; ++th) {
data[th] = th;
#ifdef GIT_THREADS
cl_git_pass(
git_thread_create(&t[th], cache_quick, &data[th]));
#else
cl_assert(cache_quick(&data[th]) == &data[th]);
#endif
}
#ifdef GIT_THREADS
for (th = 0; th < THREADCOUNT; ++th) {
void *rval;
cl_git_pass(git_thread_join(&t[th], &rval));
cl_assert_equal_i(th, *((int *)rval));
}
#endif
git_repository_free(g_repo);
g_repo = NULL;
}
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/shortid.c
|
#include "clar_libgit2.h"
git_repository *_repo;
void test_object_shortid__initialize(void)
{
cl_git_pass(git_repository_open(&_repo, cl_fixture("duplicate.git")));
}
void test_object_shortid__cleanup(void)
{
git_repository_free(_repo);
_repo = NULL;
}
void test_object_shortid__select(void)
{
git_oid full;
git_object *obj;
git_buf shorty = {0};
git_oid_fromstr(&full, "ce013625030ba8dba906f756967f9e9ca394464a");
cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY));
cl_git_pass(git_object_short_id(&shorty, obj));
cl_assert_equal_i(7, shorty.size);
cl_assert_equal_s("ce01362", shorty.ptr);
git_object_free(obj);
git_oid_fromstr(&full, "038d718da6a1ebbc6a7780a96ed75a70cc2ad6e2");
cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY));
cl_git_pass(git_object_short_id(&shorty, obj));
cl_assert_equal_i(7, shorty.size);
cl_assert_equal_s("038d718", shorty.ptr);
git_object_free(obj);
git_oid_fromstr(&full, "dea509d097ce692e167dfc6a48a7a280cc5e877e");
cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY));
cl_git_pass(git_object_short_id(&shorty, obj));
cl_assert_equal_i(9, shorty.size);
cl_assert_equal_s("dea509d09", shorty.ptr);
git_object_free(obj);
git_oid_fromstr(&full, "dea509d0b3cb8ee0650f6ca210bc83f4678851ba");
cl_git_pass(git_object_lookup(&obj, _repo, &full, GIT_OBJECT_ANY));
cl_git_pass(git_object_short_id(&shorty, obj));
cl_assert_equal_i(9, shorty.size);
cl_assert_equal_s("dea509d0b", shorty.ptr);
git_object_free(obj);
git_buf_dispose(&shorty);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/lookup.c
|
#include "clar_libgit2.h"
#include "repository.h"
static git_repository *g_repo;
void test_object_lookup__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
}
void test_object_lookup__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_lookup__lookup_wrong_type_returns_enotfound(void)
{
const char *commit = "e90810b8df3e80c413d903f631643c716887138d";
git_oid oid;
git_object *object;
cl_git_pass(git_oid_fromstr(&oid, commit));
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG));
}
void test_object_lookup__lookup_nonexisting_returns_enotfound(void)
{
const char *unknown = "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef";
git_oid oid;
git_object *object;
cl_git_pass(git_oid_fromstr(&oid, unknown));
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_ANY));
}
void test_object_lookup__lookup_wrong_type_by_abbreviated_id_returns_enotfound(void)
{
const char *commit = "e90810b";
git_oid oid;
git_object *object;
cl_git_pass(git_oid_fromstrn(&oid, commit, strlen(commit)));
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup_prefix(&object, g_repo, &oid, strlen(commit), GIT_OBJECT_TAG));
}
void test_object_lookup__lookup_wrong_type_eventually_returns_enotfound(void)
{
const char *commit = "e90810b8df3e80c413d903f631643c716887138d";
git_oid oid;
git_object *object;
cl_git_pass(git_oid_fromstr(&oid, commit));
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
git_object_free(object);
cl_assert_equal_i(
GIT_ENOTFOUND, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_TAG));
}
void test_object_lookup__lookup_corrupt_object_returns_error(void)
{
const char *commit = "8e73b769e97678d684b809b163bebdae2911720f",
*file = "objects/8e/73b769e97678d684b809b163bebdae2911720f";
git_buf path = GIT_BUF_INIT, contents = GIT_BUF_INIT;
git_oid oid;
git_object *object;
size_t i;
cl_git_pass(git_oid_fromstr(&oid, commit));
cl_git_pass(git_buf_joinpath(&path, git_repository_path(g_repo), file));
cl_git_pass(git_futils_readbuffer(&contents, path.ptr));
/* Corrupt and try to read the object */
for (i = 0; i < contents.size; i++) {
contents.ptr[i] ^= 0x1;
cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644));
cl_git_fail(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
contents.ptr[i] ^= 0x1;
}
/* Restore original content and assert we can read the object */
cl_git_pass(git_futils_writebuffer(&contents, path.ptr, O_RDWR, 0644));
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
git_object_free(object);
git_buf_dispose(&path);
git_buf_dispose(&contents);
}
void test_object_lookup__lookup_object_with_wrong_hash_returns_error(void)
{
const char *oldloose = "objects/8e/73b769e97678d684b809b163bebdae2911720f",
*newloose = "objects/8e/73b769e97678d684b809b163bebdae2911720e",
*commit = "8e73b769e97678d684b809b163bebdae2911720e";
git_buf oldpath = GIT_BUF_INIT, newpath = GIT_BUF_INIT;
git_object *object;
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, commit));
/* Copy object to another location with wrong hash */
cl_git_pass(git_buf_joinpath(&oldpath, git_repository_path(g_repo), oldloose));
cl_git_pass(git_buf_joinpath(&newpath, git_repository_path(g_repo), newloose));
cl_git_pass(git_futils_cp(oldpath.ptr, newpath.ptr, 0644));
/* Verify that lookup fails due to a hashsum mismatch */
cl_git_fail_with(GIT_EMISMATCH, git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
/* Disable verification and try again */
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 0));
cl_git_pass(git_object_lookup(&object, g_repo, &oid, GIT_OBJECT_COMMIT));
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION, 1));
git_object_free(object);
git_buf_dispose(&oldpath);
git_buf_dispose(&newpath);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/message.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "message.h"
static void assert_message_prettifying(char *expected_output, char *input, int strip_comments)
{
git_buf prettified_message = GIT_BUF_INIT;
git_message_prettify(&prettified_message, input, strip_comments, '#');
cl_assert_equal_s(expected_output, git_buf_cstr(&prettified_message));
git_buf_dispose(&prettified_message);
}
#define t40 "A quick brown fox jumps over the lazy do"
#define s40 " "
#define sss s40 s40 s40 s40 s40 s40 s40 s40 s40 s40 /* # 400 */
#define ttt t40 t40 t40 t40 t40 t40 t40 t40 t40 t40 /* # 400 */
/* Ported from git.git */
/* see https://github.com/git/git/blob/master/t/t0030-stripspace.sh */
void test_object_message__long_lines_without_spaces_should_be_unchanged(void)
{
assert_message_prettifying(ttt "\n", ttt, 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt, 0);
assert_message_prettifying(ttt ttt ttt "\n", ttt ttt ttt, 0);
assert_message_prettifying(ttt ttt ttt ttt "\n", ttt ttt ttt ttt, 0);
}
void test_object_message__lines_with_spaces_at_the_beginning_should_be_unchanged(void)
{
assert_message_prettifying(sss ttt "\n", sss ttt, 0);
assert_message_prettifying(sss sss ttt "\n", sss sss ttt, 0);
assert_message_prettifying(sss sss sss ttt "\n", sss sss sss ttt, 0);
}
void test_object_message__lines_with_intermediate_spaces_should_be_unchanged(void)
{
assert_message_prettifying(ttt sss ttt "\n", ttt sss ttt, 0);
assert_message_prettifying(ttt sss sss ttt "\n", ttt sss sss ttt, 0);
}
void test_object_message__consecutive_blank_lines_should_be_unified(void)
{
assert_message_prettifying(ttt "\n\n" ttt "\n", ttt "\n\n\n\n\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt "\n\n" ttt "\n", ttt ttt "\n\n\n\n\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt ttt "\n\n" ttt "\n", ttt ttt ttt "\n\n\n\n\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n\n" ttt ttt "\n", ttt "\n\n\n\n\n" ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n\n" ttt ttt ttt "\n", ttt "\n\n\n\n\n" ttt ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n\n" ttt "\n", ttt "\n\t\n \n\n \t\t\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt "\n\n" ttt "\n", ttt ttt "\n\t\n \n\n \t\t\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt ttt "\n\n" ttt "\n", ttt ttt ttt "\n\t\n \n\n \t\t\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n\n" ttt ttt "\n", ttt "\n\t\n \n\n \t\t\n" ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n\n" ttt ttt ttt "\n", ttt "\n\t\n \n\n \t\t\n" ttt ttt ttt "\n", 0);
}
void test_object_message__only_consecutive_blank_lines_should_be_completely_removed(void)
{
assert_message_prettifying("", "\n", 0);
assert_message_prettifying("", "\n\n\n", 0);
assert_message_prettifying("", sss "\n" sss "\n" sss "\n", 0);
assert_message_prettifying("", sss sss "\n" sss "\n\n", 0);
}
void test_object_message__consecutive_blank_lines_at_the_beginning_should_be_removed(void)
{
assert_message_prettifying(ttt "\n", "\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", "\n\n\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt "\n", "\n\n\n" ttt ttt "\n", 0);
assert_message_prettifying(ttt ttt ttt "\n", "\n\n\n" ttt ttt ttt "\n", 0);
assert_message_prettifying(ttt ttt ttt ttt "\n", "\n\n\n" ttt ttt ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n", sss "\n" sss "\n" sss "\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", "\n" sss "\n" sss sss "\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", sss sss "\n" sss "\n\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", sss sss sss "\n\n\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", "\n" sss sss sss "\n\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n", "\n\n" sss sss sss "\n" ttt "\n", 0);
}
void test_object_message__consecutive_blank_lines_at_the_end_should_be_removed(void)
{
assert_message_prettifying(ttt "\n", ttt "\n\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n\n\n\n", 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt "\n\n\n\n", 0);
assert_message_prettifying(ttt ttt ttt "\n", ttt ttt ttt "\n\n\n\n", 0);
assert_message_prettifying(ttt ttt ttt ttt "\n", ttt ttt ttt ttt "\n\n\n\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n" sss "\n" sss "\n" sss "\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n\n" sss "\n" sss sss "\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n" sss sss "\n" sss "\n\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n" sss sss sss "\n\n\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n\n" sss sss sss "\n\n", 0);
assert_message_prettifying(ttt "\n", ttt "\n\n\n" sss sss sss "\n\n", 0);
}
void test_object_message__text_without_newline_at_end_should_end_with_newline(void)
{
assert_message_prettifying(ttt "\n", ttt, 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt, 0);
assert_message_prettifying(ttt ttt ttt "\n", ttt ttt ttt, 0);
assert_message_prettifying(ttt ttt ttt ttt "\n", ttt ttt ttt ttt, 0);
}
void test_object_message__text_plus_spaces_without_newline_should_not_show_spaces_and_end_with_newline(void)
{
assert_message_prettifying(ttt "\n", ttt sss, 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt sss, 0);
assert_message_prettifying(ttt ttt ttt "\n", ttt ttt ttt sss, 0);
assert_message_prettifying(ttt "\n", ttt sss sss, 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt sss sss, 0);
assert_message_prettifying(ttt "\n", ttt sss sss sss, 0);
}
void test_object_message__text_plus_spaces_ending_with_newline_should_be_cleaned_and_newline_must_remain(void){
assert_message_prettifying(ttt "\n", ttt sss "\n", 0);
assert_message_prettifying(ttt "\n", ttt sss sss "\n", 0);
assert_message_prettifying(ttt "\n", ttt sss sss sss "\n", 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt sss "\n", 0);
assert_message_prettifying(ttt ttt "\n", ttt ttt sss sss "\n", 0);
assert_message_prettifying(ttt ttt ttt "\n", ttt ttt ttt sss "\n", 0);
}
void test_object_message__spaces_with_newline_at_end_should_be_replaced_with_empty_string(void)
{
assert_message_prettifying("", sss "\n", 0);
assert_message_prettifying("", sss sss "\n", 0);
assert_message_prettifying("", sss sss sss "\n", 0);
assert_message_prettifying("", sss sss sss sss "\n", 0);
}
void test_object_message__spaces_without_newline_at_end_should_be_replaced_with_empty_string(void)
{
assert_message_prettifying("", "", 0);
assert_message_prettifying("", sss sss, 0);
assert_message_prettifying("", sss sss sss, 0);
assert_message_prettifying("", sss sss sss sss, 0);
}
void test_object_message__consecutive_text_lines_should_be_unchanged(void)
{
assert_message_prettifying(ttt ttt "\n" ttt "\n", ttt ttt "\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n" ttt ttt "\n" ttt "\n", ttt "\n" ttt ttt "\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n" ttt "\n" ttt "\n" ttt ttt "\n", ttt "\n" ttt "\n" ttt "\n" ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n" ttt "\n\n" ttt ttt "\n" ttt "\n", ttt "\n" ttt "\n\n" ttt ttt "\n" ttt "\n", 0);
assert_message_prettifying(ttt ttt "\n\n" ttt "\n" ttt ttt "\n", ttt ttt "\n\n" ttt "\n" ttt ttt "\n", 0);
assert_message_prettifying(ttt "\n" ttt ttt "\n\n" ttt "\n", ttt "\n" ttt ttt "\n\n" ttt "\n", 0);
}
void test_object_message__strip_comments(void)
{
assert_message_prettifying("", "# comment", 1);
assert_message_prettifying("", "# comment\n", 1);
assert_message_prettifying("", "# comment \n", 1);
assert_message_prettifying(ttt "\n", ttt "\n" "# comment\n", 1);
assert_message_prettifying(ttt "\n", "# comment\n" ttt "\n", 1);
assert_message_prettifying(ttt "\n" ttt "\n", ttt "\n" "# comment\n" ttt "\n", 1);
}
void test_object_message__keep_comments(void)
{
assert_message_prettifying("# comment\n", "# comment", 0);
assert_message_prettifying("# comment\n", "# comment\n", 0);
assert_message_prettifying("# comment\n", "# comment \n", 0);
assert_message_prettifying(ttt "\n" "# comment\n", ttt "\n" "# comment\n", 0);
assert_message_prettifying("# comment\n" ttt "\n", "# comment\n" ttt "\n", 0);
assert_message_prettifying(ttt "\n" "# comment\n" ttt "\n", ttt "\n" "# comment\n" ttt "\n", 0);
}
void test_object_message__message_prettify(void)
{
git_buf buffer;
memset(&buffer, 0, sizeof(buffer));
cl_git_pass(git_message_prettify(&buffer, "", 0, '#'));
cl_assert_equal_s(buffer.ptr, "");
git_buf_dispose(&buffer);
cl_git_pass(git_message_prettify(&buffer, "", 1, '#'));
cl_assert_equal_s(buffer.ptr, "");
git_buf_dispose(&buffer);
cl_git_pass(git_message_prettify(&buffer, "Short", 0, '#'));
cl_assert_equal_s("Short\n", buffer.ptr);
git_buf_dispose(&buffer);
cl_git_pass(git_message_prettify(&buffer, "Short", 1, '#'));
cl_assert_equal_s("Short\n", buffer.ptr);
git_buf_dispose(&buffer);
cl_git_pass(git_message_prettify(&buffer, "This is longer\nAnd multiline\n# with some comments still in\n", 0, '#'));
cl_assert_equal_s(buffer.ptr, "This is longer\nAnd multiline\n# with some comments still in\n");
git_buf_dispose(&buffer);
cl_git_pass(git_message_prettify(&buffer, "This is longer\nAnd multiline\n# with some comments still in\n", 1, '#'));
cl_assert_equal_s(buffer.ptr, "This is longer\nAnd multiline\n");
git_buf_dispose(&buffer);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/short.c
|
#include "clar_libgit2.h"
#include "odb.h"
#include "hash.h"
void test_object_raw_short__oid_shortener_no_duplicates(void)
{
git_oid_shorten *os;
int min_len;
os = git_oid_shorten_new(0);
cl_assert(os != NULL);
git_oid_shorten_add(os, "22596363b3de40b06f981fb85d82312e8c0ed511");
git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09");
git_oid_shorten_add(os, "16a0123456789abcdef4b775213c23a8bd74f5e0");
min_len = git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09");
cl_assert(min_len == GIT_OID_HEXSZ + 1);
git_oid_shorten_free(os);
}
static int insert_sequential_oids(
char ***out, git_oid_shorten *os, int n, int fail)
{
int i, min_len = 0;
char numbuf[16];
git_oid oid;
char **oids = git__calloc(n, sizeof(char *));
cl_assert(oids != NULL);
for (i = 0; i < n; ++i) {
p_snprintf(numbuf, sizeof(numbuf), "%u", (unsigned int)i);
git_hash_buf(&oid, numbuf, strlen(numbuf));
oids[i] = git__malloc(GIT_OID_HEXSZ + 1);
cl_assert(oids[i]);
git_oid_nfmt(oids[i], GIT_OID_HEXSZ + 1, &oid);
min_len = git_oid_shorten_add(os, oids[i]);
/* After "fail", we expect git_oid_shorten_add to fail */
if (fail >= 0 && i >= fail)
cl_assert(min_len < 0);
else
cl_assert(min_len >= 0);
}
*out = oids;
return min_len;
}
static void free_oids(int n, char **oids)
{
int i;
for (i = 0; i < n; ++i) {
git__free(oids[i]);
}
git__free(oids);
}
void test_object_raw_short__oid_shortener_stresstest_git_oid_shorten(void)
{
#define MAX_OIDS 1000
git_oid_shorten *os;
size_t i, j;
int min_len = 0, found_collision;
char **oids;
os = git_oid_shorten_new(0);
cl_assert(os != NULL);
/*
* Insert in the shortener 1000 unique SHA1 ids
*/
min_len = insert_sequential_oids(&oids, os, MAX_OIDS, MAX_OIDS);
cl_assert(min_len > 0);
/*
* Compare the first `min_char - 1` characters of each
* SHA1 OID. If the minimizer worked, we should find at
* least one collision
*/
found_collision = 0;
for (i = 0; i < MAX_OIDS; ++i) {
for (j = i + 1; j < MAX_OIDS; ++j) {
if (memcmp(oids[i], oids[j], min_len - 1) == 0)
found_collision = 1;
}
}
cl_assert_equal_b(true, found_collision);
/*
* Compare the first `min_char` characters of each
* SHA1 OID. If the minimizer worked, every single preffix
* should be unique.
*/
found_collision = 0;
for (i = 0; i < MAX_OIDS; ++i) {
for (j = i + 1; j < MAX_OIDS; ++j) {
if (memcmp(oids[i], oids[j], min_len) == 0)
found_collision = 1;
}
}
cl_assert_equal_b(false, found_collision);
/* cleanup */
free_oids(MAX_OIDS, oids);
git_oid_shorten_free(os);
#undef MAX_OIDS
}
void test_object_raw_short__oid_shortener_too_much_oids(void)
{
/* The magic number of oids at which an oid_shortener will fail.
* This was experimentally established. */
#define MAX_OIDS 24556
git_oid_shorten *os;
char **oids;
os = git_oid_shorten_new(0);
cl_assert(os != NULL);
cl_assert(insert_sequential_oids(&oids, os, MAX_OIDS, MAX_OIDS - 1) < 0);
free_oids(MAX_OIDS, oids);
git_oid_shorten_free(os);
#undef MAX_OIDS
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/chars.c
|
#include "clar_libgit2.h"
#include "odb.h"
void test_object_raw_chars__find_invalid_chars_in_oid(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
char in[] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0";
unsigned int i;
for (i = 0; i < 256; i++) {
in[38] = (char)i;
if (git__fromhex(i) >= 0) {
exp[19] = (unsigned char)(git__fromhex(i) << 4);
cl_git_pass(git_oid_fromstr(&out, in));
cl_assert(memcmp(out.id, exp, sizeof(out.id)) == 0);
} else {
cl_git_fail(git_oid_fromstr(&out, in));
}
}
}
void test_object_raw_chars__build_valid_oid_from_raw_bytes(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
git_oid_fromraw(&out, exp);
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/data.h
|
/*
* Raw data
*/
static unsigned char commit_data[] = {
0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38,
0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32,
0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33,
0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75,
0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55,
0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61,
0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38,
0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30,
0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d,
0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20,
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65,
0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
0x3e, 0x0a,
};
static unsigned char tree_data[] = {
0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f,
0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79,
0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b,
0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31,
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f,
0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86,
0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8,
0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31,
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77,
0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b,
0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd,
0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30,
0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72,
0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1,
0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a,
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
};
static unsigned char tag_data[] = {
0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33,
0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66,
0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66,
0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39,
0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32,
0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a,
0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20,
0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74,
0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20,
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20,
0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63,
0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65,
0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30,
0x2e, 0x30, 0x2e, 0x31, 0x0a,
};
/*
* Dummy data
*/
static unsigned char zero_data[] = {
0x00,
};
static unsigned char one_data[] = {
0x0a,
};
static unsigned char two_data[] = {
0x61, 0x0a,
};
static unsigned char some_data[] = {
0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68,
0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20,
0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20,
0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61,
0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74,
0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69,
0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72,
0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a,
0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e,
0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20,
0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66,
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c,
0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61,
0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73,
0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74,
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a,
0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64,
0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74,
0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65,
0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e,
0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65,
0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62,
0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65,
0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20,
0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68,
0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65,
0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c,
0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70,
0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e,
0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20,
0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69,
0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69,
0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62,
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74,
0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67,
0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a,
0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20,
0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75,
0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65,
0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69,
0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e,
0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a,
0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20,
0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65,
0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20,
0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72,
0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20,
0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79,
0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65,
0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63,
0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20,
0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c,
0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f,
0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d,
0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c,
0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73,
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f,
0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e,
0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65,
0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20,
0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62,
0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65,
0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e,
0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20,
0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73,
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64,
0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20,
0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61,
0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c,
0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65,
0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74,
0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48,
0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20,
0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59,
0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75,
0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74,
0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69,
0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61,
0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20,
0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41,
0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54,
0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54,
0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52,
0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49,
0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55,
0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20,
0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20,
0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47,
0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50,
0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69,
0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f,
0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64,
0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a,
0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f,
0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64,
0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65,
0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61,
0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66,
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67,
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68,
0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20,
0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65,
0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47,
0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f,
0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65,
0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74,
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20,
0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e,
0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c,
0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46,
0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a,
0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c,
0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31,
0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20,
0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f,
0x0a,
};
/*
* SHA1 Hashes
*/
static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1";
static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df";
static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05";
static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391";
static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc";
static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85";
static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe";
/*
* In-memory objects
*/
static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJECT_TREE
};
static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJECT_TAG
};
static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJECT_BLOB
};
static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJECT_BLOB
};
static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJECT_BLOB
};
static git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJECT_COMMIT
};
static git_rawobj some_obj = {
some_data,
sizeof(some_data),
GIT_OBJECT_BLOB
};
static git_rawobj junk_obj = {
NULL,
0,
GIT_OBJECT_INVALID
};
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/hash.c
|
#include "clar_libgit2.h"
#include "odb.h"
#include "hash.h"
#include "data.h"
static void hash_object_pass(git_oid *oid, git_rawobj *obj)
{
cl_git_pass(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static void hash_object_fail(git_oid *oid, git_rawobj *obj)
{
cl_git_fail(git_odb_hash(oid, obj->data, obj->len, obj->type));
}
static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511";
static char *hello_text = "hello world\n";
static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09";
static char *bye_text = "bye world\n";
void test_object_raw_hash__hash_by_blocks(void)
{
git_hash_ctx ctx;
git_oid id1, id2;
cl_git_pass(git_hash_ctx_init(&ctx));
/* should already be init'd */
cl_git_pass(git_hash_update(&ctx, hello_text, strlen(hello_text)));
cl_git_pass(git_hash_final(&id2, &ctx));
cl_git_pass(git_oid_fromstr(&id1, hello_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
/* reinit should permit reuse */
cl_git_pass(git_hash_init(&ctx));
cl_git_pass(git_hash_update(&ctx, bye_text, strlen(bye_text)));
cl_git_pass(git_hash_final(&id2, &ctx));
cl_git_pass(git_oid_fromstr(&id1, bye_id));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
git_hash_ctx_cleanup(&ctx);
}
void test_object_raw_hash__hash_buffer_in_single_call(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, hello_id));
git_hash_buf(&id2, hello_text, strlen(hello_text));
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_vector(void)
{
git_oid id1, id2;
git_buf_vec vec[2];
cl_git_pass(git_oid_fromstr(&id1, hello_id));
vec[0].data = hello_text;
vec[0].len = 4;
vec[1].data = hello_text+4;
vec[1].len = strlen(hello_text)-4;
git_hash_vec(&id2, vec, 2);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_junk_data(void)
{
git_oid id, id_zero;
cl_git_pass(git_oid_fromstr(&id_zero, zero_id));
/* invalid types: */
junk_obj.data = some_data;
hash_object_fail(&id, &junk_obj);
junk_obj.type = 0; /* EXT1 */
hash_object_fail(&id, &junk_obj);
junk_obj.type = 5; /* EXT2 */
hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJECT_OFS_DELTA;
hash_object_fail(&id, &junk_obj);
junk_obj.type = GIT_OBJECT_REF_DELTA;
hash_object_fail(&id, &junk_obj);
junk_obj.type = 42;
hash_object_fail(&id, &junk_obj);
/* data can be NULL only if len is zero: */
junk_obj.type = GIT_OBJECT_BLOB;
junk_obj.data = NULL;
hash_object_pass(&id, &junk_obj);
cl_assert(git_oid_cmp(&id, &id_zero) == 0);
junk_obj.len = 1;
hash_object_fail(&id, &junk_obj);
}
void test_object_raw_hash__hash_commit_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, commit_id));
hash_object_pass(&id2, &commit_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tree_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tree_id));
hash_object_pass(&id2, &tree_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_tag_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, tag_id));
hash_object_pass(&id2, &tag_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_zero_length_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, zero_id));
hash_object_pass(&id2, &zero_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_one_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, one_id));
hash_object_pass(&id2, &one_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_two_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, two_id));
hash_object_pass(&id2, &two_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
void test_object_raw_hash__hash_multi_byte_object(void)
{
git_oid id1, id2;
cl_git_pass(git_oid_fromstr(&id1, some_id));
hash_object_pass(&id2, &some_obj);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/size.c
|
#include "clar_libgit2.h"
#include "odb.h"
void test_object_raw_size__validate_oid_size(void)
{
git_oid out;
cl_assert(20 == GIT_OID_RAWSZ);
cl_assert(40 == GIT_OID_HEXSZ);
cl_assert(sizeof(out) == GIT_OID_RAWSZ);
cl_assert(sizeof(out.id) == GIT_OID_RAWSZ);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/compare.c
|
#include "clar_libgit2.h"
#include "odb.h"
void test_object_raw_compare__succeed_on_copy_oid(void)
{
git_oid a, b;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
memset(&b, 0, sizeof(b));
git_oid_fromraw(&a, exp);
git_oid_cpy(&b, &a);
cl_git_pass(memcmp(a.id, exp, sizeof(a.id)));
}
void test_object_raw_compare__succeed_on_oid_comparison_lesser(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
unsigned char b_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xf0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, b_in);
cl_assert(git_oid_cmp(&a, &b) < 0);
}
void test_object_raw_compare__succeed_on_oid_comparison_equal(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, a_in);
cl_assert(git_oid_cmp(&a, &b) == 0);
}
void test_object_raw_compare__succeed_on_oid_comparison_greater(void)
{
git_oid a, b;
unsigned char a_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
unsigned char b_in[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xd0,
};
git_oid_fromraw(&a, a_in);
git_oid_fromraw(&b, b_in);
cl_assert(git_oid_cmp(&a, &b) > 0);
}
void test_object_raw_compare__compare_fmt_oids(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
cl_git_pass(git_oid_fromstr(&in, exp));
/* Format doesn't touch the last byte */
out[GIT_OID_HEXSZ] = 'Z';
git_oid_fmt(out, &in);
cl_assert(out[GIT_OID_HEXSZ] == 'Z');
/* Format produced the right result */
out[GIT_OID_HEXSZ] = '\0';
cl_assert_equal_s(exp, out);
}
void test_object_raw_compare__compare_static_oids(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char *out;
cl_git_pass(git_oid_fromstr(&in, exp));
out = git_oid_tostr_s(&in);
cl_assert(out);
cl_assert_equal_s(exp, out);
}
void test_object_raw_compare__compare_pathfmt_oids(void)
{
const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0";
const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 2];
cl_git_pass(git_oid_fromstr(&in, exp1));
/* Format doesn't touch the last byte */
out[GIT_OID_HEXSZ + 1] = 'Z';
git_oid_pathfmt(out, &in);
cl_assert(out[GIT_OID_HEXSZ + 1] == 'Z');
/* Format produced the right result */
out[GIT_OID_HEXSZ + 1] = '\0';
cl_assert_equal_s(exp2, out);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/write.c
|
#include "clar_libgit2.h"
#include "git2/odb_backend.h"
#include "futils.h"
#include "odb.h"
typedef struct object_data {
char *id; /* object id (sha1) */
char *dir; /* object store (fan-out) directory name */
char *file; /* object store filename */
} object_data;
static const char *odb_dir = "test-objects";
void test_body(object_data *d, git_rawobj *o);
/* Helpers */
static void remove_object_files(object_data *d)
{
cl_git_pass(p_unlink(d->file));
cl_git_pass(p_rmdir(d->dir));
cl_assert(errno != ENOTEMPTY);
cl_git_pass(p_rmdir(odb_dir) < 0);
}
static void streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw)
{
git_odb_stream *stream;
int error;
cl_git_pass(git_odb_open_wstream(&stream, odb, raw->len, raw->type));
git_odb_stream_write(stream, raw->data, raw->len);
error = git_odb_stream_finalize_write(oid, stream);
git_odb_stream_free(stream);
cl_git_pass(error);
}
static void check_object_files(object_data *d)
{
cl_assert(git_path_exists(d->dir));
cl_assert(git_path_exists(d->file));
}
static void cmp_objects(git_rawobj *o1, git_rawobj *o2)
{
cl_assert(o1->type == o2->type);
cl_assert(o1->len == o2->len);
if (o1->len > 0)
cl_assert(memcmp(o1->data, o2->data, o1->len) == 0);
}
static void make_odb_dir(void)
{
cl_git_pass(p_mkdir(odb_dir, GIT_OBJECT_DIR_MODE));
}
/* Standard test form */
void test_body(object_data *d, git_rawobj *o)
{
git_odb *db;
git_oid id1, id2;
git_odb_object *obj;
git_rawobj tmp;
make_odb_dir();
cl_git_pass(git_odb_open(&db, odb_dir));
cl_git_pass(git_oid_fromstr(&id1, d->id));
streaming_write(&id2, db, o);
cl_assert(git_oid_cmp(&id1, &id2) == 0);
check_object_files(d);
cl_git_pass(git_odb_read(&obj, db, &id1));
tmp.data = obj->buffer;
tmp.len = obj->cached.size;
tmp.type = obj->cached.type;
cmp_objects(&tmp, o);
git_odb_object_free(obj);
git_odb_free(db);
remove_object_files(d);
}
void test_object_raw_write__loose_object(void)
{
object_data commit = {
"3d7f8a6af076c8c3f20071a8935cdbe8228594d1",
"test-objects/3d",
"test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1",
};
unsigned char commit_data[] = {
0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66,
0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35,
0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38,
0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32,
0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33,
0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75,
0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55,
0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61,
0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78,
0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f,
0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38,
0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30,
0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d,
0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20,
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65,
0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d,
0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68,
0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f,
0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f,
0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67,
0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72,
0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20,
0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70,
0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67,
0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f,
0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79,
0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69,
0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d,
0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20,
0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75,
0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61,
0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d,
0x3e, 0x0a,
};
git_rawobj commit_obj = {
commit_data,
sizeof(commit_data),
GIT_OBJECT_COMMIT
};
test_body(&commit, &commit_obj);
}
void test_object_raw_write__loose_tree(void)
{
static object_data tree = {
"dff2da90b254e1beb889d1f1f1288be1803782df",
"test-objects/df",
"test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df",
};
static unsigned char tree_data[] = {
0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f,
0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79,
0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b,
0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31,
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f,
0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86,
0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8,
0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31,
0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77,
0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b,
0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd,
0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30,
0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72,
0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1,
0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a,
0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91,
};
static git_rawobj tree_obj = {
tree_data,
sizeof(tree_data),
GIT_OBJECT_TREE
};
test_body(&tree, &tree_obj);
}
void test_object_raw_write__loose_tag(void)
{
static object_data tag = {
"09d373e1dfdc16b129ceec6dd649739911541e05",
"test-objects/09",
"test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05",
};
static unsigned char tag_data[] = {
0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33,
0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66,
0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66,
0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39,
0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32,
0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a,
0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d,
0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20,
0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74,
0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20,
0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72,
0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74,
0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d,
0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e,
0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34,
0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30,
0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20,
0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74,
0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63,
0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65,
0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30,
0x2e, 0x30, 0x2e, 0x31, 0x0a,
};
static git_rawobj tag_obj = {
tag_data,
sizeof(tag_data),
GIT_OBJECT_TAG
};
test_body(&tag, &tag_obj);
}
void test_object_raw_write__zero_length(void)
{
static object_data zero = {
"e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
"test-objects/e6",
"test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391",
};
static unsigned char zero_data[] = {
0x00 /* dummy data */
};
static git_rawobj zero_obj = {
zero_data,
0,
GIT_OBJECT_BLOB
};
test_body(&zero, &zero_obj);
}
void test_object_raw_write__one_byte(void)
{
static object_data one = {
"8b137891791fe96927ad78e64b0aad7bded08bdc",
"test-objects/8b",
"test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc",
};
static unsigned char one_data[] = {
0x0a,
};
static git_rawobj one_obj = {
one_data,
sizeof(one_data),
GIT_OBJECT_BLOB
};
test_body(&one, &one_obj);
}
void test_object_raw_write__two_byte(void)
{
static object_data two = {
"78981922613b2afb6025042ff6bd878ac1994e85",
"test-objects/78",
"test-objects/78/981922613b2afb6025042ff6bd878ac1994e85",
};
static unsigned char two_data[] = {
0x61, 0x0a,
};
static git_rawobj two_obj = {
two_data,
sizeof(two_data),
GIT_OBJECT_BLOB
};
test_body(&two, &two_obj);
}
void test_object_raw_write__several_bytes(void)
{
static object_data some = {
"fd8430bc864cfcd5f10e5590f8a447e01b942bfe",
"test-objects/fd",
"test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe",
};
static unsigned char some_data[] = {
0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68,
0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20,
0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20,
0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61,
0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74,
0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69,
0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72,
0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a,
0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e,
0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20,
0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66,
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c,
0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e,
0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61,
0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73,
0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74,
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a,
0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64,
0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74,
0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65,
0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e,
0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65,
0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e,
0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62,
0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65,
0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20,
0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68,
0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65,
0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c,
0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70,
0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f,
0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e,
0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f,
0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20,
0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f,
0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69,
0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69,
0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62,
0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74,
0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67,
0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a,
0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20,
0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75,
0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65,
0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61,
0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69,
0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e,
0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a,
0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20,
0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65,
0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20,
0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72,
0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20,
0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79,
0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65,
0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63,
0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20,
0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c,
0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f,
0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d,
0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74,
0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c,
0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73,
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f,
0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e,
0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65,
0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20,
0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62,
0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65,
0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e,
0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20,
0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c,
0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73,
0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64,
0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20,
0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61,
0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c,
0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65,
0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74,
0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48,
0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20,
0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59,
0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75,
0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74,
0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69,
0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61,
0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20,
0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41,
0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54,
0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54,
0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52,
0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49,
0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55,
0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20,
0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20,
0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47,
0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50,
0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69,
0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f,
0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64,
0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a,
0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f,
0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64,
0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65,
0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61,
0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66,
0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55,
0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c,
0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20,
0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a,
0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67,
0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68,
0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72,
0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20,
0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65,
0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47,
0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f,
0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65,
0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74,
0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20,
0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65,
0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74,
0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20,
0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e,
0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c,
0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46,
0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a,
0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c,
0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31,
0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20,
0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f,
0x0a,
};
static git_rawobj some_obj = {
some_data,
sizeof(some_data),
GIT_OBJECT_BLOB
};
test_body(&some, &some_obj);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/fromstr.c
|
#include "clar_libgit2.h"
#include "odb.h"
void test_object_raw_fromstr__fail_on_invalid_oid_string(void)
{
git_oid out;
cl_git_fail(git_oid_fromstr(&out, ""));
cl_git_fail(git_oid_fromstr(&out, "moo"));
cl_git_fail(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez"));
}
void test_object_raw_fromstr__succeed_on_valid_oid_string(void)
{
git_oid out;
unsigned char exp[] = {
0x16, 0xa6, 0x77, 0x70, 0xb7,
0xd8, 0xd7, 0x23, 0x17, 0xc4,
0xb7, 0x75, 0x21, 0x3c, 0x23,
0xa8, 0xbd, 0x74, 0xf5, 0xe0,
};
cl_git_pass(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0"));
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
cl_git_pass(git_oid_fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0"));
cl_git_pass(memcmp(out.id, exp, sizeof(out.id)));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/convert.c
|
#include "clar_libgit2.h"
#include "odb.h"
void test_object_raw_convert__succeed_on_oid_to_string_conversion(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char out[GIT_OID_HEXSZ + 1];
char *str;
int i;
cl_git_pass(git_oid_fromstr(&in, exp));
/* NULL buffer pointer, returns static empty string */
str = git_oid_tostr(NULL, sizeof(out), &in);
cl_assert(str && *str == '\0' && str != out);
/* zero buffer size, returns static empty string */
str = git_oid_tostr(out, 0, &in);
cl_assert(str && *str == '\0' && str != out);
/* NULL oid pointer, sets existing buffer to empty string */
str = git_oid_tostr(out, sizeof(out), NULL);
cl_assert(str && *str == '\0' && str == out);
/* n == 1, returns out as an empty string */
str = git_oid_tostr(out, 1, &in);
cl_assert(str && *str == '\0' && str == out);
for (i = 1; i < GIT_OID_HEXSZ; i++) {
out[i+1] = 'Z';
str = git_oid_tostr(out, i+1, &in);
/* returns out containing c-string */
cl_assert(str && str == out);
/* must be '\0' terminated */
cl_assert(*(str+i) == '\0');
/* must not touch bytes past end of string */
cl_assert(*(str+(i+1)) == 'Z');
/* i == n-1 charaters of string */
cl_git_pass(strncmp(exp, out, i));
}
/* returns out as hex formatted c-string */
str = git_oid_tostr(out, sizeof(out), &in);
cl_assert(str && str == out && *(str+GIT_OID_HEXSZ) == '\0');
cl_assert_equal_s(exp, out);
}
void test_object_raw_convert__succeed_on_oid_to_string_conversion_big(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
char *str;
cl_git_pass(git_oid_fromstr(&in, exp));
/* place some tail material */
big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */
big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */
big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */
big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */
/* returns big as hex formatted c-string */
str = git_oid_tostr(big, sizeof(big), &in);
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ) == '\0');
cl_assert_equal_s(exp, big);
/* check tail material is untouched */
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X');
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y');
cl_assert(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z');
}
static void check_partial_oid(
char *buffer, size_t count, const git_oid *oid, const char *expected)
{
git_oid_nfmt(buffer, count, oid);
buffer[count] = '\0';
cl_assert_equal_s(expected, buffer);
}
void test_object_raw_convert__convert_oid_partially(void)
{
const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0";
git_oid in;
char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */
cl_git_pass(git_oid_fromstr(&in, exp));
git_oid_nfmt(big, sizeof(big), &in);
cl_assert_equal_s(exp, big);
git_oid_nfmt(big, GIT_OID_HEXSZ + 1, &in);
cl_assert_equal_s(exp, big);
check_partial_oid(big, 1, &in, "1");
check_partial_oid(big, 2, &in, "16");
check_partial_oid(big, 3, &in, "16a");
check_partial_oid(big, 4, &in, "16a0");
check_partial_oid(big, 5, &in, "16a01");
check_partial_oid(big, GIT_OID_HEXSZ, &in, exp);
check_partial_oid(
big, GIT_OID_HEXSZ - 1, &in, "16a0123456789abcdef4b775213c23a8bd74f5e");
check_partial_oid(
big, GIT_OID_HEXSZ - 2, &in, "16a0123456789abcdef4b775213c23a8bd74f5");
check_partial_oid(
big, GIT_OID_HEXSZ - 3, &in, "16a0123456789abcdef4b775213c23a8bd74f");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/raw/type2string.c
|
#include "clar_libgit2.h"
#include "odb.h"
#include "hash.h"
void test_object_raw_type2string__convert_type_to_string(void)
{
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_INVALID), "");
cl_assert_equal_s(git_object_type2string(0), ""); /* EXT1 */
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_COMMIT), "commit");
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_TREE), "tree");
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_BLOB), "blob");
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_TAG), "tag");
cl_assert_equal_s(git_object_type2string(5), ""); /* EXT2 */
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_OFS_DELTA), "OFS_DELTA");
cl_assert_equal_s(git_object_type2string(GIT_OBJECT_REF_DELTA), "REF_DELTA");
cl_assert_equal_s(git_object_type2string(-2), "");
cl_assert_equal_s(git_object_type2string(8), "");
cl_assert_equal_s(git_object_type2string(1234), "");
}
void test_object_raw_type2string__convert_string_to_type(void)
{
cl_assert(git_object_string2type(NULL) == GIT_OBJECT_INVALID);
cl_assert(git_object_string2type("") == GIT_OBJECT_INVALID);
cl_assert(git_object_string2type("commit") == GIT_OBJECT_COMMIT);
cl_assert(git_object_string2type("tree") == GIT_OBJECT_TREE);
cl_assert(git_object_string2type("blob") == GIT_OBJECT_BLOB);
cl_assert(git_object_string2type("tag") == GIT_OBJECT_TAG);
cl_assert(git_object_string2type("OFS_DELTA") == GIT_OBJECT_OFS_DELTA);
cl_assert(git_object_string2type("REF_DELTA") == GIT_OBJECT_REF_DELTA);
cl_assert(git_object_string2type("CoMmIt") == GIT_OBJECT_INVALID);
cl_assert(git_object_string2type("hohoho") == GIT_OBJECT_INVALID);
}
void test_object_raw_type2string__check_type_is_loose(void)
{
cl_assert(git_object_typeisloose(GIT_OBJECT_INVALID) == 0);
cl_assert(git_object_typeisloose(0) == 0); /* EXT1 */
cl_assert(git_object_typeisloose(GIT_OBJECT_COMMIT) == 1);
cl_assert(git_object_typeisloose(GIT_OBJECT_TREE) == 1);
cl_assert(git_object_typeisloose(GIT_OBJECT_BLOB) == 1);
cl_assert(git_object_typeisloose(GIT_OBJECT_TAG) == 1);
cl_assert(git_object_typeisloose(5) == 0); /* EXT2 */
cl_assert(git_object_typeisloose(GIT_OBJECT_OFS_DELTA) == 0);
cl_assert(git_object_typeisloose(GIT_OBJECT_REF_DELTA) == 0);
cl_assert(git_object_typeisloose(-2) == 0);
cl_assert(git_object_typeisloose(8) == 0);
cl_assert(git_object_typeisloose(1234) == 0);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tag/read.c
|
#include "clar_libgit2.h"
#include "tag.h"
static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1";
static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
static const char *bad_tag_id = "eda9f45a2a98d4c17a09d681d88569fa4ea91755";
static const char *badly_tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
static const char *short_tag_id = "5da7760512a953e3c7c4e47e4392c7a4338fb729";
static const char *short_tagged_commit = "4a5ed60bafcf4638b7c8356bd4ce1916bfede93c";
static const char *taggerless = "4a23e2e65ad4e31c4c9db7dc746650bfad082679";
static git_repository *g_repo;
/* Fixture setup and teardown */
void test_object_tag_read__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tag_read__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tag_read__parse(void)
{
/* read and parse a tag from the repository */
git_tag *tag1, *tag2;
git_commit *commit;
git_oid id1, id2, id_commit;
git_oid_fromstr(&id1, tag1_id);
git_oid_fromstr(&id2, tag2_id);
git_oid_fromstr(&id_commit, tagged_commit);
cl_git_pass(git_tag_lookup(&tag1, g_repo, &id1));
cl_assert_equal_s(git_tag_name(tag1), "test");
cl_assert(git_tag_target_type(tag1) == GIT_OBJECT_TAG);
cl_git_pass(git_tag_target((git_object **)&tag2, tag1));
cl_assert(tag2 != NULL);
cl_assert(git_oid_cmp(&id2, git_tag_id(tag2)) == 0);
cl_git_pass(git_tag_target((git_object **)&commit, tag2));
cl_assert(commit != NULL);
cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
git_tag_free(tag1);
git_tag_free(tag2);
git_commit_free(commit);
}
void test_object_tag_read__parse_without_tagger(void)
{
/* read and parse a tag without a tagger field */
git_repository *bad_tag_repo;
git_tag *bad_tag;
git_commit *commit;
git_oid id, id_commit;
/* TODO: This is a little messy */
cl_git_pass(git_repository_open(&bad_tag_repo, cl_fixture("bad_tag.git")));
git_oid_fromstr(&id, bad_tag_id);
git_oid_fromstr(&id_commit, badly_tagged_commit);
cl_git_pass(git_tag_lookup(&bad_tag, bad_tag_repo, &id));
cl_assert(bad_tag != NULL);
cl_assert_equal_s(git_tag_name(bad_tag), "e90810b");
cl_assert(git_oid_cmp(&id, git_tag_id(bad_tag)) == 0);
cl_assert(bad_tag->tagger == NULL);
cl_git_pass(git_tag_target((git_object **)&commit, bad_tag));
cl_assert(commit != NULL);
cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
git_tag_free(bad_tag);
git_commit_free(commit);
git_repository_free(bad_tag_repo);
}
void test_object_tag_read__parse_without_message(void)
{
/* read and parse a tag without a message field */
git_repository *short_tag_repo;
git_tag *short_tag;
git_commit *commit;
git_oid id, id_commit;
/* TODO: This is a little messy */
cl_git_pass(git_repository_open(&short_tag_repo, cl_fixture("short_tag.git")));
git_oid_fromstr(&id, short_tag_id);
git_oid_fromstr(&id_commit, short_tagged_commit);
cl_git_pass(git_tag_lookup(&short_tag, short_tag_repo, &id));
cl_assert(short_tag != NULL);
cl_assert_equal_s(git_tag_name(short_tag), "no_description");
cl_assert(git_oid_cmp(&id, git_tag_id(short_tag)) == 0);
cl_assert(short_tag->message == NULL);
cl_git_pass(git_tag_target((git_object **)&commit, short_tag));
cl_assert(commit != NULL);
cl_assert(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0);
git_tag_free(short_tag);
git_commit_free(commit);
git_repository_free(short_tag_repo);
}
void test_object_tag_read__without_tagger_nor_message(void)
{
git_tag *tag;
git_oid id;
git_repository *repo;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_oid_fromstr(&id, taggerless));
cl_git_pass(git_tag_lookup(&tag, repo, &id));
cl_assert_equal_s(git_tag_name(tag), "taggerless");
cl_assert(git_tag_target_type(tag) == GIT_OBJECT_COMMIT);
cl_assert(tag->message == NULL);
cl_assert(tag->tagger == NULL);
git_tag_free(tag);
git_repository_free(repo);
}
static const char *silly_tag = "object c054ccaefbf2da31c3b19178f9e3ef20a3867924\n\
type commit\n\
tag v1_0_1\n\
tagger Jamis Buck <[email protected]> 1107717917\n\
diff --git a/lib/sqlite3/version.rb b/lib/sqlite3/version.rb\n\
index 0b3bf69..4ee8fc2 100644\n\
--- a/lib/sqlite3/version.rb\n\
+++ b/lib/sqlite3/version.rb\n\
@@ -36,7 +36,7 @@ module SQLite3\n\
\n\
MAJOR = 1\n\
MINOR = 0\n\
- TINY = 0\n\
+ TINY = 1\n\
\n\
STRING = [ MAJOR, MINOR, TINY ].join( \".\" )\n\
\n\
-0600\n\
\n\
v1_0_1 release\n";
void test_object_tag_read__extra_header_fields(void)
{
git_tag *tag;
git_odb *odb;
git_oid id;
cl_git_pass(git_repository_odb__weakptr(&odb, g_repo));
cl_git_pass(git_odb_write(&id, odb, silly_tag, strlen(silly_tag), GIT_OBJECT_TAG));
cl_git_pass(git_tag_lookup(&tag, g_repo, &id));
cl_assert_equal_s("v1_0_1 release\n", git_tag_message(tag));
git_tag_free(tag);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tag/peel.c
|
#include "clar_libgit2.h"
#include "tag.h"
static git_repository *repo;
static git_tag *tag;
static git_object *target;
void test_object_tag_peel__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
}
void test_object_tag_peel__cleanup(void)
{
git_tag_free(tag);
tag = NULL;
git_object_free(target);
target = NULL;
git_repository_free(repo);
repo = NULL;
cl_fixture_cleanup("testrepo.git");
}
static void retrieve_tag_from_oid(git_tag **tag_out, git_repository *repo, const char *sha)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, sha));
cl_git_pass(git_tag_lookup(tag_out, repo, &oid));
}
void test_object_tag_peel__can_peel_to_a_commit(void)
{
retrieve_tag_from_oid(&tag, repo, "7b4384978d2493e851f9cca7858815fac9b10980");
cl_git_pass(git_tag_peel(&target, tag));
cl_assert(git_object_type(target) == GIT_OBJECT_COMMIT);
cl_git_pass(git_oid_streq(git_object_id(target), "e90810b8df3e80c413d903f631643c716887138d"));
}
void test_object_tag_peel__can_peel_several_nested_tags_to_a_commit(void)
{
retrieve_tag_from_oid(&tag, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
cl_git_pass(git_tag_peel(&target, tag));
cl_assert(git_object_type(target) == GIT_OBJECT_COMMIT);
cl_git_pass(git_oid_streq(git_object_id(target), "e90810b8df3e80c413d903f631643c716887138d"));
}
void test_object_tag_peel__can_peel_to_a_non_commit(void)
{
retrieve_tag_from_oid(&tag, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
cl_git_pass(git_tag_peel(&target, tag));
cl_assert(git_object_type(target) == GIT_OBJECT_BLOB);
cl_git_pass(git_oid_streq(git_object_id(target), "1385f264afb75a56a5bec74243be9b367ba4ca08"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tag/write.c
|
#include "clar_libgit2.h"
static const char* tagger_name = "Vicent Marti";
static const char* tagger_email = "[email protected]";
static const char* tagger_message = "This is my tag.\n\nThere are many tags, but this one is mine\n";
static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980";
static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d";
static git_repository *g_repo;
/* Fixture setup and teardown */
void test_object_tag_write__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tag_write__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tag_write__basic(void)
{
/* write a tag to the repository and read it again */
git_tag *tag;
git_oid target_id, tag_id;
git_signature *tagger;
const git_signature *tagger1;
git_reference *ref_tag;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
/* create signature */
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
cl_git_pass(
git_tag_create(&tag_id, g_repo,
"the-tag", target, tagger, tagger_message, 0)
);
git_object_free(target);
git_signature_free(tagger);
cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
cl_assert(git_oid_cmp(git_tag_target_id(tag), &target_id) == 0);
/* Check attributes were set correctly */
tagger1 = git_tag_tagger(tag);
cl_assert(tagger1 != NULL);
cl_assert_equal_s(tagger1->name, tagger_name);
cl_assert_equal_s(tagger1->email, tagger_email);
cl_assert(tagger1->when.time == 123456789);
cl_assert(tagger1->when.offset == 60);
cl_assert_equal_s(git_tag_message(tag), tagger_message);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag"));
cl_assert(git_oid_cmp(git_reference_target(ref_tag), &tag_id) == 0);
cl_git_pass(git_reference_delete(ref_tag));
git_reference_free(ref_tag);
git_tag_free(tag);
}
void test_object_tag_write__overwrite(void)
{
/* Attempt to write a tag bearing the same name than an already existing tag */
git_oid target_id, tag_id;
git_signature *tagger;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
/* create signature */
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
cl_assert_equal_i(GIT_EEXISTS, git_tag_create(
&tag_id, /* out id */
g_repo,
"e90810b",
target,
tagger,
tagger_message,
0));
git_object_free(target);
git_signature_free(tagger);
}
void test_object_tag_write__replace(void)
{
/* Replace an already existing tag */
git_oid target_id, tag_id, old_tag_id;
git_signature *tagger;
git_reference *ref_tag;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
git_oid_cpy(&old_tag_id, git_reference_target(ref_tag));
git_reference_free(ref_tag);
/* create signature */
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
cl_git_pass(git_tag_create(
&tag_id, /* out id */
g_repo,
"e90810b",
target,
tagger,
tagger_message,
1));
git_object_free(target);
git_signature_free(tagger);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
cl_assert(git_oid_cmp(git_reference_target(ref_tag), &tag_id) == 0);
cl_assert(git_oid_cmp(git_reference_target(ref_tag), &old_tag_id) != 0);
git_reference_free(ref_tag);
}
void test_object_tag_write__lightweight(void)
{
/* write a lightweight tag to the repository and read it again */
git_oid target_id, object_id;
git_reference *ref_tag;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_tag_create_lightweight(
&object_id,
g_repo,
"light-tag",
target,
0));
git_object_free(target);
cl_assert(git_oid_cmp(&object_id, &target_id) == 0);
cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/light-tag"));
cl_assert(git_oid_cmp(git_reference_target(ref_tag), &target_id) == 0);
cl_git_pass(git_tag_delete(g_repo, "light-tag"));
git_reference_free(ref_tag);
}
void test_object_tag_write__lightweight_over_existing(void)
{
/* Attempt to write a lightweight tag bearing the same name than an already existing tag */
git_oid target_id, object_id, existing_object_id;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
cl_assert_equal_i(GIT_EEXISTS, git_tag_create_lightweight(
&object_id,
g_repo,
"e90810b",
target,
0));
git_oid_fromstr(&existing_object_id, tag2_id);
cl_assert(git_oid_cmp(&object_id, &existing_object_id) == 0);
git_object_free(target);
}
void test_object_tag_write__delete(void)
{
/* Delete an already existing tag */
git_reference *ref_tag;
cl_git_pass(git_tag_delete(g_repo, "e90810b"));
cl_git_fail(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b"));
git_reference_free(ref_tag);
}
void test_object_tag_write__creating_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
git_oid target_id, tag_id;
git_signature *tagger;
git_object *target;
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_tag_create(&tag_id, g_repo,
"Inv@{id", target, tagger, tagger_message, 0)
);
cl_assert_equal_i(GIT_EINVALIDSPEC,
git_tag_create_lightweight(&tag_id, g_repo,
"Inv@{id", target, 0)
);
git_object_free(target);
git_signature_free(tagger);
}
void test_object_tag_write__deleting_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
cl_assert_equal_i(GIT_EINVALIDSPEC, git_tag_delete(g_repo, "Inv@{id"));
}
void create_annotation(git_oid *tag_id, const char *name)
{
git_object *target;
git_oid target_id;
git_signature *tagger;
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
git_oid_fromstr(&target_id, tagged_commit);
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJECT_COMMIT));
cl_git_pass(git_tag_annotation_create(tag_id, g_repo, name, target, tagger, "boom!"));
git_object_free(target);
git_signature_free(tagger);
}
void test_object_tag_write__creating_an_annotation_stores_the_new_object_in_the_odb(void)
{
git_oid tag_id;
git_tag *tag;
create_annotation(&tag_id, "new_tag");
cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id));
cl_assert_equal_s("new_tag", git_tag_name(tag));
git_tag_free(tag);
}
void test_object_tag_write__creating_an_annotation_does_not_create_a_reference(void)
{
git_oid tag_id;
git_reference *tag_ref;
create_annotation(&tag_id, "new_tag");
cl_git_fail_with(git_reference_lookup(&tag_ref, g_repo, "refs/tags/new_tag"), GIT_ENOTFOUND);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tag/parse.c
|
#include "clar_libgit2.h"
#include "object.h"
#include "signature.h"
#include "tag.h"
static void assert_tag_parses(const char *data, size_t datalen,
const char *expected_oid,
const char *expected_name,
const char *expected_tagger,
const char *expected_message)
{
git_tag *tag;
if (!datalen)
datalen = strlen(data);
cl_git_pass(git_object__from_raw((git_object **) &tag, data, datalen, GIT_OBJECT_TAG));
cl_assert_equal_i(tag->type, GIT_OBJECT_TAG);
if (expected_oid) {
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected_oid));
cl_assert_equal_oid(&oid, &tag->target);
}
if (expected_name)
cl_assert_equal_s(expected_name, tag->tag_name);
else
cl_assert_equal_s(tag->message, NULL);
if (expected_tagger) {
git_signature *tagger;
cl_git_pass(git_signature_from_buffer(&tagger, expected_tagger));
cl_assert_equal_s(tagger->name, tag->tagger->name);
cl_assert_equal_s(tagger->email, tag->tagger->email);
cl_assert_equal_i(tagger->when.time, tag->tagger->when.time);
cl_assert_equal_i(tagger->when.offset, tag->tagger->when.offset);
cl_assert_equal_i(tagger->when.sign, tag->tagger->when.sign);
git_signature_free(tagger);
} else {
cl_assert_equal_s(tag->tagger, NULL);
}
if (expected_message)
cl_assert_equal_s(expected_message, tag->message);
else
cl_assert_equal_s(tag->message, NULL);
git_object__free(&tag->object);
}
static void assert_tag_fails(const char *data, size_t datalen)
{
git_object *object;
if (!datalen)
datalen = strlen(data);
cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TAG));
}
void test_object_tag_parse__valid_tag_parses(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_parses(tag, 0,
"a8d447f68076d1520f69649bb52629941be7031f",
"tagname",
"Taggy Mr. Taggart <[email protected]>",
"Message");
}
void test_object_tag_parse__missing_tagger_parses(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag tagname\n"
"\n"
"Message";
assert_tag_parses(tag, 0,
"a8d447f68076d1520f69649bb52629941be7031f",
"tagname",
NULL,
"Message");
}
void test_object_tag_parse__missing_message_parses(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n";
assert_tag_parses(tag, 0,
"a8d447f68076d1520f69649bb52629941be7031f",
"tagname",
"Taggy Mr. Taggart <[email protected]>",
NULL);
}
void test_object_tag_parse__unknown_field_parses(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"foo bar\n"
"frubble frabble\n"
"\n"
"Message";
assert_tag_parses(tag, 0,
"a8d447f68076d1520f69649bb52629941be7031f",
"tagname",
"Taggy Mr. Taggart <[email protected]>",
"Message");
}
void test_object_tag_parse__missing_object_fails(void)
{
const char *tag =
"type tag\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__malformatted_object_fails(void)
{
const char *tag =
"object a8d447f68076d15xxxxxxxxxxxxxxxx41be7031f\n"
"type tag\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__missing_type_fails(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__invalid_type_fails(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type garbage\n"
"tag tagname\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__missing_tagname_fails(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tagger Taggy Mr. Taggart <[email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__misformatted_tagger_fails(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag Tag\n"
"tagger [email protected]>\n"
"\n"
"Message";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__missing_message_fails(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag Tag\n"
"tagger [email protected]>\n";
assert_tag_fails(tag, 0);
}
void test_object_tag_parse__no_oob_read_when_searching_message(void)
{
const char *tag =
"object a8d447f68076d1520f69649bb52629941be7031f\n"
"type tag\n"
"tag \n"
"tagger <>\n"
" \n\n"
"Message";
/*
* The OOB read previously resulted in an OOM error. We
* thus want to make sure that the resulting error is the
* expected one.
*/
assert_tag_fails(tag, strlen(tag) - strlen("\n\nMessage"));
cl_assert(strstr(git_error_last()->message, "tag contains no message"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tag/list.c
|
#include "clar_libgit2.h"
#include "tag.h"
static git_repository *g_repo;
#define MAX_USED_TAGS 6
struct pattern_match_t
{
const char* pattern;
const size_t expected_matches;
const char* expected_results[MAX_USED_TAGS];
};
/* Helpers */
static void ensure_tag_pattern_match(git_repository *repo,
const struct pattern_match_t* data)
{
int already_found[MAX_USED_TAGS] = { 0 };
git_strarray tag_list;
int error = 0;
size_t successfully_found = 0;
size_t i, j;
cl_assert(data->expected_matches <= MAX_USED_TAGS);
if ((error = git_tag_list_match(&tag_list, data->pattern, repo)) < 0)
goto exit;
if (tag_list.count != data->expected_matches)
{
error = GIT_ERROR;
goto exit;
}
/* we have to be prepared that tags come in any order. */
for (i = 0; i < tag_list.count; i++)
{
for (j = 0; j < data->expected_matches; j++)
{
if (!already_found[j] && !strcmp(data->expected_results[j], tag_list.strings[i]))
{
already_found[j] = 1;
successfully_found++;
break;
}
}
}
cl_assert_equal_i((int)successfully_found, (int)data->expected_matches);
exit:
git_strarray_dispose(&tag_list);
cl_git_pass(error);
}
/* Fixture setup and teardown */
void test_object_tag_list__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tag_list__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tag_list__list_all(void)
{
/* list all tag names from the repository */
git_strarray tag_list;
cl_git_pass(git_tag_list(&tag_list, g_repo));
cl_assert_equal_i((int)tag_list.count, 6);
git_strarray_dispose(&tag_list);
}
static const struct pattern_match_t matches[] = {
/* All tags, including a packed one and two namespaced ones. */
{ "", 6, { "e90810b", "point_to_blob", "test", "packed-tag", "foo/bar", "foo/foo/bar" } },
/* beginning with */
{ "t*", 1, { "test" } },
/* ending with */
{ "*b", 2, { "e90810b", "point_to_blob" } },
/* exact match */
{ "e", 0 },
{ "e90810b", 1, { "e90810b" } },
/* either or */
{ "e90810[ab]", 1, { "e90810b" } },
/* glob in the middle */
{ "foo/*/bar", 1, { "foo/foo/bar" } },
/*
* The matching of '*' is based on plain string matching analog to the regular expression ".*"
* => a '/' in the tag name has no special meaning.
* Compare to `git tag -l "*bar"`
*/
{ "*bar", 2, { "foo/bar", "foo/foo/bar" } },
/* End of list */
{ NULL }
};
void test_object_tag_list__list_by_pattern(void)
{
/* list all tag names from the repository matching a specified pattern */
size_t i = 0;
while (matches[i].pattern)
ensure_tag_pattern_match(g_repo, &matches[i++]);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/commit/commitstagedfile.c
|
#include "clar_libgit2.h"
#include "posix.h"
static git_repository *repo;
void test_object_commit_commitstagedfile__initialize(void)
{
cl_fixture("treebuilder");
cl_git_pass(git_repository_init(&repo, "treebuilder/", 0));
cl_assert(repo != NULL);
}
void test_object_commit_commitstagedfile__cleanup(void)
{
git_repository_free(repo);
repo = NULL;
cl_fixture_cleanup("treebuilder");
}
void test_object_commit_commitstagedfile__generate_predictable_object_ids(void)
{
git_index *index;
const git_index_entry *entry;
git_oid expected_blob_oid, tree_oid, expected_tree_oid, commit_oid, expected_commit_oid;
git_signature *signature;
git_tree *tree;
git_buf buffer;
/*
* The test below replicates the following git scenario
*
* $ echo "test" > test.txt
* $ git hash-object test.txt
* 9daeafb9864cf43055ae93beb0afd6c7d144bfa4
*
* $ git add .
* $ git commit -m "Initial commit"
*
* $ git log
* commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d
* Author: nulltoken <[email protected]>
* Date: Wed Dec 14 08:29:03 2011 +0100
*
* Initial commit
*
* $ git show 1fe3 --format=raw
* commit 1fe3126578fc4eca68c193e4a3a0a14a0704624d
* tree 2b297e643c551e76cfa1f93810c50811382f9117
* author nulltoken <[email protected]> 1323847743 +0100
* committer nulltoken <[email protected]> 1323847743 +0100
*
* Initial commit
*
* diff --git a/test.txt b/test.txt
* new file mode 100644
* index 0000000..9daeafb
* --- /dev/null
* +++ b/test.txt
* @@ -0,0 +1 @@
* +test
*
* $ git ls-tree 2b297
* 100644 blob 9daeafb9864cf43055ae93beb0afd6c7d144bfa4 test.txt
*/
cl_git_pass(git_oid_fromstr(&expected_commit_oid, "1fe3126578fc4eca68c193e4a3a0a14a0704624d"));
cl_git_pass(git_oid_fromstr(&expected_tree_oid, "2b297e643c551e76cfa1f93810c50811382f9117"));
cl_git_pass(git_oid_fromstr(&expected_blob_oid, "9daeafb9864cf43055ae93beb0afd6c7d144bfa4"));
/*
* Add a new file to the index
*/
cl_git_mkfile("treebuilder/test.txt", "test\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "test.txt"));
entry = git_index_get_byindex(index, 0);
cl_assert(git_oid_cmp(&expected_blob_oid, &entry->id) == 0);
/*
* Information about index entry should match test file
*/
{
struct stat st;
cl_must_pass(p_lstat("treebuilder/test.txt", &st));
cl_assert(entry->file_size == st.st_size);
#ifndef _WIN32
/*
* Windows doesn't populate these fields, and the signage is
* wrong in the Windows version of the struct, so lets avoid
* the "comparing signed and unsigned" compilation warning in
* that case.
*/
cl_assert(entry->uid == st.st_uid);
cl_assert(entry->gid == st.st_gid);
#endif
}
/*
* Build the tree from the index
*/
cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_assert(git_oid_cmp(&expected_tree_oid, &tree_oid) == 0);
/*
* Commit the staged file
*/
cl_git_pass(git_signature_new(&signature, "nulltoken", "[email protected]", 1323847743, 60));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
memset(&buffer, 0, sizeof(git_buf));
cl_git_pass(git_message_prettify(&buffer, "Initial commit", 0, '#'));
cl_git_pass(git_commit_create_v(
&commit_oid,
repo,
"HEAD",
signature,
signature,
NULL,
buffer.ptr,
tree,
0));
cl_assert(git_oid_cmp(&expected_commit_oid, &commit_oid) == 0);
git_buf_dispose(&buffer);
git_signature_free(signature);
git_tree_free(tree);
git_index_free(index);
}
static void assert_commit_tree_has_n_entries(git_commit *c, int count)
{
git_tree *tree;
cl_git_pass(git_commit_tree(&tree, c));
cl_assert_equal_i(count, git_tree_entrycount(tree));
git_tree_free(tree);
}
static void assert_commit_is_head_(git_commit *c, const char *file, const char *func, int line)
{
git_commit *head;
cl_git_pass(git_revparse_single((git_object **)&head, repo, "HEAD"));
clar__assert(git_oid_equal(git_commit_id(c), git_commit_id(head)), file, func, line, "Commit is not the HEAD", NULL, 1);
git_commit_free(head);
}
#define assert_commit_is_head(C) assert_commit_is_head_((C),__FILE__,__func__,__LINE__)
void test_object_commit_commitstagedfile__amend_commit(void)
{
git_index *index;
git_oid old_oid, new_oid, tree_oid;
git_commit *old_commit, *new_commit;
git_tree *tree;
/* make a commit */
cl_git_mkfile("treebuilder/myfile", "This is a file\n");
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_add_bypath(index, "myfile"));
cl_repo_commit_from_index(&old_oid, repo, NULL, 0, "first commit");
cl_git_pass(git_commit_lookup(&old_commit, repo, &old_oid));
cl_assert_equal_i(0, git_commit_parentcount(old_commit));
assert_commit_tree_has_n_entries(old_commit, 1);
assert_commit_is_head(old_commit);
/* let's amend the message of the HEAD commit */
cl_git_pass(git_commit_amend(
&new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", NULL));
/* fail because the commit isn't the tip of the branch anymore */
cl_git_fail(git_commit_amend(
&new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", NULL));
cl_git_pass(git_commit_lookup(&new_commit, repo, &new_oid));
cl_assert_equal_i(0, git_commit_parentcount(new_commit));
assert_commit_tree_has_n_entries(new_commit, 1);
assert_commit_is_head(new_commit);
git_commit_free(old_commit);
old_commit = new_commit;
/* let's amend the tree of that last commit */
cl_git_mkfile("treebuilder/anotherfile", "This is another file\n");
cl_git_pass(git_index_add_bypath(index, "anotherfile"));
cl_git_pass(git_index_write_tree(&tree_oid, index));
cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid));
cl_assert_equal_i(2, git_tree_entrycount(tree));
/* fail to amend on a ref which does not exist */
cl_git_fail_with(GIT_ENOTFOUND, git_commit_amend(
&new_oid, old_commit, "refs/heads/nope", NULL, NULL, NULL, "Initial commit", tree));
cl_git_pass(git_commit_amend(
&new_oid, old_commit, "HEAD", NULL, NULL, NULL, "Initial commit", tree));
git_tree_free(tree);
cl_git_pass(git_commit_lookup(&new_commit, repo, &new_oid));
cl_assert_equal_i(0, git_commit_parentcount(new_commit));
assert_commit_tree_has_n_entries(new_commit, 2);
assert_commit_is_head(new_commit);
/* cleanup */
git_commit_free(old_commit);
git_commit_free(new_commit);
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/commit/parse.c
|
#include "clar_libgit2.h"
#include "commit.h"
#include "object.h"
#include "signature.h"
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);
}
static void assert_commit_fails(const char *data, size_t datalen)
{
git_object *object;
if (!datalen)
datalen = strlen(data);
cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_COMMIT));
}
void test_object_commit_parse__parsing_commit_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n"
"encoding Encoding\n"
"\n"
"Message";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author <[email protected]>",
"Committer <[email protected]>",
"Encoding",
"Message", 0);
}
void test_object_commit_parse__parsing_commit_without_encoding_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n"
"\n"
"Message";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author <[email protected]>",
"Committer <[email protected]>",
NULL,
"Message", 0);
}
void test_object_commit_parse__parsing_commit_with_multiple_authors_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author1 <[email protected]>\n"
"author Author2 <[email protected]>\n"
"author Author3 <[email protected]>\n"
"author Author4 <[email protected]>\n"
"committer Committer <[email protected]>\n"
"\n"
"Message";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author1 <[email protected]>",
"Committer <[email protected]>",
NULL,
"Message", 0);
}
void test_object_commit_parse__parsing_commit_with_multiple_committers_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer1 <[email protected]>\n"
"committer Committer2 <[email protected]>\n"
"committer Committer3 <[email protected]>\n"
"committer Committer4 <[email protected]>\n"
"\n"
"Message";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author <[email protected]>",
"Committer1 <[email protected]>",
NULL,
"Message", 0);
}
void test_object_commit_parse__parsing_commit_without_message_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author <[email protected]>",
"Committer <[email protected]>",
NULL,
"", 0);
}
void test_object_commit_parse__parsing_commit_with_unknown_fields_succeeds(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n"
"foo bar\n"
"more garbage\n"
"\n"
"Message";
assert_commit_parses(commit, 0,
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"Author <[email protected]>",
"Committer <[email protected]>",
NULL,
"Message", 0);
}
void test_object_commit_parse__parsing_commit_with_invalid_tree_fails(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1xxx5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n"
"\n"
"Message";
assert_commit_fails(commit, 0);
}
void test_object_commit_parse__parsing_commit_without_tree_fails(void)
{
const char *commit =
"author Author <[email protected]>\n"
"committer Committer <[email protected]>\n"
"\n"
"Message";
assert_commit_fails(commit, 0);
}
void test_object_commit_parse__parsing_commit_without_author_fails(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"committer Committer <[email protected]>\n"
"\n"
"Message";
assert_commit_fails(commit, 0);
}
void test_object_commit_parse__parsing_commit_without_committer_fails(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author Author <[email protected]>\n"
"\n"
"Message";
assert_commit_fails(commit, 0);
}
void test_object_commit_parse__parsing_encoding_will_not_cause_oob_read(void)
{
const char *commit =
"tree 3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8\n"
"author <>\n"
"committer <>\n"
"encoding foo\n";
/*
* As we ignore unknown fields, the cut-off encoding field will be
* parsed just fine.
*/
assert_commit_parses(commit, strlen(commit) - strlen("ncoding foo\n"),
"3e7ac388cadacccdf1c6c5f3445895b71d9cb0f8",
"<>",
"<>",
NULL,
"", 0);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/blob/filter.c
|
#include "clar_libgit2.h"
#include "posix.h"
#include "blob.h"
static git_repository *g_repo = NULL;
#define CRLF_NUM_TEST_OBJECTS 9
static const char *g_crlf_raw[CRLF_NUM_TEST_OBJECTS] = {
"",
"foo\nbar\n",
"foo\rbar\r",
"foo\r\nbar\r\n",
"foo\nbar\rboth\r\nreversed\n\ragain\nproblems\r",
"123\n\000\001\002\003\004abc\255\254\253\r\n",
"\xEF\xBB\xBFThis is UTF-8\n",
"\xEF\xBB\xBF\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\r\n\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\r\n",
"\xFE\xFF\x00T\x00h\x00i\x00s\x00!"
};
static off64_t g_crlf_raw_len[CRLF_NUM_TEST_OBJECTS] = {
-1, -1, -1, -1, -1, 17, -1, -1, 12
};
static git_oid g_crlf_oids[CRLF_NUM_TEST_OBJECTS];
static git_buf g_crlf_filtered[CRLF_NUM_TEST_OBJECTS] = {
{ "", 0, 0 },
{ "foo\nbar\n", 0, 8 },
{ "foo\rbar\r", 0, 8 },
{ "foo\nbar\n", 0, 8 },
{ "foo\nbar\rboth\nreversed\n\ragain\nproblems\r", 0, 38 },
{ "123\n\000\001\002\003\004abc\255\254\253\n", 0, 16 },
{ "\xEF\xBB\xBFThis is UTF-8\n", 0, 17 },
{ "\xEF\xBB\xBF\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\n\xE3\x81\xBB\xE3\x81\x92\xE3\x81\xBB\xE3\x81\x92\n", 0, 29 },
{ "\xFE\xFF\x00T\x00h\x00i\x00s\x00!", 0, 12 }
};
static git_buf_text_stats g_crlf_filtered_stats[CRLF_NUM_TEST_OBJECTS] = {
{ 0, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 2, 0, 6, 0 },
{ 0, 0, 2, 0, 0, 6, 0 },
{ 0, 0, 2, 2, 2, 6, 0 },
{ 0, 0, 4, 4, 1, 31, 0 },
{ 0, 1, 1, 2, 1, 9, 5 },
{ GIT_BUF_BOM_UTF8, 0, 0, 1, 0, 16, 0 },
{ GIT_BUF_BOM_UTF8, 0, 2, 2, 2, 27, 0 },
{ GIT_BUF_BOM_UTF16_BE, 5, 0, 0, 0, 7, 5 },
};
void test_object_blob_filter__initialize(void)
{
int i;
g_repo = cl_git_sandbox_init("empty_standard_repo");
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
if (g_crlf_raw_len[i] < 0)
g_crlf_raw_len[i] = strlen(g_crlf_raw[i]);
cl_git_pass(git_blob_create_from_buffer(
&g_crlf_oids[i], g_repo, g_crlf_raw[i], (size_t)g_crlf_raw_len[i]));
}
}
void test_object_blob_filter__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_blob_filter__unfiltered(void)
{
int i;
git_blob *blob;
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
size_t raw_len = (size_t)g_crlf_raw_len[i];
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
cl_assert_equal_sz(raw_len, (size_t)git_blob_rawsize(blob));
cl_assert_equal_i(
0, memcmp(g_crlf_raw[i], git_blob_rawcontent(blob), raw_len));
git_blob_free(blob);
}
}
void test_object_blob_filter__stats(void)
{
int i;
git_blob *blob;
git_buf buf = GIT_BUF_INIT;
git_buf_text_stats stats;
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
cl_git_pass(git_blob__getbuf(&buf, blob));
git_buf_gather_text_stats(&stats, &buf, false);
cl_assert_equal_i(
0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats)));
git_blob_free(blob);
}
git_buf_dispose(&buf);
}
void test_object_blob_filter__to_odb(void)
{
git_filter_list *fl = NULL;
git_config *cfg;
int i;
git_blob *blob;
git_buf out = GIT_BUF_INIT, zeroed;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_assert(cfg);
git_attr_cache_flush(g_repo);
cl_git_append2file("empty_standard_repo/.gitattributes", "*.txt text\n");
cl_git_pass(git_filter_list_load(
&fl, g_repo, NULL, "filename.txt", GIT_FILTER_TO_ODB, 0));
cl_assert(fl != NULL);
for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i]));
/* try once with allocated blob */
cl_git_pass(git_filter_list_apply_to_blob(&out, fl, blob));
cl_assert_equal_sz(g_crlf_filtered[i].size, out.size);
cl_assert_equal_i(
0, memcmp(out.ptr, g_crlf_filtered[i].ptr, out.size));
/* try again with zeroed blob */
memset(&zeroed, 0, sizeof(zeroed));
cl_git_pass(git_filter_list_apply_to_blob(&zeroed, fl, blob));
cl_assert_equal_sz(g_crlf_filtered[i].size, zeroed.size);
cl_assert_equal_i(
0, memcmp(zeroed.ptr, g_crlf_filtered[i].ptr, zeroed.size));
git_buf_dispose(&zeroed);
git_blob_free(blob);
}
git_filter_list_free(fl);
git_buf_dispose(&out);
git_config_free(cfg);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/blob/fromstream.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
static git_repository *repo;
static char textual_content[] = "libgit2\n\r\n\0";
void test_object_blob_fromstream__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
}
void test_object_blob_fromstream__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_blob_fromstream__multiple_write(void)
{
git_oid expected_id, id;
git_object *blob;
git_writestream *stream;
int i, howmany = 6;
cl_git_pass(git_oid_fromstr(&expected_id, "321cbdf08803c744082332332838df6bd160f8f9"));
cl_git_fail_with(GIT_ENOTFOUND,
git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_ANY));
cl_git_pass(git_blob_create_from_stream(&stream, repo, NULL));
for (i = 0; i < howmany; i++)
cl_git_pass(stream->write(stream, textual_content, strlen(textual_content)));
cl_git_pass(git_blob_create_from_stream_commit(&id, stream));
cl_assert_equal_oid(&expected_id, &id);
cl_git_pass(git_object_lookup(&blob, repo, &expected_id, GIT_OBJECT_BLOB));
git_object_free(blob);
}
#define GITATTR "* text=auto\n" \
"*.txt text\n" \
"*.data binary\n"
static void write_attributes(git_repository *repo)
{
git_buf buf = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&buf, git_repository_path(repo), "info"));
cl_git_pass(git_buf_joinpath(&buf, git_buf_cstr(&buf), "attributes"));
cl_git_pass(git_futils_mkpath2file(git_buf_cstr(&buf), 0777));
cl_git_rewritefile(git_buf_cstr(&buf), GITATTR);
git_buf_dispose(&buf);
}
static void assert_named_chunked_blob(const char *expected_sha, const char *fake_name)
{
git_oid expected_id, id;
git_writestream *stream;
int i, howmany = 6;
cl_git_pass(git_oid_fromstr(&expected_id, expected_sha));
cl_git_pass(git_blob_create_from_stream(&stream, repo, fake_name));
for (i = 0; i < howmany; i++)
cl_git_pass(stream->write(stream, textual_content, strlen(textual_content)));
cl_git_pass(git_blob_create_from_stream_commit(&id, stream));
cl_assert_equal_oid(&expected_id, &id);
}
void test_object_blob_fromstream__creating_a_blob_from_chunks_honors_the_attributes_directives(void)
{
write_attributes(repo);
assert_named_chunked_blob("321cbdf08803c744082332332838df6bd160f8f9", "dummy.data");
assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.txt");
assert_named_chunked_blob("e9671e138a780833cb689753570fd10a55be84fb", "dummy.dunno");
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/blob/write.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "posix.h"
#include "path.h"
#include "futils.h"
static git_repository *repo;
#define WORKDIR "empty_standard_repo"
#define BARE_REPO "testrepo.git"
#define ELSEWHERE "elsewhere"
typedef int (*blob_creator_fn)(
git_oid *,
git_repository *,
const char *);
void test_object_blob_write__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static void assert_blob_creation(const char *path_to_file, const char *blob_from_path, blob_creator_fn creator)
{
git_oid oid;
cl_git_mkfile(path_to_file, "1..2...3... Can you hear me?\n");
cl_must_pass(creator(&oid, repo, blob_from_path));
cl_assert(git_oid_streq(&oid, "da5e4f20c91c81b44a7e298f3d3fb3fe2f178e32") == 0);
}
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_file_located_in_the_working_directory(void)
{
repo = cl_git_sandbox_init(WORKDIR);
assert_blob_creation(WORKDIR "/test.txt", "test.txt", &git_blob_create_from_workdir);
}
void test_object_blob_write__can_create_a_blob_in_a_standard_repo_from_a_absolute_filepath_pointing_outside_of_the_working_directory(void)
{
git_buf full_path = GIT_BUF_INIT;
repo = cl_git_sandbox_init(WORKDIR);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
cl_must_pass(git_buf_puts(&full_path, "test.txt"));
assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
git_buf_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_object_blob_write__can_create_a_blob_in_a_bare_repo_from_a_absolute_filepath(void)
{
git_buf full_path = GIT_BUF_INIT;
repo = cl_git_sandbox_init(BARE_REPO);
cl_must_pass(p_mkdir(ELSEWHERE, 0777));
cl_must_pass(git_path_prettify_dir(&full_path, ELSEWHERE, NULL));
cl_must_pass(git_buf_puts(&full_path, "test.txt"));
assert_blob_creation(ELSEWHERE "/test.txt", git_buf_cstr(&full_path), &git_blob_create_from_disk);
git_buf_dispose(&full_path);
cl_must_pass(git_futils_rmdir_r(ELSEWHERE, NULL, GIT_RMDIR_REMOVE_FILES));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/read.c
|
#include "clar_libgit2.h"
#include "tree.h"
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
static git_repository *g_repo;
/* Fixture setup and teardown */
void test_object_tree_read__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tree_read__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tree_read__loaded(void)
{
/* acces randomly the entries on a loaded tree */
git_oid id;
git_tree *tree;
git_oid_fromstr(&id, tree_oid);
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_assert(git_tree_entry_byname(tree, "README") != NULL);
cl_assert(git_tree_entry_byname(tree, "NOTEXISTS") == NULL);
cl_assert(git_tree_entry_byname(tree, "") == NULL);
cl_assert(git_tree_entry_byindex(tree, 0) != NULL);
cl_assert(git_tree_entry_byindex(tree, 2) != NULL);
cl_assert(git_tree_entry_byindex(tree, 3) == NULL);
cl_assert(git_tree_entry_byindex(tree, (unsigned int)-1) == NULL);
git_tree_free(tree);
}
void test_object_tree_read__two(void)
{
/* read a tree from the repository */
git_oid id;
git_tree *tree;
const git_tree_entry *entry;
git_object *obj;
git_oid_fromstr(&id, tree_oid);
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_assert(git_tree_entrycount(tree) == 3);
/* GH-86: git_object_lookup() should also check the type if the object comes from the cache */
cl_assert(git_object_lookup(&obj, g_repo, &id, GIT_OBJECT_TREE) == 0);
cl_assert(obj != NULL);
git_object_free(obj);
obj = NULL;
cl_git_fail(git_object_lookup(&obj, g_repo, &id, GIT_OBJECT_BLOB));
cl_assert(obj == NULL);
entry = git_tree_entry_byname(tree, "README");
cl_assert(entry != NULL);
cl_assert_equal_s(git_tree_entry_name(entry), "README");
cl_git_pass(git_tree_entry_to_object(&obj, g_repo, entry));
cl_assert(obj != NULL);
git_object_free(obj);
git_tree_free(tree);
}
#define BIGFILE "bigfile"
#ifdef GIT_ARCH_64
#define BIGFILE_SIZE (off_t)4294967296
#else
# define BIGFILE_SIZE SIZE_MAX
#endif
void test_object_tree_read__largefile(void)
{
const git_tree_entry *entry;
git_index_entry ie;
git_commit *commit;
git_object *object;
git_index *index;
git_tree *tree;
git_oid oid;
char *buf;
if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE"))
cl_skip();
cl_assert(buf = git__calloc(1, BIGFILE_SIZE));
memset(&ie, 0, sizeof(ie));
ie.mode = GIT_FILEMODE_BLOB;
ie.path = BIGFILE;
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_add_from_buffer(index, &ie, buf, BIGFILE_SIZE));
cl_repo_commit_from_index(&oid, g_repo, NULL, 0, BIGFILE);
cl_git_pass(git_commit_lookup(&commit, g_repo, &oid));
cl_git_pass(git_commit_tree(&tree, commit));
cl_assert(entry = git_tree_entry_byname(tree, BIGFILE));
cl_git_pass(git_tree_entry_to_object(&object, g_repo, entry));
git_object_free(object);
git_tree_free(tree);
git_index_free(index);
git_commit_free(commit);
git__free(buf);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/update.c
|
#include "clar_libgit2.h"
#include "tree.h"
static git_repository *g_repo;
void test_object_tree_update__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo2");
}
void test_object_tree_update__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tree_update__remove_blob(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
const char *path = "README";
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operation via the tree updater */
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 1, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
git_tree_free(base_tree);
}
void test_object_tree_update__remove_blob_deeper(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
const char *path = "subdir/README";
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operation via the tree updater */
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 1, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
git_tree_free(base_tree);
}
void test_object_tree_update__remove_all_entries(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
const char *path1 = "subdir/subdir2/README";
const char *path2 = "subdir/subdir2/new.txt";
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path1},
{ GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB /* ignored */, path2},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path1, 0));
cl_git_pass(git_index_remove(idx, path2, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operation via the tree updater */
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 2, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
git_tree_free(base_tree);
}
void test_object_tree_update__replace_blob(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
const char *path = "README";
git_index_entry entry = { {0} };
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, path},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index_read_tree(idx, base_tree));
entry.path = path;
cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92"));
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_add(idx, &entry));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operation via the tree updater */
cl_git_pass(git_oid_fromstr(&updates[0].id, "fa49b077972391ad58037050f2a75f74e3671e92"));
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 1, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
git_tree_free(base_tree);
}
void test_object_tree_update__add_blobs(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
git_index_entry entry = { {0} };
int i;
const char *paths[] = {
"some/deep/path",
"some/other/path",
"a/path/elsewhere",
};
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[0]},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[1]},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[2]},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92"));
for (i = 0; i < 3; i++) {
cl_git_pass(git_oid_fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92"));
}
for (i = 0; i < 2; i++) {
int j;
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
base_tree = NULL;
if (i == 1) {
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
cl_git_pass(git_index_read_tree(idx, base_tree));
}
for (j = 0; j < 3; j++) {
entry.path = paths[j];
cl_git_pass(git_index_add(idx, &entry));
}
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operations via the tree updater */
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 3, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
}
git_tree_free(base_tree);
}
void test_object_tree_update__add_blobs_unsorted(void)
{
git_oid tree_index_id, tree_updater_id, base_id;
git_tree *base_tree;
git_index *idx;
git_index_entry entry = { {0} };
int i;
const char *paths[] = {
"some/deep/path",
"a/path/elsewhere",
"some/other/path",
};
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[0]},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[1]},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, paths[2]},
};
cl_git_pass(git_oid_fromstr(&base_id, "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"));
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_oid_fromstr(&entry.id, "fa49b077972391ad58037050f2a75f74e3671e92"));
for (i = 0; i < 3; i++) {
cl_git_pass(git_oid_fromstr(&updates[i].id, "fa49b077972391ad58037050f2a75f74e3671e92"));
}
for (i = 0; i < 2; i++) {
int j;
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
base_tree = NULL;
if (i == 1) {
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
cl_git_pass(git_index_read_tree(idx, base_tree));
}
for (j = 0; j < 3; j++) {
entry.path = paths[j];
cl_git_pass(git_index_add(idx, &entry));
}
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
git_index_free(idx);
/* Perform the same operations via the tree updater */
cl_git_pass(git_tree_create_updated(&tree_updater_id, g_repo, base_tree, 3, updates));
cl_assert_equal_oid(&tree_index_id, &tree_updater_id);
}
git_tree_free(base_tree);
}
void test_object_tree_update__add_conflict(void)
{
int i;
git_oid tree_updater_id;
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir/blob"},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir"},
};
for (i = 0; i < 2; i++) {
cl_git_pass(git_oid_fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"));
}
cl_git_fail(git_tree_create_updated(&tree_updater_id, g_repo, NULL, 2, updates));
}
void test_object_tree_update__add_conflict2(void)
{
int i;
git_oid tree_updater_id;
git_tree_update updates[] = {
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_BLOB, "a/dir/blob"},
{ GIT_TREE_UPDATE_UPSERT, {{0}}, GIT_FILEMODE_TREE, "a/dir/blob"},
};
for (i = 0; i < 2; i++) {
cl_git_pass(git_oid_fromstr(&updates[i].id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"));
}
cl_git_fail(git_tree_create_updated(&tree_updater_id, g_repo, NULL, 2, updates));
}
void test_object_tree_update__remove_invalid_submodule(void)
{
git_tree *baseline;
git_oid updated_tree_id, baseline_id;
git_tree_update updates[] = {
{GIT_TREE_UPDATE_REMOVE, {{0}}, GIT_FILEMODE_BLOB, "submodule"},
};
/* This tree contains a submodule with an all-zero commit for a submodule named 'submodule' */
cl_git_pass(git_oid_fromstr(&baseline_id, "396c7f1adb7925f51ba13a75f48252f44c5a14a2"));
cl_git_pass(git_tree_lookup(&baseline, g_repo, &baseline_id));
cl_git_pass(git_tree_create_updated(&updated_tree_id, g_repo, baseline, 1, updates));
git_tree_free(baseline);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/walk.c
|
#include "clar_libgit2.h"
#include "tree.h"
static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";
static git_repository *g_repo;
void test_object_tree_walk__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tree_walk__cleanup(void)
{
cl_git_sandbox_cleanup();
}
static int treewalk_count_cb(
const char *root, const git_tree_entry *entry, void *payload)
{
int *count = payload;
GIT_UNUSED(root);
GIT_UNUSED(entry);
(*count) += 1;
return 0;
}
void test_object_tree_walk__0(void)
{
git_oid id;
git_tree *tree;
int ct;
git_oid_fromstr(&id, tree_oid);
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
ct = 0;
cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_count_cb, &ct));
cl_assert_equal_i(3, ct);
ct = 0;
cl_git_pass(git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_count_cb, &ct));
cl_assert_equal_i(3, ct);
git_tree_free(tree);
}
static int treewalk_stop_cb(
const char *root, const git_tree_entry *entry, void *payload)
{
int *count = payload;
GIT_UNUSED(root);
GIT_UNUSED(entry);
(*count) += 1;
return (*count == 2) ? -123 : 0;
}
static int treewalk_stop_immediately_cb(
const char *root, const git_tree_entry *entry, void *payload)
{
GIT_UNUSED(root);
GIT_UNUSED(entry);
GIT_UNUSED(payload);
return -100;
}
void test_object_tree_walk__1(void)
{
git_oid id;
git_tree *tree;
int ct;
git_oid_fromstr(&id, tree_oid);
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
ct = 0;
cl_assert_equal_i(
-123, git_tree_walk(tree, GIT_TREEWALK_PRE, treewalk_stop_cb, &ct));
cl_assert_equal_i(2, ct);
ct = 0;
cl_assert_equal_i(
-123, git_tree_walk(tree, GIT_TREEWALK_POST, treewalk_stop_cb, &ct));
cl_assert_equal_i(2, ct);
cl_assert_equal_i(
-100, git_tree_walk(
tree, GIT_TREEWALK_PRE, treewalk_stop_immediately_cb, NULL));
cl_assert_equal_i(
-100, git_tree_walk(
tree, GIT_TREEWALK_POST, treewalk_stop_immediately_cb, NULL));
git_tree_free(tree);
}
struct treewalk_skip_data {
int files;
int dirs;
const char *skip;
const char *stop;
};
static int treewalk_skip_de_cb(
const char *root, const git_tree_entry *entry, void *payload)
{
struct treewalk_skip_data *data = payload;
const char *name = git_tree_entry_name(entry);
GIT_UNUSED(root);
if (git_tree_entry_type(entry) == GIT_OBJECT_TREE)
data->dirs++;
else
data->files++;
if (data->skip && !strcmp(name, data->skip))
return 1;
else if (data->stop && !strcmp(name, data->stop))
return -1;
else
return 0;
}
void test_object_tree_walk__2(void)
{
git_oid id;
git_tree *tree;
struct treewalk_skip_data data;
/* look up a deep tree */
git_oid_fromstr(&id, "ae90f12eea699729ed24555e40b9fd669da12a12");
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
memset(&data, 0, sizeof(data));
data.skip = "de";
cl_assert_equal_i(0, git_tree_walk(
tree, GIT_TREEWALK_PRE, treewalk_skip_de_cb, &data));
cl_assert_equal_i(5, data.files);
cl_assert_equal_i(3, data.dirs);
memset(&data, 0, sizeof(data));
data.stop = "3.txt";
cl_assert_equal_i(-1, git_tree_walk(
tree, GIT_TREEWALK_PRE, treewalk_skip_de_cb, &data));
cl_assert_equal_i(3, data.files);
cl_assert_equal_i(2, data.dirs);
memset(&data, 0, sizeof(data));
data.skip = "new.txt";
cl_assert_equal_i(0, git_tree_walk(
tree, GIT_TREEWALK_PRE, treewalk_skip_de_cb, &data));
cl_assert_equal_i(7, data.files);
cl_assert_equal_i(4, data.dirs);
memset(&data, 0, sizeof(data));
data.stop = "new.txt";
cl_assert_equal_i(-1, git_tree_walk(
tree, GIT_TREEWALK_PRE, treewalk_skip_de_cb, &data));
cl_assert_equal_i(7, data.files);
cl_assert_equal_i(4, data.dirs);
git_tree_free(tree);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/write.c
|
#include "clar_libgit2.h"
#include "tree.h"
static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92";
static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7";
static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1";
static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488";
static git_repository *g_repo;
/* Fixture setup and teardown */
void test_object_tree_write__initialize(void)
{
g_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tree_write__cleanup(void)
{
cl_git_sandbox_cleanup();
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 1));
}
void test_object_tree_write__from_memory(void)
{
/* write a tree from a memory */
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, rid, id2;
git_oid_fromstr(&id, first_tree);
git_oid_fromstr(&id2, second_tree);
git_oid_fromstr(&bid, blob_oid);
/* create a second tree from first tree using `git_treebuilder_insert`
* on REPOSITORY_FOLDER.
*/
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_new(&builder, g_repo, tree));
cl_git_fail(git_treebuilder_insert(NULL, builder, "",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "/",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "..",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".",
&bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt",
&bid, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_insert(
NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_write(&rid, builder));
cl_assert(git_oid_cmp(&rid, &id2) == 0);
git_treebuilder_free(builder);
git_tree_free(tree);
}
void test_object_tree_write__subtree(void)
{
/* write a hierarchical tree from a memory */
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, subtree_id, id2, id3;
git_oid id_hiearar;
git_oid_fromstr(&id, first_tree);
git_oid_fromstr(&id2, second_tree);
git_oid_fromstr(&id3, third_tree);
git_oid_fromstr(&bid, blob_oid);
/* create subtree */
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
cl_git_pass(git_treebuilder_insert(
NULL, builder, "new.txt", &bid, GIT_FILEMODE_BLOB)); /* -V536 */
cl_git_pass(git_treebuilder_write(&subtree_id, builder));
git_treebuilder_free(builder);
/* create parent tree */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_git_pass(git_treebuilder_new(&builder, g_repo, tree));
cl_git_pass(git_treebuilder_insert(
NULL, builder, "new", &subtree_id, GIT_FILEMODE_TREE)); /* -V536 */
cl_git_pass(git_treebuilder_write(&id_hiearar, builder));
git_treebuilder_free(builder);
git_tree_free(tree);
cl_assert(git_oid_cmp(&id_hiearar, &id3) == 0);
/* check data is correct */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id_hiearar));
cl_assert(2 == git_tree_entrycount(tree));
git_tree_free(tree);
}
/*
* And the Lord said: Is this tree properly sorted?
*/
void test_object_tree_write__sorted_subtrees(void)
{
git_treebuilder *builder;
git_tree *tree;
unsigned int i;
int position_c = -1, position_cake = -1, position_config = -1;
struct {
unsigned int attr;
const char *filename;
} entries[] = {
{ GIT_FILEMODE_BLOB, ".gitattributes" },
{ GIT_FILEMODE_BLOB, ".gitignore" },
{ GIT_FILEMODE_BLOB, ".htaccess" },
{ GIT_FILEMODE_BLOB, "Capfile" },
{ GIT_FILEMODE_BLOB, "Makefile"},
{ GIT_FILEMODE_BLOB, "README"},
{ GIT_FILEMODE_TREE, "app"},
{ GIT_FILEMODE_TREE, "cake"},
{ GIT_FILEMODE_TREE, "config"},
{ GIT_FILEMODE_BLOB, "c"},
{ GIT_FILEMODE_BLOB, "git_test.txt"},
{ GIT_FILEMODE_BLOB, "htaccess.htaccess"},
{ GIT_FILEMODE_BLOB, "index.php"},
{ GIT_FILEMODE_TREE, "plugins"},
{ GIT_FILEMODE_TREE, "schemas"},
{ GIT_FILEMODE_TREE, "ssl-certs"},
{ GIT_FILEMODE_TREE, "vendors"}
};
git_oid bid, tid, tree_oid;
cl_git_pass(git_oid_fromstr(&bid, blob_oid));
cl_git_pass(git_oid_fromstr(&tid, first_tree));
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
for (i = 0; i < ARRAY_SIZE(entries); ++i) {
git_oid *id = entries[i].attr == GIT_FILEMODE_TREE ? &tid : &bid;
cl_git_pass(git_treebuilder_insert(NULL,
builder, entries[i].filename, id, entries[i].attr));
}
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
for (i = 0; i < git_tree_entrycount(tree); i++) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
if (strcmp(entry->filename, "c") == 0)
position_c = i;
if (strcmp(entry->filename, "cake") == 0)
position_cake = i;
if (strcmp(entry->filename, "config") == 0)
position_config = i;
}
git_tree_free(tree);
cl_assert(position_c != -1);
cl_assert(position_cake != -1);
cl_assert(position_config != -1);
cl_assert(position_c < position_cake);
cl_assert(position_cake < position_config);
git_treebuilder_free(builder);
}
static struct {
unsigned int attr;
const char *filename;
} _entries[] = {
{ GIT_FILEMODE_BLOB, "aardvark" },
{ GIT_FILEMODE_BLOB, ".first" },
{ GIT_FILEMODE_BLOB, "apple" },
{ GIT_FILEMODE_BLOB, "last"},
{ GIT_FILEMODE_BLOB, "apple_after"},
{ GIT_FILEMODE_BLOB, "after_aardvark"},
{ 0, NULL },
};
void test_object_tree_write__removing_and_re_adding_in_treebuilder(void)
{
git_treebuilder *builder;
int i, aardvark_i, apple_i, apple_after_i, apple_extra_i, last_i;
git_oid entry_oid, tree_oid;
git_tree *tree;
cl_git_pass(git_oid_fromstr(&entry_oid, blob_oid));
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
cl_assert_equal_i(0, (int)git_treebuilder_entrycount(builder));
for (i = 0; _entries[i].filename; ++i)
cl_git_pass(git_treebuilder_insert(NULL,
builder, _entries[i].filename, &entry_oid, _entries[i].attr));
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_remove(builder, "apple"));
cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_remove(builder, "apple_after"));
cl_assert_equal_i(4, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_insert(
NULL, builder, "before_last", &entry_oid, GIT_FILEMODE_BLOB));
cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
/* reinsert apple_after */
cl_git_pass(git_treebuilder_insert(
NULL, builder, "apple_after", &entry_oid, GIT_FILEMODE_BLOB));
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_remove(builder, "last"));
cl_assert_equal_i(5, (int)git_treebuilder_entrycount(builder));
/* reinsert last */
cl_git_pass(git_treebuilder_insert(
NULL, builder, "last", &entry_oid, GIT_FILEMODE_BLOB));
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_insert(
NULL, builder, "apple_extra", &entry_oid, GIT_FILEMODE_BLOB));
cl_assert_equal_i(7, (int)git_treebuilder_entrycount(builder));
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
git_treebuilder_free(builder);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
cl_assert_equal_i(7, (int)git_tree_entrycount(tree));
cl_assert(git_tree_entry_byname(tree, ".first") != NULL);
cl_assert(git_tree_entry_byname(tree, "apple") == NULL);
cl_assert(git_tree_entry_byname(tree, "apple_after") != NULL);
cl_assert(git_tree_entry_byname(tree, "apple_extra") != NULL);
cl_assert(git_tree_entry_byname(tree, "last") != NULL);
aardvark_i = apple_i = apple_after_i = apple_extra_i = last_i = -1;
for (i = 0; i < 7; ++i) {
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
if (!strcmp(entry->filename, "aardvark"))
aardvark_i = i;
else if (!strcmp(entry->filename, "apple"))
apple_i = i;
else if (!strcmp(entry->filename, "apple_after"))
apple_after_i = i;
else if (!strcmp(entry->filename, "apple_extra"))
apple_extra_i = i;
else if (!strcmp(entry->filename, "last"))
last_i = i;
}
cl_assert_equal_i(-1, apple_i);
cl_assert_equal_i(6, last_i);
cl_assert(aardvark_i < apple_after_i);
cl_assert(apple_after_i < apple_extra_i);
git_tree_free(tree);
}
static int treebuilder_filter_prefixed(
const git_tree_entry *entry, void *payload)
{
return !git__prefixcmp(git_tree_entry_name(entry), payload);
}
void test_object_tree_write__filtering(void)
{
git_treebuilder *builder;
int i;
git_oid entry_oid, tree_oid;
git_tree *tree;
git_oid_fromstr(&entry_oid, blob_oid);
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
for (i = 0; _entries[i].filename; ++i)
cl_git_pass(git_treebuilder_insert(NULL,
builder, _entries[i].filename, &entry_oid, _entries[i].attr));
cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));
cl_assert(git_treebuilder_get(builder, "apple") != NULL);
cl_assert(git_treebuilder_get(builder, "aardvark") != NULL);
cl_assert(git_treebuilder_get(builder, "last") != NULL);
git_treebuilder_filter(builder, treebuilder_filter_prefixed, "apple");
cl_assert_equal_i(4, (int)git_treebuilder_entrycount(builder));
cl_assert(git_treebuilder_get(builder, "apple") == NULL);
cl_assert(git_treebuilder_get(builder, "aardvark") != NULL);
cl_assert(git_treebuilder_get(builder, "last") != NULL);
git_treebuilder_filter(builder, treebuilder_filter_prefixed, "a");
cl_assert_equal_i(2, (int)git_treebuilder_entrycount(builder));
cl_assert(git_treebuilder_get(builder, "aardvark") == NULL);
cl_assert(git_treebuilder_get(builder, "last") != NULL);
cl_git_pass(git_treebuilder_write(&tree_oid, builder));
git_treebuilder_free(builder);
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));
cl_assert_equal_i(2, (int)git_tree_entrycount(tree));
git_tree_free(tree);
}
void test_object_tree_write__cruel_paths(void)
{
static const char *the_paths[] = {
"C:\\",
" : * ? \" \n < > |",
"a\\b",
"\\\\b\a",
":\\",
"COM1",
"foo.aux",
REP1024("1234"), /* 4096 char string */
REP1024("12345678"), /* 8192 char string */
"\xC5\xAA\x6E\xC4\xAD\x63\xC5\x8D\x64\x65\xCC\xBD", /* Ūnĭcōde̽ */
NULL
};
git_treebuilder *builder;
git_tree *tree;
git_oid id, bid, subid;
const char **scan;
int count = 0, i, j;
git_tree_entry *te;
git_oid_fromstr(&bid, blob_oid);
/* create tree */
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
for (scan = the_paths; *scan; ++scan) {
cl_git_pass(git_treebuilder_insert(
NULL, builder, *scan, &bid, GIT_FILEMODE_BLOB));
count++;
}
cl_git_pass(git_treebuilder_write(&id, builder));
git_treebuilder_free(builder);
/* check data is correct */
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
cl_assert_equal_i(count, git_tree_entrycount(tree));
for (scan = the_paths; *scan; ++scan) {
const git_tree_entry *cte = git_tree_entry_byname(tree, *scan);
cl_assert(cte != NULL);
cl_assert_equal_s(*scan, git_tree_entry_name(cte));
}
for (scan = the_paths; *scan; ++scan) {
cl_git_pass(git_tree_entry_bypath(&te, tree, *scan));
cl_assert_equal_s(*scan, git_tree_entry_name(te));
git_tree_entry_free(te);
}
git_tree_free(tree);
/* let's try longer paths */
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
for (scan = the_paths; *scan; ++scan) {
cl_git_pass(git_treebuilder_insert(
NULL, builder, *scan, &id, GIT_FILEMODE_TREE));
}
cl_git_pass(git_treebuilder_write(&subid, builder));
git_treebuilder_free(builder);
/* check data is correct */
cl_git_pass(git_tree_lookup(&tree, g_repo, &subid));
cl_assert_equal_i(count, git_tree_entrycount(tree));
for (i = 0; i < count; ++i) {
for (j = 0; j < count; ++j) {
git_buf b = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&b, the_paths[i], the_paths[j]));
cl_git_pass(git_tree_entry_bypath(&te, tree, b.ptr));
cl_assert_equal_s(the_paths[j], git_tree_entry_name(te));
git_tree_entry_free(te);
git_buf_dispose(&b);
}
}
git_tree_free(tree);
}
void test_object_tree_write__protect_filesystems(void)
{
git_treebuilder *builder;
git_oid bid;
cl_git_pass(git_oid_fromstr(&bid, "fa49b077972391ad58037050f2a75f74e3671e92"));
/* Ensure that (by default) we can write objects with funny names on
* platforms that are not affected.
*/
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git.", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "git~1", &bid, GIT_FILEMODE_BLOB));
#ifndef __APPLE__
cl_git_pass(git_treebuilder_insert(NULL, builder, ".git\xef\xbb\xbf", &bid, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_insert(NULL, builder, ".git\xe2\x80\xad", &bid, GIT_FILEMODE_BLOB));
#endif
git_treebuilder_free(builder);
/* Now turn on core.protectHFS and core.protectNTFS and validate that these
* paths are rejected.
*/
cl_repo_set_bool(g_repo, "core.protectHFS", true);
cl_repo_set_bool(g_repo, "core.protectNTFS", true);
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git.", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, "git~1", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git\xef\xbb\xbf", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git\xe2\x80\xad", &bid, GIT_FILEMODE_BLOB));
cl_git_fail(git_treebuilder_insert(NULL, builder, ".git::$INDEX_ALLOCATION/dummy-file", &bid, GIT_FILEMODE_BLOB));
git_treebuilder_free(builder);
}
static void test_invalid_objects(bool should_allow_invalid)
{
git_treebuilder *builder;
git_oid valid_blob_id, invalid_blob_id, valid_tree_id, invalid_tree_id;
#define assert_allowed(expr) \
clar__assert(!(expr) == should_allow_invalid, \
__FILE__, __func__, __LINE__, \
(should_allow_invalid ? \
"Expected function call to succeed: " #expr : \
"Expected function call to fail: " #expr), \
NULL, 1)
cl_git_pass(git_oid_fromstr(&valid_blob_id, blob_oid));
cl_git_pass(git_oid_fromstr(&invalid_blob_id,
"1234567890123456789012345678901234567890"));
cl_git_pass(git_oid_fromstr(&valid_tree_id, first_tree));
cl_git_pass(git_oid_fromstr(&invalid_tree_id,
"0000000000111111111122222222223333333333"));
cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));
/* test valid blobs and trees (these should always pass) */
cl_git_pass(git_treebuilder_insert(NULL, builder, "file.txt", &valid_blob_id, GIT_FILEMODE_BLOB));
cl_git_pass(git_treebuilder_insert(NULL, builder, "folder", &valid_tree_id, GIT_FILEMODE_TREE));
/* replace valid files and folders with invalid ones */
assert_allowed(git_treebuilder_insert(NULL, builder, "file.txt", &invalid_blob_id, GIT_FILEMODE_BLOB));
assert_allowed(git_treebuilder_insert(NULL, builder, "folder", &invalid_blob_id, GIT_FILEMODE_BLOB));
/* insert new invalid files and folders */
assert_allowed(git_treebuilder_insert(NULL, builder, "invalid_file.txt", &invalid_blob_id, GIT_FILEMODE_BLOB));
assert_allowed(git_treebuilder_insert(NULL, builder, "invalid_folder", &invalid_blob_id, GIT_FILEMODE_BLOB));
/* insert valid blobs as trees and trees as blobs */
assert_allowed(git_treebuilder_insert(NULL, builder, "file_as_folder", &valid_blob_id, GIT_FILEMODE_TREE));
assert_allowed(git_treebuilder_insert(NULL, builder, "folder_as_file.txt", &valid_tree_id, GIT_FILEMODE_BLOB));
#undef assert_allowed
git_treebuilder_free(builder);
}
static void test_inserting_submodule(void)
{
git_treebuilder *bld;
git_oid sm_id;
cl_git_pass(git_oid_fromstr(&sm_id, "da39a3ee5e6b4b0d3255bfef95601890afd80709"));
cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL));
cl_git_pass(git_treebuilder_insert(NULL, bld, "sm", &sm_id, GIT_FILEMODE_COMMIT));
git_treebuilder_free(bld);
}
void test_object_tree_write__object_validity(void)
{
/* Ensure that we cannot add invalid objects by default */
test_invalid_objects(false);
test_inserting_submodule();
/* Ensure that we can turn off validation */
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0));
test_invalid_objects(true);
test_inserting_submodule();
}
void test_object_tree_write__invalid_null_oid(void)
{
git_treebuilder *bld;
git_oid null_oid = {{0}};
cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL));
cl_git_fail(git_treebuilder_insert(NULL, bld, "null_oid_file", &null_oid, GIT_FILEMODE_BLOB));
cl_assert(git_error_last() && strstr(git_error_last()->message, "null OID") != NULL);
git_treebuilder_free(bld);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/frompath.c
|
#include "clar_libgit2.h"
static git_repository *repo;
static git_tree *tree;
void test_object_tree_frompath__initialize(void)
{
git_oid id;
const char *tree_with_subtrees_oid = "ae90f12eea699729ed24555e40b9fd669da12a12";
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_assert(repo != NULL);
cl_git_pass(git_oid_fromstr(&id, tree_with_subtrees_oid));
cl_git_pass(git_tree_lookup(&tree, repo, &id));
cl_assert(tree != NULL);
}
void test_object_tree_frompath__cleanup(void)
{
git_tree_free(tree);
tree = NULL;
git_repository_free(repo);
repo = NULL;
}
static void assert_tree_from_path(
git_tree *root,
const char *path,
const char *expected_entry_name)
{
git_tree_entry *entry;
cl_git_pass(git_tree_entry_bypath(&entry, root, path));
cl_assert_equal_s(git_tree_entry_name(entry), expected_entry_name);
git_tree_entry_free(entry);
}
void test_object_tree_frompath__retrieve_tree_from_path_to_treeentry(void)
{
git_tree_entry *e;
assert_tree_from_path(tree, "README", "README");
assert_tree_from_path(tree, "ab/de/fgh/1.txt", "1.txt");
assert_tree_from_path(tree, "ab/de/fgh", "fgh");
assert_tree_from_path(tree, "ab/de/fgh/", "fgh");
assert_tree_from_path(tree, "ab/de", "de");
assert_tree_from_path(tree, "ab/", "ab");
assert_tree_from_path(tree, "ab/de/", "de");
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "i-do-not-exist.txt"));
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "README/"));
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/de/fgh/i-do-not-exist.txt"));
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "nope/de/fgh/1.txt"));
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt"));
cl_assert_equal_i(GIT_ENOTFOUND, git_tree_entry_bypath(&e, tree, "ab/me-neither/fgh/2.txt/"));
}
void test_object_tree_frompath__fail_when_processing_an_invalid_path(void)
{
git_tree_entry *e;
cl_must_fail(git_tree_entry_bypath(&e, tree, "/"));
cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab"));
cl_must_fail(git_tree_entry_bypath(&e, tree, "/ab/de"));
cl_must_fail(git_tree_entry_bypath(&e, tree, "ab//de"));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/parse.c
|
#include "clar_libgit2.h"
#include "tree.h"
#include "object.h"
#define OID1_HEX \
"\xae\x90\xf1\x2e\xea\x69\x97\x29\xed\x24" \
"\x55\x5e\x40\xb9\xfd\x66\x9d\xa1\x2a\x12"
#define OID1_STR "ae90f12eea699729ed24555e40b9fd669da12a12"
#define OID2_HEX \
"\xe8\xbf\xe5\xaf\x39\x57\x9a\x7e\x48\x98" \
"\xbb\x23\xf3\xa7\x6a\x72\xc3\x68\xce\xe6"
#define OID2_STR "e8bfe5af39579a7e4898bb23f3a76a72c368cee6"
typedef struct {
const char *filename;
uint16_t attr;
const char *oid;
} expected_entry;
static void assert_tree_parses(const char *data, size_t datalen,
expected_entry *expected_entries, size_t expected_nentries)
{
git_tree *tree;
size_t n;
if (!datalen)
datalen = strlen(data);
cl_git_pass(git_object__from_raw((git_object **) &tree, data, datalen, GIT_OBJECT_TREE));
cl_assert_equal_i(git_tree_entrycount(tree), expected_nentries);
for (n = 0; n < expected_nentries; n++) {
expected_entry *expected = expected_entries + n;
const git_tree_entry *entry;
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, expected->oid));
cl_assert(entry = git_tree_entry_byname(tree, expected->filename));
cl_assert_equal_s(expected->filename, entry->filename);
cl_assert_equal_i(expected->attr, entry->attr);
cl_assert_equal_oid(&oid, entry->oid);
}
git_object_free(&tree->object);
}
static void assert_tree_fails(const char *data, size_t datalen)
{
git_object *object;
if (!datalen)
datalen = strlen(data);
cl_git_fail(git_object__from_raw(&object, data, datalen, GIT_OBJECT_TREE));
}
void test_object_tree_parse__single_blob_parses(void)
{
expected_entry entries[] = {
{ "foo", 0100644, OID1_STR },
};
const char data[] = "100644 foo\x00" OID1_HEX;
assert_tree_parses(data, ARRAY_SIZE(data) - 1, entries, ARRAY_SIZE(entries));
}
void test_object_tree_parse__single_tree_parses(void)
{
expected_entry entries[] = {
{ "foo", 040000, OID1_STR },
};
const char data[] = "040000 foo\x00" OID1_HEX;
assert_tree_parses(data, ARRAY_SIZE(data) - 1, entries, ARRAY_SIZE(entries));
}
void test_object_tree_parse__leading_filename_spaces_parse(void)
{
expected_entry entries[] = {
{ " bar", 0100644, OID1_STR },
};
const char data[] = "100644 bar\x00" OID1_HEX;
assert_tree_parses(data, ARRAY_SIZE(data) - 1, entries, ARRAY_SIZE(entries));
}
void test_object_tree_parse__multiple_entries_parse(void)
{
expected_entry entries[] = {
{ "bar", 0100644, OID1_STR },
{ "foo", 040000, OID2_STR },
};
const char data[] =
"100644 bar\x00" OID1_HEX
"040000 foo\x00" OID2_HEX;
assert_tree_parses(data, ARRAY_SIZE(data) - 1, entries, ARRAY_SIZE(entries));
}
void test_object_tree_parse__invalid_mode_fails(void)
{
const char data[] = "10x644 bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__missing_mode_fails(void)
{
const char data[] = " bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__mode_doesnt_cause_oob_read(void)
{
const char data[] = "100644 bar\x00" OID1_HEX;
assert_tree_fails(data, 2);
/*
* An oob-read would correctly parse the filename and
* later fail to parse the OID with a different error
* message
*/
cl_assert_equal_s(git_error_last()->message, "failed to parse tree: missing space after filemode");
}
void test_object_tree_parse__unreasonably_large_mode_fails(void)
{
const char data[] = "10000000000000000000000000 bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__missing_filename_separator_fails(void)
{
const char data[] = "100644bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__missing_filename_terminator_fails(void)
{
const char data[] = "100644 bar" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__empty_filename_fails(void)
{
const char data[] = "100644 \x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__trailing_garbage_fails(void)
{
const char data[] = "100644 bar\x00" OID1_HEX "x";
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__leading_space_fails(void)
{
const char data[] = " 100644 bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 1);
}
void test_object_tree_parse__truncated_oid_fails(void)
{
const char data[] = " 100644 bar\x00" OID1_HEX;
assert_tree_fails(data, ARRAY_SIZE(data) - 2);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/attributes.c
|
#include "clar_libgit2.h"
#include "tree.h"
static git_repository *repo;
static const char *blob_oid = "3d0970ec547fc41ef8a5882dde99c6adce65b021";
static const char *tree_oid = "1b05fdaa881ee45b48cbaa5e9b037d667a47745e";
void test_object_tree_attributes__initialize(void)
{
repo = cl_git_sandbox_init("deprecated-mode.git");
}
void test_object_tree_attributes__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_object_tree_attributes__ensure_correctness_of_attributes_on_insertion(void)
{
git_treebuilder *builder;
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, blob_oid));
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0777777));
cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0100666));
cl_git_fail(git_treebuilder_insert(NULL, builder, "one.txt", &oid, (git_filemode_t)0000001));
git_treebuilder_free(builder);
}
void test_object_tree_attributes__group_writable_tree_entries_created_with_an_antique_git_version_can_still_be_accessed(void)
{
git_oid tid;
git_tree *tree;
const git_tree_entry *entry;
cl_git_pass(git_oid_fromstr(&tid, tree_oid));
cl_git_pass(git_tree_lookup(&tree, repo, &tid));
entry = git_tree_entry_byname(tree, "old_mode.txt");
cl_assert_equal_i(
GIT_FILEMODE_BLOB,
git_tree_entry_filemode(entry));
git_tree_free(tree);
}
void test_object_tree_attributes__treebuilder_reject_invalid_filemode(void)
{
git_treebuilder *builder;
git_oid bid;
const git_tree_entry *entry;
cl_git_pass(git_oid_fromstr(&bid, blob_oid));
cl_git_pass(git_treebuilder_new(&builder, repo, NULL));
cl_git_fail(git_treebuilder_insert(
&entry,
builder,
"normalized.txt",
&bid,
GIT_FILEMODE_BLOB_GROUP_WRITABLE));
git_treebuilder_free(builder);
}
void test_object_tree_attributes__normalize_attributes_when_creating_a_tree_from_an_existing_one(void)
{
git_treebuilder *builder;
git_oid tid, tid2;
git_tree *tree;
const git_tree_entry *entry;
cl_git_pass(git_oid_fromstr(&tid, tree_oid));
cl_git_pass(git_tree_lookup(&tree, repo, &tid));
cl_git_pass(git_treebuilder_new(&builder, repo, tree));
entry = git_treebuilder_get(builder, "old_mode.txt");
cl_assert(entry != NULL);
cl_assert_equal_i(
GIT_FILEMODE_BLOB,
git_tree_entry_filemode(entry));
cl_git_pass(git_treebuilder_write(&tid2, builder));
git_treebuilder_free(builder);
git_tree_free(tree);
cl_git_pass(git_tree_lookup(&tree, repo, &tid2));
entry = git_tree_entry_byname(tree, "old_mode.txt");
cl_assert(entry != NULL);
cl_assert_equal_i(
GIT_FILEMODE_BLOB,
git_tree_entry_filemode(entry));
git_tree_free(tree);
}
void test_object_tree_attributes__normalize_600(void)
{
git_oid id;
git_tree *tree;
const git_tree_entry *entry;
git_oid_fromstr(&id, "0810fb7818088ff5ac41ee49199b51473b1bd6c7");
cl_git_pass(git_tree_lookup(&tree, repo, &id));
entry = git_tree_entry_byname(tree, "ListaTeste.xml");
cl_assert_equal_i(git_tree_entry_filemode(entry), GIT_FILEMODE_BLOB);
cl_assert_equal_i(git_tree_entry_filemode_raw(entry), 0100600);
git_tree_free(tree);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/object/tree/duplicateentries.c
|
#include "clar_libgit2.h"
#include "tree.h"
static git_repository *_repo;
void test_object_tree_duplicateentries__initialize(void) {
_repo = cl_git_sandbox_init("testrepo");
}
void test_object_tree_duplicateentries__cleanup(void) {
cl_git_sandbox_cleanup();
}
/*
* $ git show --format=raw refs/heads/dir
* commit 144344043ba4d4a405da03de3844aa829ae8be0e
* tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
* parent cf80f8de9f1185bf3a05f993f6121880dd0cfbc9
* author Ben Straub <[email protected]> 1343755506 -0700
* committer Ben Straub <[email protected]> 1343755506 -0700
*
* Change a file mode
*
* diff --git a/a/b.txt b/a/b.txt
* old mode 100644
* new mode 100755
*
* $ git ls-tree d52a8fe84ceedf260afe4f0287bbfca04a117e83
* 100644 blob a8233120f6ad708f843d861ce2b7228ec4e3dec6 README
* 040000 tree 4e0883eeeeebc1fb1735161cea82f7cb5fab7e63 a
* 100644 blob 45b983be36b73c0788dc9cbcb76cbb80fc7bb057 branch_file.txt
* 100644 blob a71586c1dfe8a71c6cbf6c129f404c5642ff31bd new.txt
*/
static void tree_checker(
git_oid *tid,
const char *expected_sha,
git_filemode_t expected_filemode)
{
git_tree *tree;
const git_tree_entry *entry;
git_oid oid;
cl_git_pass(git_tree_lookup(&tree, _repo, tid));
cl_assert_equal_i(1, (int)git_tree_entrycount(tree));
entry = git_tree_entry_byindex(tree, 0);
cl_git_pass(git_oid_fromstr(&oid, expected_sha));
cl_assert_equal_i(0, git_oid_cmp(&oid, git_tree_entry_id(entry)));
cl_assert_equal_i(expected_filemode, git_tree_entry_filemode(entry));
git_tree_free(tree);
}
static void tree_creator(git_oid *out, void (*fn)(git_treebuilder *))
{
git_treebuilder *builder;
cl_git_pass(git_treebuilder_new(&builder, _repo, NULL));
fn(builder);
cl_git_pass(git_treebuilder_write(out, builder));
git_treebuilder_free(builder);
}
static void two_blobs(git_treebuilder *bld)
{
git_oid oid;
const git_tree_entry *entry;
cl_git_pass(git_oid_fromstr(&oid,
"a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
cl_git_pass(git_treebuilder_insert(
&entry, bld, "duplicate", &oid,
GIT_FILEMODE_BLOB));
cl_git_pass(git_oid_fromstr(&oid,
"a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); /* blob oid (new.txt) */
cl_git_pass(git_treebuilder_insert(
&entry, bld, "duplicate", &oid,
GIT_FILEMODE_BLOB));
}
static void one_blob_and_one_tree(git_treebuilder *bld)
{
git_oid oid;
const git_tree_entry *entry;
cl_git_pass(git_oid_fromstr(&oid,
"a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* blob oid (README) */
cl_git_pass(git_treebuilder_insert(
&entry, bld, "duplicate", &oid,
GIT_FILEMODE_BLOB));
cl_git_pass(git_oid_fromstr(&oid,
"4e0883eeeeebc1fb1735161cea82f7cb5fab7e63")); /* tree oid (a) */
cl_git_pass(git_treebuilder_insert(
&entry, bld, "duplicate", &oid,
GIT_FILEMODE_TREE));
}
void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_through_the_treebuilder(void)
{
git_oid tid;
tree_creator(&tid, two_blobs);
tree_checker(&tid, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", GIT_FILEMODE_BLOB);
tree_creator(&tid, one_blob_and_one_tree);
tree_checker(&tid, "4e0883eeeeebc1fb1735161cea82f7cb5fab7e63", GIT_FILEMODE_TREE);
}
static void add_fake_conflicts(git_index *index)
{
git_index_entry ancestor_entry, our_entry, their_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));
ancestor_entry.path = "duplicate";
ancestor_entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&ancestor_entry, 1);
git_oid_fromstr(&ancestor_entry.id, "a8233120f6ad708f843d861ce2b7228ec4e3dec6");
our_entry.path = "duplicate";
our_entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&our_entry, 2);
git_oid_fromstr(&our_entry.id, "45b983be36b73c0788dc9cbcb76cbb80fc7bb057");
their_entry.path = "duplicate";
their_entry.mode = GIT_FILEMODE_BLOB;
GIT_INDEX_ENTRY_STAGE_SET(&their_entry, 3);
git_oid_fromstr(&their_entry.id, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd");
cl_git_pass(git_index_conflict_add(index, &ancestor_entry, &our_entry, &their_entry));
}
void test_object_tree_duplicateentries__cannot_create_a_duplicate_entry_building_a_tree_from_a_index_with_conflicts(void)
{
git_index *index;
git_oid tid;
cl_git_pass(git_repository_index(&index, _repo));
add_fake_conflicts(index);
cl_assert_equal_i(GIT_EUNMERGED, git_index_write_tree(&tid, index));
git_index_free(index);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/pathspec.c
|
#include "clar_libgit2.h"
#include "git2/pathspec.h"
static git_repository *g_repo;
void test_repo_pathspec__initialize(void)
{
g_repo = cl_git_sandbox_init("status");
}
void test_repo_pathspec__cleanup(void)
{
cl_git_sandbox_cleanup();
g_repo = NULL;
}
static char *str0[] = { "*_file", "new_file", "garbage" };
static char *str1[] = { "*_FILE", "NEW_FILE", "GARBAGE" };
static char *str2[] = { "staged_*" };
static char *str3[] = { "!subdir", "*_file", "new_file" };
static char *str4[] = { "*" };
static char *str5[] = { "S*" };
void test_repo_pathspec__workdir0(void)
{
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "*_file", "new_file", "garbage" } */
s.strings = str0; s.count = ARRAY_SIZE(str0);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo, 0, ps));
cl_assert_equal_sz(10, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(10, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(1, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("garbage", git_pathspec_match_list_failed_entry(m, 0));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_FIND_FAILURES | GIT_PATHSPEC_FAILURES_ONLY, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(1, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
}
void test_repo_pathspec__workdir1(void)
{
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "*_FILE", "NEW_FILE", "GARBAGE" } */
s.strings = str1; s.count = ARRAY_SIZE(str1);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_IGNORE_CASE, ps));
cl_assert_equal_sz(10, git_pathspec_match_list_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_USE_CASE, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_fail(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_USE_CASE | GIT_PATHSPEC_NO_MATCH_ERROR, ps));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_IGNORE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(10, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(1, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_USE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(3, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
}
void test_repo_pathspec__workdir2(void)
{
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "staged_*" } */
s.strings = str2; s.count = ARRAY_SIZE(str2);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo, 0, ps));
cl_assert_equal_sz(5, git_pathspec_match_list_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(5, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_fail(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_NO_GLOB | GIT_PATHSPEC_NO_MATCH_ERROR, ps));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_NO_GLOB | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(1, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
}
void test_repo_pathspec__workdir3(void)
{
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "!subdir", "*_file", "new_file" } */
s.strings = str3; s.count = ARRAY_SIZE(str3);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo, 0, ps));
cl_assert_equal_sz(7, git_pathspec_match_list_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_workdir(&m, g_repo,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(7, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("current_file", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("modified_file", git_pathspec_match_list_entry(m, 1));
cl_assert_equal_s("new_file", git_pathspec_match_list_entry(m, 2));
cl_assert_equal_s("staged_changes_modified_file", git_pathspec_match_list_entry(m, 3));
cl_assert_equal_s("staged_delete_modified_file", git_pathspec_match_list_entry(m, 4));
cl_assert_equal_s("staged_new_file", git_pathspec_match_list_entry(m, 5));
cl_assert_equal_s("staged_new_file_modified_file", git_pathspec_match_list_entry(m, 6));
cl_assert_equal_s(NULL, git_pathspec_match_list_entry(m, 7));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
}
void test_repo_pathspec__workdir4(void)
{
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "*" } */
s.strings = str4; s.count = ARRAY_SIZE(str4);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_workdir(&m, g_repo, 0, ps));
cl_assert_equal_sz(13, git_pathspec_match_list_entrycount(m));
cl_assert_equal_s("\xE8\xBF\x99", git_pathspec_match_list_entry(m, 12));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
}
void test_repo_pathspec__index0(void)
{
git_index *idx;
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
cl_git_pass(git_repository_index(&idx, g_repo));
/* { "*_file", "new_file", "garbage" } */
s.strings = str0; s.count = ARRAY_SIZE(str0);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_index(&m, idx, 0, ps));
cl_assert_equal_sz(9, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("current_file", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("modified_file", git_pathspec_match_list_entry(m, 1));
cl_assert_equal_s("staged_changes_modified_file", git_pathspec_match_list_entry(m, 2));
cl_assert_equal_s("staged_new_file", git_pathspec_match_list_entry(m, 3));
cl_assert_equal_s("staged_new_file_deleted_file", git_pathspec_match_list_entry(m, 4));
cl_assert_equal_s("staged_new_file_modified_file", git_pathspec_match_list_entry(m, 5));
cl_assert_equal_s("subdir/current_file", git_pathspec_match_list_entry(m, 6));
cl_assert_equal_s("subdir/deleted_file", git_pathspec_match_list_entry(m, 7));
cl_assert_equal_s("subdir/modified_file", git_pathspec_match_list_entry(m, 8));
cl_assert_equal_s(NULL, git_pathspec_match_list_entry(m, 9));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_index(&m, idx,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(9, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(2, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("new_file", git_pathspec_match_list_failed_entry(m, 0));
cl_assert_equal_s("garbage", git_pathspec_match_list_failed_entry(m, 1));
cl_assert_equal_s(NULL, git_pathspec_match_list_failed_entry(m, 2));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
git_index_free(idx);
}
void test_repo_pathspec__index1(void)
{
/* Currently the USE_CASE and IGNORE_CASE flags don't work on the
* index because the index sort order for the index iterator is
* set by the index itself. I think the correct fix is for the
* index not to embed a global sort order but to support traversal
* in either case sensitive or insensitive order in a stateless
* manner.
*
* Anyhow, as it is, there is no point in doing this test.
*/
#if 0
git_index *idx;
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
cl_git_pass(git_repository_index(&idx, g_repo));
/* { "*_FILE", "NEW_FILE", "GARBAGE" } */
s.strings = str1; s.count = ARRAY_SIZE(str1);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_pathspec_match_index(&m, idx,
GIT_PATHSPEC_USE_CASE, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_index(&m, idx,
GIT_PATHSPEC_USE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(3, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_index(&m, idx,
GIT_PATHSPEC_IGNORE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(10, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(2, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_pathspec_free(ps);
git_index_free(idx);
#endif
}
void test_repo_pathspec__tree0(void)
{
git_object *tree;
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "*_file", "new_file", "garbage" } */
s.strings = str0; s.count = ARRAY_SIZE(str0);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_revparse_single(&tree, g_repo, "HEAD~2^{tree}"));
cl_git_pass(git_pathspec_match_tree(&m, (git_tree *)tree,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(4, git_pathspec_match_list_entrycount(m));
cl_assert_equal_s("current_file", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("modified_file", git_pathspec_match_list_entry(m, 1));
cl_assert_equal_s("staged_changes_modified_file", git_pathspec_match_list_entry(m, 2));
cl_assert_equal_s("staged_delete_modified_file", git_pathspec_match_list_entry(m, 3));
cl_assert_equal_s(NULL, git_pathspec_match_list_entry(m, 4));
cl_assert_equal_sz(2, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("new_file", git_pathspec_match_list_failed_entry(m, 0));
cl_assert_equal_s("garbage", git_pathspec_match_list_failed_entry(m, 1));
cl_assert_equal_s(NULL, git_pathspec_match_list_failed_entry(m, 2));
git_pathspec_match_list_free(m);
git_object_free(tree);
cl_git_pass(git_revparse_single(&tree, g_repo, "HEAD^{tree}"));
cl_git_pass(git_pathspec_match_tree(&m, (git_tree *)tree,
GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(7, git_pathspec_match_list_entrycount(m));
cl_assert_equal_s("current_file", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("modified_file", git_pathspec_match_list_entry(m, 1));
cl_assert_equal_s("staged_changes_modified_file", git_pathspec_match_list_entry(m, 2));
cl_assert_equal_s("staged_delete_modified_file", git_pathspec_match_list_entry(m, 3));
cl_assert_equal_s("subdir/current_file", git_pathspec_match_list_entry(m, 4));
cl_assert_equal_s("subdir/deleted_file", git_pathspec_match_list_entry(m, 5));
cl_assert_equal_s("subdir/modified_file", git_pathspec_match_list_entry(m, 6));
cl_assert_equal_s(NULL, git_pathspec_match_list_entry(m, 7));
cl_assert_equal_sz(2, git_pathspec_match_list_failed_entrycount(m));
cl_assert_equal_s("new_file", git_pathspec_match_list_failed_entry(m, 0));
cl_assert_equal_s("garbage", git_pathspec_match_list_failed_entry(m, 1));
cl_assert_equal_s(NULL, git_pathspec_match_list_failed_entry(m, 2));
git_pathspec_match_list_free(m);
git_object_free(tree);
git_pathspec_free(ps);
}
void test_repo_pathspec__tree5(void)
{
git_object *tree;
git_strarray s;
git_pathspec *ps;
git_pathspec_match_list *m;
/* { "S*" } */
s.strings = str5; s.count = ARRAY_SIZE(str5);
cl_git_pass(git_pathspec_new(&ps, &s));
cl_git_pass(git_revparse_single(&tree, g_repo, "HEAD~2^{tree}"));
cl_git_pass(git_pathspec_match_tree(&m, (git_tree *)tree,
GIT_PATHSPEC_USE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(0, git_pathspec_match_list_entrycount(m));
cl_assert_equal_sz(1, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
cl_git_pass(git_pathspec_match_tree(&m, (git_tree *)tree,
GIT_PATHSPEC_IGNORE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(5, git_pathspec_match_list_entrycount(m));
cl_assert_equal_s("staged_changes", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("staged_delete_modified_file", git_pathspec_match_list_entry(m, 4));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_object_free(tree);
cl_git_pass(git_revparse_single(&tree, g_repo, "HEAD^{tree}"));
cl_git_pass(git_pathspec_match_tree(&m, (git_tree *)tree,
GIT_PATHSPEC_IGNORE_CASE | GIT_PATHSPEC_FIND_FAILURES, ps));
cl_assert_equal_sz(9, git_pathspec_match_list_entrycount(m));
cl_assert_equal_s("staged_changes", git_pathspec_match_list_entry(m, 0));
cl_assert_equal_s("subdir.txt", git_pathspec_match_list_entry(m, 5));
cl_assert_equal_s("subdir/current_file", git_pathspec_match_list_entry(m, 6));
cl_assert_equal_sz(0, git_pathspec_match_list_failed_entrycount(m));
git_pathspec_match_list_free(m);
git_object_free(tree);
git_pathspec_free(ps);
}
void test_repo_pathspec__in_memory(void)
{
static char *strings[] = { "one", "two*", "!three*", "*four" };
git_strarray s = { strings, ARRAY_SIZE(strings) };
git_pathspec *ps;
cl_git_pass(git_pathspec_new(&ps, &s));
cl_assert(git_pathspec_matches_path(ps, 0, "one"));
cl_assert(!git_pathspec_matches_path(ps, 0, "ONE"));
cl_assert(git_pathspec_matches_path(ps, GIT_PATHSPEC_IGNORE_CASE, "ONE"));
cl_assert(git_pathspec_matches_path(ps, 0, "two"));
cl_assert(git_pathspec_matches_path(ps, 0, "two.txt"));
cl_assert(!git_pathspec_matches_path(ps, 0, "three.txt"));
cl_assert(git_pathspec_matches_path(ps, 0, "anything.four"));
cl_assert(!git_pathspec_matches_path(ps, 0, "three.four"));
cl_assert(!git_pathspec_matches_path(ps, 0, "nomatch"));
cl_assert(!git_pathspec_matches_path(ps, GIT_PATHSPEC_NO_GLOB, "two"));
cl_assert(git_pathspec_matches_path(ps, GIT_PATHSPEC_NO_GLOB, "two*"));
cl_assert(!git_pathspec_matches_path(ps, GIT_PATHSPEC_NO_GLOB, "anyfour"));
cl_assert(git_pathspec_matches_path(ps, GIT_PATHSPEC_NO_GLOB, "*four"));
git_pathspec_free(ps);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/shallow.c
|
#include "clar_libgit2.h"
#include "futils.h"
static git_repository *g_repo;
void test_repo_shallow__initialize(void)
{
}
void test_repo_shallow__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_shallow__no_shallow_file(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__empty_shallow_file(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_git_mkfile("testrepo.git/shallow", "");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__shallow_repo(void)
{
g_repo = cl_git_sandbox_init("shallow.git");
cl_assert_equal_i(1, git_repository_is_shallow(g_repo));
}
void test_repo_shallow__clears_errors(void)
{
g_repo = cl_git_sandbox_init("testrepo.git");
cl_assert_equal_i(0, git_repository_is_shallow(g_repo));
cl_assert_equal_p(NULL, git_error_last());
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/reservedname.c
|
#include "clar_libgit2.h"
#include "../submodule/submodule_helpers.h"
#include "repository.h"
void test_repo_reservedname__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_reservedname__includes_shortname_on_win32(void)
{
git_repository *repo;
git_buf *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, false));
#ifdef GIT_WIN32
cl_assert_equal_i(2, reserved_len);
cl_assert_equal_s(".git", reserved[0].ptr);
cl_assert_equal_s("GIT~1", reserved[1].ptr);
#else
cl_assert_equal_i(1, reserved_len);
cl_assert_equal_s(".git", reserved[0].ptr);
#endif
}
void test_repo_reservedname__includes_shortname_when_requested(void)
{
git_repository *repo;
git_buf *reserved;
size_t reserved_len;
repo = cl_git_sandbox_init("nasty");
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
cl_assert_equal_i(2, reserved_len);
cl_assert_equal_s(".git", reserved[0].ptr);
cl_assert_equal_s("GIT~1", reserved[1].ptr);
}
/* Ensures that custom shortnames are included: creates a GIT~1 so that the
* .git folder itself will have to be named GIT~2
*/
void test_repo_reservedname__custom_shortname_recognized(void)
{
#ifdef GIT_WIN32
git_repository *repo;
git_buf *reserved;
size_t reserved_len;
if (!cl_sandbox_supports_8dot3())
clar__skip();
repo = cl_git_sandbox_init("nasty");
cl_must_pass(p_rename("nasty/.git", "nasty/_temp"));
cl_git_write2file("nasty/git~1", "", 0, O_RDWR|O_CREAT, 0666);
cl_must_pass(p_rename("nasty/_temp", "nasty/.git"));
cl_assert(git_repository__reserved_names(&reserved, &reserved_len, repo, true));
cl_assert_equal_i(3, reserved_len);
cl_assert_equal_s(".git", reserved[0].ptr);
cl_assert_equal_s("GIT~1", reserved[1].ptr);
cl_assert_equal_s("GIT~2", reserved[2].ptr);
#endif
}
/* When looking at the short name for a submodule, we need to prevent
* people from overwriting the `.git` file in the submodule working
* directory itself. We don't want to look at the actual repository
* path, since it will be in the super's repository above us, and
* typically named with the name of our subrepository. Consequently,
* preventing access to the short name of the actual repository path
* would prevent us from creating files with the same name as the
* subrepo. (Eg, a submodule named "libgit2" could not contain a file
* named "libgit2", which would be unfortunate.)
*/
void test_repo_reservedname__submodule_pointer(void)
{
#ifdef GIT_WIN32
git_repository *super_repo, *sub_repo;
git_submodule *sub;
git_buf *sub_reserved;
size_t sub_reserved_len;
if (!cl_sandbox_supports_8dot3())
clar__skip();
super_repo = setup_fixture_submod2();
assert_submodule_exists(super_repo, "sm_unchanged");
cl_git_pass(git_submodule_lookup(&sub, super_repo, "sm_unchanged"));
cl_git_pass(git_submodule_open(&sub_repo, sub));
cl_assert(git_repository__reserved_names(&sub_reserved, &sub_reserved_len, sub_repo, true));
cl_assert_equal_i(2, sub_reserved_len);
cl_assert_equal_s(".git", sub_reserved[0].ptr);
cl_assert_equal_s("GIT~1", sub_reserved[1].ptr);
git_submodule_free(sub);
git_repository_free(sub_repo);
#endif
}
/* Like the `submodule_pointer` test (above), this ensures that we do not
* follow the gitlink to the submodule's repository location and treat that
* as a reserved name. This tests at an initial submodule update, where the
* submodule repo is being created.
*/
void test_repo_reservedname__submodule_pointer_during_create(void)
{
git_repository *repo;
git_submodule *sm;
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
git_buf url = GIT_BUF_INIT;
repo = setup_fixture_super();
cl_git_pass(git_buf_joinpath(&url, clar_sandbox_path(), "sub.git"));
cl_repo_set_string(repo, "submodule.sub.url", url.ptr);
cl_git_pass(git_submodule_lookup(&sm, repo, "sub"));
cl_git_pass(git_submodule_update(sm, 1, &update_options));
git_submodule_free(sm);
git_buf_dispose(&url);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/repo_helpers.h
|
#include "common.h"
#define NON_EXISTING_HEAD "refs/heads/hide/and/seek"
extern void make_head_unborn(git_repository* repo, const char *target);
extern void delete_head(git_repository* repo);
extern void create_tmp_global_config(const char *path, const char *key, const char *val);
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/head.c
|
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"
#include "git2/annotated_commit.h"
static const char *g_email = "[email protected]";
static git_repository *repo;
void test_repo_head__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_set_ident(repo, "Foo Bar", g_email));
}
void test_repo_head__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_head__unborn_head(void)
{
git_reference *ref;
cl_git_pass(git_repository_head_detached(repo));
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert(git_repository_head_unborn(repo) == 1);
/* take the repo back to it's original state */
cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1, NULL));
cl_assert(git_repository_head_unborn(repo) == 0);
git_reference_free(ref);
}
void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_doesnt_exist(void)
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet"));
}
void test_repo_head__set_head_Fails_when_the_reference_points_to_a_non_commitish(void)
{
cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob"));
}
void test_repo_head__set_head_Attaches_HEAD_when_the_reference_points_to_a_branch(void)
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/br2"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_head(&head, repo));
cl_assert_equal_s("refs/heads/br2", git_reference_name(head));
git_reference_free(head);
}
static void assert_head_is_correctly_detached(void)
{
git_reference *head;
git_object *commit;
cl_assert_equal_i(true, git_repository_head_detached(repo));
cl_git_pass(git_repository_head(&head, repo));
cl_git_pass(git_object_lookup(&commit, repo, git_reference_target(head), GIT_OBJECT_COMMIT));
git_object_free(commit);
git_reference_free(head);
}
void test_repo_head__set_head_Detaches_HEAD_when_the_reference_doesnt_point_to_a_branch(void)
{
cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
cl_assert_equal_i(true, git_repository_head_detached(repo));
assert_head_is_correctly_detached();
}
void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_exist(void)
{
git_oid oid;
cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid));
}
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
{
git_object *blob;
cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));
cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));
git_object_free(blob);
}
void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
{
git_object *tag;
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_assert_equal_i(GIT_OBJECT_TAG, git_object_type(tag));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
assert_head_is_correctly_detached();
git_object_free(tag);
}
void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_commit(void)
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_detach_head(repo));
assert_head_is_correctly_detached();
}
void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void)
{
git_reference *head;
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL));
cl_git_fail(git_repository_detach_head(repo));
git_reference_free(head);
}
void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo));
}
void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
git_reference *head;
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo));
}
void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void)
{
git_reference *head;
delete_head(repo);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo));
}
void test_repo_head__can_tell_if_an_unborn_head_is_detached(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(false, git_repository_head_detached(repo));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/template.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "repo/repo_helpers.h"
#define CLEAR_FOR_CORE_FILEMODE(M) ((M) &= ~0177)
static git_repository *_repo = NULL;
static mode_t g_umask = 0;
static git_buf _global_path = GIT_BUF_INIT;
static const char *fixture_repo;
static const char *fixture_templates;
void test_repo_template__initialize(void)
{
_repo = NULL;
/* load umask if not already loaded */
if (!g_umask) {
g_umask = p_umask(022);
(void)p_umask(g_umask);
}
}
void test_repo_template__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
_global_path.ptr);
git_buf_dispose(&_global_path);
cl_fixture_cleanup("tmp_global_path");
if (fixture_repo) {
cl_fixture_cleanup(fixture_repo);
fixture_repo = NULL;
}
if (fixture_templates) {
cl_fixture_cleanup(fixture_templates);
fixture_templates = NULL;
}
git_repository_free(_repo);
_repo = NULL;
}
static void assert_hooks_match(
const char *template_dir,
const char *repo_dir,
const char *hook_path,
bool core_filemode)
{
git_buf expected = GIT_BUF_INIT;
git_buf actual = GIT_BUF_INIT;
struct stat expected_st, st;
cl_git_pass(git_buf_joinpath(&expected, template_dir, hook_path));
cl_git_pass(git_path_lstat(expected.ptr, &expected_st));
cl_git_pass(git_buf_joinpath(&actual, repo_dir, hook_path));
cl_git_pass(git_path_lstat(actual.ptr, &st));
cl_assert(expected_st.st_size == st.st_size);
if (GIT_MODE_TYPE(expected_st.st_mode) != GIT_FILEMODE_LINK) {
mode_t expected_mode =
GIT_MODE_TYPE(expected_st.st_mode) |
(GIT_PERMS_FOR_WRITE(expected_st.st_mode) & ~g_umask);
if (!core_filemode) {
CLEAR_FOR_CORE_FILEMODE(expected_mode);
CLEAR_FOR_CORE_FILEMODE(st.st_mode);
}
cl_assert_equal_i_fmt(expected_mode, st.st_mode, "%07o");
}
git_buf_dispose(&expected);
git_buf_dispose(&actual);
}
static void assert_mode_seems_okay(
const char *base, const char *path,
git_filemode_t expect_mode, bool expect_setgid, bool core_filemode)
{
git_buf full = GIT_BUF_INIT;
struct stat st;
cl_git_pass(git_buf_joinpath(&full, base, path));
cl_git_pass(git_path_lstat(full.ptr, &st));
git_buf_dispose(&full);
if (!core_filemode) {
CLEAR_FOR_CORE_FILEMODE(expect_mode);
CLEAR_FOR_CORE_FILEMODE(st.st_mode);
expect_setgid = false;
}
if (S_ISGID != 0)
cl_assert_equal_b(expect_setgid, (st.st_mode & S_ISGID) != 0);
cl_assert_equal_b(
GIT_PERMS_IS_EXEC(expect_mode), GIT_PERMS_IS_EXEC(st.st_mode));
cl_assert_equal_i_fmt(
GIT_MODE_TYPE(expect_mode), GIT_MODE_TYPE(st.st_mode), "%07o");
}
static void setup_repo(const char *name, git_repository_init_options *opts)
{
cl_git_pass(git_repository_init_ext(&_repo, name, opts));
fixture_repo = name;
}
static void setup_templates(const char *name, bool setup_globally)
{
git_buf path = GIT_BUF_INIT;
cl_fixture_sandbox("template");
if (strcmp(name, "template"))
cl_must_pass(p_rename("template", name));
fixture_templates = name;
/*
* Create a symlink from link.sample to update.sample if the filesystem
* supports it.
*/
cl_git_pass(git_buf_join3(&path, '/', name, "hooks", "link.sample"));
#ifdef GIT_WIN32
cl_git_mkfile(path.ptr, "#!/bin/sh\necho hello, world\n");
#else
cl_must_pass(p_symlink("update.sample", path.ptr));
#endif
git_buf_clear(&path);
/* Create a file starting with a dot */
cl_git_pass(git_buf_join3(&path, '/', name, "hooks", ".dotfile"));
cl_git_mkfile(path.ptr, "something\n");
git_buf_clear(&path);
if (setup_globally) {
cl_git_pass(git_buf_joinpath(&path, clar_sandbox_path(), name));
create_tmp_global_config("tmp_global_path", "init.templatedir", path.ptr);
}
git_buf_dispose(&path);
}
static void validate_templates(git_repository *repo, const char *template_path)
{
git_buf path = GIT_BUF_INIT, expected = GIT_BUF_INIT, actual = GIT_BUF_INIT;
int filemode;
cl_git_pass(git_buf_joinpath(&path, template_path, "description"));
cl_git_pass(git_futils_readbuffer(&expected, path.ptr));
git_buf_clear(&path);
cl_git_pass(git_buf_joinpath(&path, git_repository_path(repo), "description"));
cl_git_pass(git_futils_readbuffer(&actual, path.ptr));
cl_assert_equal_s(expected.ptr, actual.ptr);
filemode = cl_repo_get_bool(repo, "core.filemode");
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/update.sample", filemode);
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/link.sample", filemode);
assert_hooks_match(
template_path, git_repository_path(repo),
"hooks/.dotfile", filemode);
git_buf_dispose(&expected);
git_buf_dispose(&actual);
git_buf_dispose(&path);
}
void test_repo_template__external_templates_specified_in_options(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.template_path = "template";
setup_templates("template", false);
setup_repo("templated.git", &opts);
validate_templates(_repo, "template");
}
void test_repo_template__external_templates_specified_in_config(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
setup_templates("template", true);
setup_repo("templated.git", &opts);
validate_templates(_repo, "template");
}
void test_repo_template__external_templates_with_leading_dot(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE |
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
setup_templates(".template_with_leading_dot", true);
setup_repo("templated.git", &opts);
validate_templates(_repo, ".template_with_leading_dot");
}
void test_repo_template__extended_with_template_and_shared_mode(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
const char *repo_path;
int filemode;
opts.flags = GIT_REPOSITORY_INIT_MKPATH |
GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.template_path = "template";
opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
setup_templates("template", false);
setup_repo("init_shared_from_tpl", &opts);
filemode = cl_repo_get_bool(_repo, "core.filemode");
repo_path = git_repository_path(_repo);
assert_mode_seems_okay(repo_path, "hooks",
GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
assert_mode_seems_okay(repo_path, "info",
GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode);
assert_mode_seems_okay(repo_path, "description",
GIT_FILEMODE_BLOB, false, filemode);
validate_templates(_repo, "template");
}
void test_repo_template__templated_head_is_used(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_buf head = GIT_BUF_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
setup_templates("template", true);
cl_git_mkfile("template/HEAD", "foobar\n");
setup_repo("repo", &opts);
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("foobar\n", head.ptr);
git_buf_dispose(&head);
}
void test_repo_template__initial_head_option_overrides_template_head(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_buf head = GIT_BUF_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.initial_head = "manual";
setup_templates("template", true);
cl_git_mkfile("template/HEAD", "foobar\n");
setup_repo("repo", &opts);
cl_git_pass(git_futils_readbuffer(&head, "repo/.git/HEAD"));
cl_assert_equal_s("ref: refs/heads/manual\n", head.ptr);
git_buf_dispose(&head);
}
void test_repo_template__empty_template_path(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE;
opts.template_path = "";
setup_repo("foo", &opts);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/init.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "repository.h"
#include "config.h"
#include "path.h"
#include "config/config_helpers.h"
#include "repo/repo_helpers.h"
enum repo_mode {
STANDARD_REPOSITORY = 0,
BARE_REPOSITORY = 1
};
static git_repository *g_repo = NULL;
static git_buf g_global_path = GIT_BUF_INIT;
void test_repo_init__initialize(void)
{
g_repo = NULL;
git_libgit2_opts(GIT_OPT_GET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
&g_global_path);
}
void test_repo_init__cleanup(void)
{
git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL,
g_global_path.ptr);
git_buf_dispose(&g_global_path);
cl_fixture_cleanup("tmp_global_path");
}
static void cleanup_repository(void *path)
{
git_repository_free(g_repo);
g_repo = NULL;
cl_fixture_cleanup((const char *)path);
}
static void ensure_repository_init(
const char *working_directory,
int is_bare,
const char *expected_path_repository,
const char *expected_working_directory)
{
const char *workdir;
cl_assert(!git_path_isdir(working_directory));
cl_git_pass(git_repository_init(&g_repo, working_directory, is_bare));
workdir = git_repository_workdir(g_repo);
if (workdir != NULL || expected_working_directory != NULL) {
cl_assert(
git__suffixcmp(workdir, expected_working_directory) == 0
);
}
cl_assert(
git__suffixcmp(git_repository_path(g_repo), expected_path_repository) == 0
);
cl_assert(git_repository_is_bare(g_repo) == is_bare);
#ifdef GIT_WIN32
if (!is_bare) {
DWORD fattrs = GetFileAttributes(git_repository_path(g_repo));
cl_assert((fattrs & FILE_ATTRIBUTE_HIDDEN) != 0);
}
#endif
cl_assert(git_repository_is_empty(g_repo));
}
void test_repo_init__standard_repo(void)
{
cl_set_cleanup(&cleanup_repository, "testrepo");
ensure_repository_init("testrepo/", 0, "testrepo/.git/", "testrepo/");
}
void test_repo_init__standard_repo_noslash(void)
{
cl_set_cleanup(&cleanup_repository, "testrepo");
ensure_repository_init("testrepo", 0, "testrepo/.git/", "testrepo/");
}
void test_repo_init__bare_repo(void)
{
cl_set_cleanup(&cleanup_repository, "testrepo.git");
ensure_repository_init("testrepo.git/", 1, "testrepo.git/", NULL);
}
void test_repo_init__bare_repo_noslash(void)
{
cl_set_cleanup(&cleanup_repository, "testrepo.git");
ensure_repository_init("testrepo.git", 1, "testrepo.git/", NULL);
}
void test_repo_init__bare_repo_escaping_current_workdir(void)
{
git_buf path_repository = GIT_BUF_INIT;
git_buf path_current_workdir = GIT_BUF_INIT;
cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL));
cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c"));
cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), GIT_DIR_MODE));
/* Change the current working directory */
cl_git_pass(chdir(git_buf_cstr(&path_repository)));
/* Initialize a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_init(&g_repo, "../d/e.git", 1));
cl_git_pass(git__suffixcmp(git_repository_path(g_repo), "/a/b/d/e.git/"));
git_repository_free(g_repo);
g_repo = NULL;
/* Open a bare repo with a relative path escaping out of the current working directory */
cl_git_pass(git_repository_open(&g_repo, "../d/e.git"));
cl_git_pass(chdir(git_buf_cstr(&path_current_workdir)));
git_buf_dispose(&path_current_workdir);
git_buf_dispose(&path_repository);
cleanup_repository("a");
}
void test_repo_init__reinit_bare_repo(void)
{
cl_set_cleanup(&cleanup_repository, "reinit.git");
/* Initialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
git_repository_free(g_repo);
g_repo = NULL;
/* Reinitialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
}
void test_repo_init__reinit_too_recent_bare_repo(void)
{
git_config *config;
/* Initialize the repository */
cl_git_pass(git_repository_init(&g_repo, "reinit.git", 1));
git_repository_config(&config, g_repo);
/*
* Hack the config of the repository to make it look like it has
* been created by a recenter version of git/libgit2
*/
cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 42));
git_config_free(config);
git_repository_free(g_repo);
g_repo = NULL;
/* Try to reinitialize the repository */
cl_git_fail(git_repository_init(&g_repo, "reinit.git", 1));
cl_fixture_cleanup("reinit.git");
}
void test_repo_init__additional_templates(void)
{
git_buf path = GIT_BUF_INIT;
cl_set_cleanup(&cleanup_repository, "tester");
ensure_repository_init("tester", 0, "tester/.git/", "tester/");
cl_git_pass(
git_buf_joinpath(&path, git_repository_path(g_repo), "description"));
cl_assert(git_path_isfile(git_buf_cstr(&path)));
cl_git_pass(
git_buf_joinpath(&path, git_repository_path(g_repo), "info/exclude"));
cl_assert(git_path_isfile(git_buf_cstr(&path)));
cl_git_pass(
git_buf_joinpath(&path, git_repository_path(g_repo), "hooks"));
cl_assert(git_path_isdir(git_buf_cstr(&path)));
/* won't confirm specific contents of hooks dir since it may vary */
git_buf_dispose(&path);
}
static void assert_config_entry_on_init_bytype(
const char *config_key, int expected_value, bool is_bare)
{
git_config *config;
int error, current_value;
const char *repo_path = is_bare ?
"config_entry/test.bare.git" : "config_entry/test.non.bare.git";
cl_set_cleanup(&cleanup_repository, "config_entry");
cl_git_pass(git_repository_init(&g_repo, repo_path, is_bare));
cl_git_pass(git_repository_config(&config, g_repo));
error = git_config_get_bool(¤t_value, config, config_key);
git_config_free(config);
if (expected_value >= 0) {
cl_assert_equal_i(0, error);
cl_assert_equal_i(expected_value, current_value);
} else {
cl_assert_equal_i(expected_value, error);
}
}
static void assert_config_entry_on_init(
const char *config_key, int expected_value)
{
assert_config_entry_on_init_bytype(config_key, expected_value, true);
git_repository_free(g_repo);
g_repo = NULL;
assert_config_entry_on_init_bytype(config_key, expected_value, false);
}
void test_repo_init__detect_filemode(void)
{
assert_config_entry_on_init("core.filemode", cl_is_chmod_supported());
}
void test_repo_init__detect_ignorecase(void)
{
struct stat st;
bool found_without_match;
cl_git_write2file("testCAPS", "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
found_without_match = (p_stat("Testcaps", &st) == 0);
cl_must_pass(p_unlink("testCAPS"));
assert_config_entry_on_init(
"core.ignorecase", found_without_match ? true : GIT_ENOTFOUND);
}
/*
* Windows: if the filesystem supports symlinks (because we're running
* as administrator, or because the user has opted into it for normal
* users) then we can also opt-in explicitly by settings `core.symlinks`
* in the global config. Symlinks remain off by default.
*/
void test_repo_init__symlinks_win32_enabled_by_global_config(void)
{
#ifndef GIT_WIN32
cl_skip();
#else
git_config *config, *repo_config;
int val;
if (!git_path_supports_symlinks("link"))
cl_skip();
create_tmp_global_config("tmp_global_config", "core.symlinks", "true");
/*
* Create a new repository (can't use `assert_config_on_init` since we
* want to examine configuration levels with more granularity.)
*/
cl_git_pass(git_repository_init(&g_repo, "config_entry/test.non.bare.git", false));
/* Ensure that core.symlinks remains set (via the global config). */
cl_git_pass(git_repository_config(&config, g_repo));
cl_git_pass(git_config_get_bool(&val, config, "core.symlinks"));
cl_assert_equal_i(1, val);
/*
* Ensure that the repository config does not set core.symlinks.
* It should remain inherited.
*/
cl_git_pass(git_config_open_level(&repo_config, config, GIT_CONFIG_LEVEL_LOCAL));
cl_git_fail_with(GIT_ENOTFOUND, git_config_get_bool(&val, repo_config, "core.symlinks"));
git_config_free(repo_config);
git_config_free(config);
git_repository_free(g_repo);
g_repo = NULL;
#endif
}
void test_repo_init__symlinks_win32_off_by_default(void)
{
#ifndef GIT_WIN32
cl_skip();
#else
assert_config_entry_on_init("core.symlinks", false);
#endif
}
void test_repo_init__symlinks_posix_detected(void)
{
#ifdef GIT_WIN32
cl_skip();
#else
assert_config_entry_on_init(
"core.symlinks", git_path_supports_symlinks("link") ? GIT_ENOTFOUND : false);
#endif
}
void test_repo_init__detect_precompose_unicode_required(void)
{
#ifdef GIT_USE_ICONV
char *composed = "ḱṷṓn", *decomposed = "ḱṷṓn";
struct stat st;
bool found_with_nfd;
cl_git_write2file(composed, "whatever\n", 0, O_CREAT | O_WRONLY, 0666);
found_with_nfd = (p_stat(decomposed, &st) == 0);
cl_must_pass(p_unlink(composed));
assert_config_entry_on_init("core.precomposeunicode", found_with_nfd);
#else
assert_config_entry_on_init("core.precomposeunicode", GIT_ENOTFOUND);
#endif
}
void test_repo_init__reinit_doesnot_overwrite_ignorecase(void)
{
git_config *config;
int current_value;
/* Init a new repo */
cl_set_cleanup(&cleanup_repository, "not.overwrite.git");
cl_git_pass(git_repository_init(&g_repo, "not.overwrite.git", 1));
/* Change the "core.ignorecase" config value to something unlikely */
git_repository_config(&config, g_repo);
git_config_set_int32(config, "core.ignorecase", 42);
git_config_free(config);
git_repository_free(g_repo);
g_repo = NULL;
/* Reinit the repository */
cl_git_pass(git_repository_init(&g_repo, "not.overwrite.git", 1));
git_repository_config(&config, g_repo);
/* Ensure the "core.ignorecase" config value hasn't been updated */
cl_git_pass(git_config_get_int32(¤t_value, config, "core.ignorecase"));
cl_assert_equal_i(42, current_value);
git_config_free(config);
}
void test_repo_init__reinit_overwrites_filemode(void)
{
int expected = cl_is_chmod_supported(), current_value;
/* Init a new repo */
cl_set_cleanup(&cleanup_repository, "overwrite.git");
cl_git_pass(git_repository_init(&g_repo, "overwrite.git", 1));
/* Change the "core.filemode" config value to something unlikely */
cl_repo_set_bool(g_repo, "core.filemode", !expected);
git_repository_free(g_repo);
g_repo = NULL;
/* Reinit the repository */
cl_git_pass(git_repository_init(&g_repo, "overwrite.git", 1));
/* Ensure the "core.filemode" config value has been reset */
current_value = cl_repo_get_bool(g_repo, "core.filemode");
cl_assert_equal_i(expected, current_value);
}
void test_repo_init__sets_logAllRefUpdates_according_to_type_of_repository(void)
{
assert_config_entry_on_init_bytype("core.logallrefupdates", GIT_ENOTFOUND, true);
git_repository_free(g_repo);
assert_config_entry_on_init_bytype("core.logallrefupdates", true, false);
}
void test_repo_init__extended_0(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
/* without MKDIR this should fail */
cl_git_fail(git_repository_init_ext(&g_repo, "extended", &opts));
/* make the directory first, then it should succeed */
cl_git_pass(git_futils_mkdir("extended", 0775, 0));
cl_git_pass(git_repository_init_ext(&g_repo, "extended", &opts));
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/extended/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/extended/.git/"));
cl_assert(!git_repository_is_bare(g_repo));
cl_assert(git_repository_is_empty(g_repo));
cleanup_repository("extended");
}
void test_repo_init__extended_1(void)
{
git_reference *ref;
git_remote *remote;
struct stat st;
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
opts.flags = GIT_REPOSITORY_INIT_MKPATH |
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP;
opts.workdir_path = "../c_wd";
opts.description = "Awesomest test repository evah";
opts.initial_head = "development";
opts.origin_url = "https://github.com/libgit2/libgit2.git";
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/c.git", &opts));
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "/c_wd/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "/c.git/"));
cl_assert(git_path_isfile("root/b/c_wd/.git"));
cl_assert(!git_repository_is_bare(g_repo));
/* repo will not be counted as empty because we set head to "development" */
cl_assert(!git_repository_is_empty(g_repo));
cl_git_pass(git_path_lstat(git_repository_path(g_repo), &st));
cl_assert(S_ISDIR(st.st_mode));
if (cl_is_chmod_supported())
cl_assert((S_ISGID & st.st_mode) == S_ISGID);
else
cl_assert((S_ISGID & st.st_mode) == 0);
cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD"));
cl_assert(git_reference_type(ref) == GIT_REFERENCE_SYMBOLIC);
cl_assert_equal_s("refs/heads/development", git_reference_symbolic_target(ref));
git_reference_free(ref);
cl_git_pass(git_remote_lookup(&remote, g_repo, "origin"));
cl_assert_equal_s("origin", git_remote_name(remote));
cl_assert_equal_s(opts.origin_url, git_remote_url(remote));
git_remote_free(remote);
git_repository_free(g_repo);
cl_fixture_cleanup("root");
}
void test_repo_init__relative_gitdir(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_buf dot_git_content = GIT_BUF_INIT;
opts.workdir_path = "../c_wd";
opts.flags =
GIT_REPOSITORY_INIT_MKPATH |
GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
/* make the directory first, then it should succeed */
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
cl_assert(!git_repository_is_bare(g_repo));
cl_assert(git_repository_is_empty(g_repo));
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
assert_config_entry_value(g_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_dispose(&dot_git_content);
cleanup_repository("root");
}
void test_repo_init__relative_gitdir_2(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_buf dot_git_content = GIT_BUF_INIT;
git_buf full_path = GIT_BUF_INIT;
cl_git_pass(git_path_prettify(&full_path, ".", NULL));
cl_git_pass(git_buf_joinpath(&full_path, full_path.ptr, "root/b/c_wd"));
opts.workdir_path = full_path.ptr;
opts.flags =
GIT_REPOSITORY_INIT_MKPATH |
GIT_REPOSITORY_INIT_RELATIVE_GITLINK |
GIT_REPOSITORY_INIT_NO_DOTGIT_DIR;
/* make the directory first, then it should succeed */
cl_git_pass(git_repository_init_ext(&g_repo, "root/b/my_repository", &opts));
git_buf_dispose(&full_path);
cl_assert(!git__suffixcmp(git_repository_workdir(g_repo), "root/b/c_wd/"));
cl_assert(!git__suffixcmp(git_repository_path(g_repo), "root/b/my_repository/"));
cl_assert(!git_repository_is_bare(g_repo));
cl_assert(git_repository_is_empty(g_repo));
/* Verify that the gitlink and worktree entries are relative */
/* Verify worktree */
assert_config_entry_value(g_repo, "core.worktree", "../c_wd/");
/* Verify gitlink */
cl_git_pass(git_futils_readbuffer(&dot_git_content, "root/b/c_wd/.git"));
cl_assert_equal_s("gitdir: ../my_repository/", dot_git_content.ptr);
git_buf_dispose(&dot_git_content);
cleanup_repository("root");
}
void test_repo_init__can_reinit_an_initialized_repository(void)
{
git_repository *reinit;
cl_set_cleanup(&cleanup_repository, "extended");
cl_git_pass(git_futils_mkdir("extended", 0775, 0));
cl_git_pass(git_repository_init(&g_repo, "extended", false));
cl_git_pass(git_repository_init(&reinit, "extended", false));
cl_assert_equal_s(git_repository_path(g_repo), git_repository_path(reinit));
git_repository_free(reinit);
}
void test_repo_init__init_with_initial_commit(void)
{
git_index *index;
cl_set_cleanup(&cleanup_repository, "committed");
/* Initialize the repository */
cl_git_pass(git_repository_init(&g_repo, "committed", 0));
/* Index will be automatically created when requested for a new repo */
cl_git_pass(git_repository_index(&index, g_repo));
/* Create a file so we can commit it
*
* If you are writing code outside the test suite, you can create this
* file any way that you like, such as:
* FILE *fp = fopen("committed/file.txt", "w");
* fputs("some stuff\n", fp);
* fclose(fp);
* We like to use the help functions because they do error detection
* in a way that's easily compatible with our test suite.
*/
cl_git_mkfile("committed/file.txt", "some stuff\n");
/* Add file to the index */
cl_git_pass(git_index_add_bypath(index, "file.txt"));
cl_git_pass(git_index_write(index));
/* Intentionally not using cl_repo_commit_from_index here so this code
* can be used as an example of how an initial commit is typically
* made to a repository...
*/
/* Make sure we're ready to use git_signature_default :-) */
{
git_config *cfg, *local;
cl_git_pass(git_repository_config(&cfg, g_repo));
cl_git_pass(git_config_open_level(&local, cfg, GIT_CONFIG_LEVEL_LOCAL));
cl_git_pass(git_config_set_string(local, "user.name", "Test User"));
cl_git_pass(git_config_set_string(local, "user.email", "[email protected]"));
git_config_free(local);
git_config_free(cfg);
}
/* Create a commit with the new contents of the index */
{
git_signature *sig;
git_oid tree_id, commit_id;
git_tree *tree;
cl_git_pass(git_signature_default(&sig, g_repo));
cl_git_pass(git_index_write_tree(&tree_id, index));
cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id));
cl_git_pass(git_commit_create_v(
&commit_id, g_repo, "HEAD", sig, sig,
NULL, "First", tree, 0));
git_tree_free(tree);
git_signature_free(sig);
}
git_index_free(index);
}
void test_repo_init__at_filesystem_root(void)
{
git_repository *repo;
const char *sandbox = clar_sandbox_path();
git_buf root = GIT_BUF_INIT;
int root_len;
if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE"))
cl_skip();
root_len = git_path_root(sandbox);
cl_assert(root_len >= 0);
git_buf_put(&root, sandbox, root_len+1);
git_buf_joinpath(&root, root.ptr, "libgit2_test_dir");
cl_assert(!git_path_exists(root.ptr));
cl_git_pass(git_repository_init(&repo, root.ptr, 0));
cl_assert(git_path_isdir(root.ptr));
cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES));
git_buf_dispose(&root);
git_repository_free(repo);
}
void test_repo_init__nonexisting_directory(void)
{
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
git_repository *repo;
/*
* If creating a repo with non-existing parent directories, then libgit2
* will by default create the complete directory hierarchy if using
* `git_repository_init`. Thus, let's use the extended version and not
* set the `GIT_REPOSITORY_INIT_MKPATH` flag.
*/
cl_git_fail(git_repository_init_ext(&repo, "nonexisting/path", &opts));
}
void test_repo_init__nonexisting_root(void)
{
#ifdef GIT_WIN32
git_repository *repo;
/*
* This really only depends on the nonexistence of the Q: drive. We
* cannot implement the equivalent test on Unix systems, as there is
* fundamentally no path that is disconnected from the root directory.
*/
cl_git_fail(git_repository_init(&repo, "Q:/non/existent/path", 0));
cl_git_fail(git_repository_init(&repo, "Q:\\non\\existent\\path", 0));
#else
clar__skip();
#endif
}
void test_repo_init__unwriteable_directory(void)
{
#ifndef GIT_WIN32
git_repository *repo;
if (geteuid() == 0)
clar__skip();
/*
* Create a non-writeable directory so that we cannot create directories
* inside of it. The root user has CAP_DAC_OVERRIDE, so he doesn't care
* for the directory permissions and thus we need to skip the test if
* run as root user.
*/
cl_must_pass(p_mkdir("unwriteable", 0444));
cl_git_fail(git_repository_init(&repo, "unwriteable/repo", 0));
cl_must_pass(p_rmdir("unwriteable"));
#else
clar__skip();
#endif
}
void test_repo_init__defaultbranch_config(void)
{
git_reference *head;
cl_set_cleanup(&cleanup_repository, "repo");
create_tmp_global_config("tmp_global_path", "init.defaultbranch", "my_default_branch");
cl_git_pass(git_repository_init(&g_repo, "repo", 0));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert_equal_s("refs/heads/my_default_branch", git_reference_symbolic_target(head));
git_reference_free(head);
}
void test_repo_init__defaultbranch_config_empty(void)
{
git_reference *head;
cl_set_cleanup(&cleanup_repository, "repo");
create_tmp_global_config("tmp_global_path", "init.defaultbranch", "");
cl_git_pass(git_repository_init(&g_repo, "repo", 0));
cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head));
git_reference_free(head);
}
void test_repo_init__longpath(void)
{
#ifdef GIT_WIN32
size_t padding = CONST_STRLEN("objects/pack/pack-.pack.lock") + GIT_OID_HEXSZ;
size_t max, i;
git_buf path = GIT_BUF_INIT;
git_repository *one = NULL, *two = NULL;
/*
* Files within repositories need to fit within MAX_PATH;
* that means a repo path must be at most (MAX_PATH - 18).
*/
cl_git_pass(git_buf_puts(&path, clar_sandbox_path()));
cl_git_pass(git_buf_putc(&path, '/'));
max = ((MAX_PATH) - path.size) - padding;
for (i = 0; i < max - 1; i++)
cl_git_pass(git_buf_putc(&path, 'a'));
cl_git_pass(git_repository_init(&one, path.ptr, 1));
/* Paths longer than this are rejected */
cl_git_pass(git_buf_putc(&path, 'z'));
cl_git_fail(git_repository_init(&two, path.ptr, 1));
git_repository_free(one);
git_repository_free(two);
git_buf_dispose(&path);
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/getters.c
|
#include "clar_libgit2.h"
#include "repo/repo_helpers.h"
void test_repo_getters__is_empty_correctly_deals_with_pristine_looking_repos(void)
{
git_repository *repo;
repo = cl_git_sandbox_init("empty_bare.git");
cl_git_remove_placeholders(git_repository_path(repo), "dummy-marker.txt");
cl_assert_equal_i(true, git_repository_is_empty(repo));
cl_git_sandbox_cleanup();
}
void test_repo_getters__is_empty_can_detect_used_repositories(void)
{
git_repository *repo;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_assert_equal_i(false, git_repository_is_empty(repo));
git_repository_free(repo);
}
void test_repo_getters__is_empty_can_detect_repositories_with_defaultbranch_config_empty(void)
{
git_repository *repo;
create_tmp_global_config("tmp_global_path", "init.defaultBranch", "");
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_assert_equal_i(false, git_repository_is_empty(repo));
git_repository_free(repo);
}
void test_repo_getters__retrieving_the_odb_honors_the_refcount(void)
{
git_odb *odb;
git_repository *repo;
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_odb(&odb, repo));
cl_assert(((git_refcount *)odb)->refcount.val == 2);
git_repository_free(repo);
cl_assert(((git_refcount *)odb)->refcount.val == 1);
git_odb_free(odb);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/open.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "sysdir.h"
#include <ctype.h>
void test_repo_open__cleanup(void)
{
cl_git_sandbox_cleanup();
if (git_path_isdir("alternate"))
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES);
}
void test_repo_open__bare_empty_repo(void)
{
git_repository *repo = cl_git_sandbox_init("empty_bare.git");
cl_assert(git_repository_path(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
cl_assert(git_repository_workdir(repo) == NULL);
}
void test_repo_open__format_version_1(void)
{
git_repository *repo;
git_config *config;
repo = cl_git_sandbox_init("empty_bare.git");
cl_git_pass(git_repository_open(&repo, "empty_bare.git"));
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1));
git_config_free(config);
git_repository_free(repo);
cl_git_pass(git_repository_open(&repo, "empty_bare.git"));
cl_assert(git_repository_path(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
git_repository_free(repo);
}
void test_repo_open__standard_empty_repo_through_gitdir(void)
{
git_repository *repo;
cl_git_pass(git_repository_open(&repo, cl_fixture("empty_standard_repo/.gitted")));
cl_assert(git_repository_path(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
git_repository_free(repo);
}
void test_repo_open__standard_empty_repo_through_workdir(void)
{
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
cl_assert(git_repository_path(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_path(repo), "/") == 0);
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git__suffixcmp(git_repository_workdir(repo), "/") == 0);
}
void test_repo_open__open_with_discover(void)
{
static const char *variants[] = {
"attr", "attr/", "attr/.git", "attr/.git/",
"attr/sub", "attr/sub/", "attr/sub/sub", "attr/sub/sub/",
NULL
};
git_repository *repo;
const char **scan;
cl_fixture_sandbox("attr");
cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
for (scan = variants; *scan != NULL; scan++) {
cl_git_pass(git_repository_open_ext(&repo, *scan, 0, NULL));
cl_assert(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0);
git_repository_free(repo);
}
cl_fixture_cleanup("attr");
}
void test_repo_open__check_if_repository(void)
{
cl_git_sandbox_init("empty_standard_repo");
/* Pass NULL for the output parameter to check for but not open the repo */
cl_git_pass(git_repository_open_ext(NULL, "empty_standard_repo", 0, NULL));
cl_git_fail(git_repository_open_ext(NULL, "repo_does_not_exist", 0, NULL));
cl_fixture_cleanup("empty_standard_repo");
}
static void make_gitlink_dir(const char *dir, const char *linktext)
{
git_buf path = GIT_BUF_INIT;
cl_git_pass(git_futils_mkdir(dir, 0777, GIT_MKDIR_VERIFY_DIR));
cl_git_pass(git_buf_joinpath(&path, dir, ".git"));
cl_git_rewritefile(path.ptr, linktext);
git_buf_dispose(&path);
}
void test_repo_open__gitlinked(void)
{
/* need to have both repo dir and workdir set up correctly */
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
git_repository *repo2;
make_gitlink_dir("alternate", "gitdir: ../empty_standard_repo/.git");
cl_git_pass(git_repository_open(&repo2, "alternate"));
cl_assert(git_repository_path(repo2) != NULL);
cl_assert_(git__suffixcmp(git_repository_path(repo2), "empty_standard_repo/.git/") == 0, git_repository_path(repo2));
cl_assert_equal_s(git_repository_path(repo), git_repository_path(repo2));
cl_assert(git_repository_workdir(repo2) != NULL);
cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2));
git_repository_free(repo2);
}
void test_repo_open__with_symlinked_config(void)
{
#ifndef GIT_WIN32
git_buf path = GIT_BUF_INIT;
git_repository *repo;
git_config *cfg;
int32_t value;
cl_git_sandbox_init("empty_standard_repo");
/* Setup .gitconfig as symlink */
cl_git_pass(git_futils_mkdir_r("home", 0777));
cl_git_mkfile("home/.gitconfig.linked", "[global]\ntest = 4567\n");
cl_must_pass(symlink(".gitconfig.linked", "home/.gitconfig"));
cl_git_pass(git_path_prettify(&path, "home", NULL));
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_config_open_default(&cfg));
cl_git_pass(git_config_get_int32(&value, cfg, "global.test"));
cl_assert_equal_i(4567, value);
git_config_free(cfg);
git_repository_free(repo);
cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES));
cl_sandbox_set_search_path_defaults();
git_buf_dispose(&path);
#endif
}
void test_repo_open__from_git_new_workdir(void)
{
#ifndef GIT_WIN32
/* The git-new-workdir script that ships with git sets up a bunch of
* symlinks to create a second workdir that shares the object db with
* another checkout. Libgit2 can open a repo that has been configured
* this way.
*/
git_repository *repo2;
git_buf link_tgt = GIT_BUF_INIT, link = GIT_BUF_INIT, body = GIT_BUF_INIT;
const char **scan;
int link_fd;
static const char *links[] = {
"config", "refs", "logs/refs", "objects", "info", "hooks",
"packed-refs", "remotes", "rr-cache", "svn", NULL
};
static const char *copies[] = {
"HEAD", NULL
};
cl_git_sandbox_init("empty_standard_repo");
cl_git_pass(p_mkdir("alternate", 0777));
cl_git_pass(p_mkdir("alternate/.git", 0777));
for (scan = links; *scan != NULL; scan++) {
git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
git_buf_joinpath(&link_tgt, "../../empty_standard_repo/.git", *scan);
git_buf_joinpath(&link, "alternate/.git", *scan);
if (strchr(*scan, '/'))
git_futils_mkpath2file(link.ptr, 0777);
cl_assert_(symlink(link_tgt.ptr, link.ptr) == 0, strerror(errno));
}
}
for (scan = copies; *scan != NULL; scan++) {
git_buf_joinpath(&link_tgt, "empty_standard_repo/.git", *scan);
if (git_path_exists(link_tgt.ptr)) {
git_buf_joinpath(&link, "alternate/.git", *scan);
cl_git_pass(git_futils_readbuffer(&body, link_tgt.ptr));
cl_assert((link_fd = git_futils_creat_withpath(link.ptr, 0777, 0666)) >= 0);
cl_must_pass(p_write(link_fd, body.ptr, body.size));
p_close(link_fd);
}
}
git_buf_dispose(&link_tgt);
git_buf_dispose(&link);
git_buf_dispose(&body);
cl_git_pass(git_repository_open(&repo2, "alternate"));
cl_assert(git_repository_path(repo2) != NULL);
cl_assert_(git__suffixcmp(git_repository_path(repo2), "alternate/.git/") == 0, git_repository_path(repo2));
cl_assert(git_repository_workdir(repo2) != NULL);
cl_assert_(git__suffixcmp(git_repository_workdir(repo2), "alternate/") == 0, git_repository_workdir(repo2));
git_repository_free(repo2);
#else
cl_skip();
#endif
}
void test_repo_open__failures(void)
{
git_repository *base, *repo;
git_buf ceiling = GIT_BUF_INIT;
base = cl_git_sandbox_init("attr");
cl_git_pass(git_buf_sets(&ceiling, git_repository_workdir(base)));
/* fail with no searching */
cl_git_fail(git_repository_open(&repo, "attr/sub"));
cl_git_fail(git_repository_open_ext(
&repo, "attr/sub", GIT_REPOSITORY_OPEN_NO_SEARCH, NULL));
/* fail with ceiling too low */
cl_git_fail(git_repository_open_ext(&repo, "attr/sub", 0, ceiling.ptr));
cl_git_pass(git_buf_joinpath(&ceiling, ceiling.ptr, "sub"));
cl_git_fail(git_repository_open_ext(&repo, "attr/sub/sub", 0, ceiling.ptr));
/* fail with no repo */
cl_git_pass(p_mkdir("alternate", 0777));
cl_git_pass(p_mkdir("alternate/.git", 0777));
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
cl_git_fail(git_repository_open_ext(&repo, "alternate/.git", 0, NULL));
/* fail with no searching and no appending .git */
cl_git_fail(git_repository_open_ext(
&repo, "attr",
GIT_REPOSITORY_OPEN_NO_SEARCH | GIT_REPOSITORY_OPEN_NO_DOTGIT,
NULL));
git_buf_dispose(&ceiling);
}
void test_repo_open__bad_gitlinks(void)
{
git_repository *repo;
static const char *bad_links[] = {
"garbage\n", "gitdir", "gitdir:\n", "gitdir: foobar",
"gitdir: ../invalid", "gitdir: ../invalid2",
"gitdir: ../attr/.git with extra stuff",
NULL
};
const char **scan;
cl_git_sandbox_init("attr");
cl_git_pass(p_mkdir("invalid", 0777));
cl_git_pass(git_futils_mkdir_r("invalid2/.git", 0777));
for (scan = bad_links; *scan != NULL; scan++) {
make_gitlink_dir("alternate", *scan);
repo = NULL;
cl_git_fail(git_repository_open_ext(&repo, "alternate", 0, NULL));
cl_assert(repo == NULL);
}
git_futils_rmdir_r("invalid", NULL, GIT_RMDIR_REMOVE_FILES);
git_futils_rmdir_r("invalid2", NULL, GIT_RMDIR_REMOVE_FILES);
}
#ifdef GIT_WIN32
static void unposix_path(git_buf *path)
{
char *src, *tgt;
src = tgt = path->ptr;
/* convert "/d/..." to "d:\..." */
if (src[0] == '/' && isalpha(src[1]) && src[2] == '/') {
*tgt++ = src[1];
*tgt++ = ':';
*tgt++ = '\\';
src += 3;
}
while (*src) {
*tgt++ = (*src == '/') ? '\\' : *src;
src++;
}
*tgt = '\0';
}
#endif
void test_repo_open__win32_path(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("empty_standard_repo"), *repo2;
git_buf winpath = GIT_BUF_INIT;
static const char *repo_path = "empty_standard_repo/.git/";
static const char *repo_wd = "empty_standard_repo/";
cl_assert(git__suffixcmp(git_repository_path(repo), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo), repo_wd) == 0);
cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
cl_git_pass(git_buf_sets(&winpath, git_repository_path(repo)));
git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
cl_git_pass(git_buf_sets(&winpath, git_repository_workdir(repo)));
git_buf_truncate(&winpath, winpath.size - 1); /* remove trailing '/' */
unposix_path(&winpath);
cl_git_pass(git_repository_open(&repo2, winpath.ptr));
cl_assert(git__suffixcmp(git_repository_path(repo2), repo_path) == 0);
cl_assert(git__suffixcmp(git_repository_workdir(repo2), repo_wd) == 0);
git_repository_free(repo2);
git_buf_dispose(&winpath);
#endif
}
void test_repo_open__opening_a_non_existing_repository_returns_ENOTFOUND(void)
{
git_repository *repo;
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_open(&repo, "i-do-not/exist"));
}
void test_repo_open__no_config(void)
{
git_buf path = GIT_BUF_INIT;
git_repository *repo;
git_config *config;
cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename(
"empty_standard_repo/.gitted", "empty_standard_repo/.git"));
/* remove local config */
cl_git_pass(git_futils_rmdir_r(
"empty_standard_repo/.git/config", NULL, GIT_RMDIR_REMOVE_FILES));
/* isolate from system level configs */
cl_must_pass(p_mkdir("alternate", 0777));
cl_git_pass(git_path_prettify(&path, "alternate", NULL));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
git_buf_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_string(config, "test.set", "42"));
git_config_free(config);
git_repository_free(repo);
cl_fixture_cleanup("empty_standard_repo");
cl_sandbox_set_search_path_defaults();
}
void test_repo_open__force_bare(void)
{
/* need to have both repo dir and workdir set up correctly */
git_repository *repo = cl_git_sandbox_init("empty_standard_repo");
git_repository *barerepo;
make_gitlink_dir("alternate", "gitdir: ../empty_standard_repo/.git");
cl_assert(!git_repository_is_bare(repo));
cl_git_pass(git_repository_open(&barerepo, "alternate"));
cl_assert(!git_repository_is_bare(barerepo));
git_repository_free(barerepo);
cl_git_pass(git_repository_open_bare(
&barerepo, "empty_standard_repo/.git"));
cl_assert(git_repository_is_bare(barerepo));
git_repository_free(barerepo);
cl_git_fail(git_repository_open_bare(&barerepo, "alternate/.git"));
cl_git_pass(git_repository_open_ext(
&barerepo, "alternate/.git", GIT_REPOSITORY_OPEN_BARE, NULL));
cl_assert(git_repository_is_bare(barerepo));
git_repository_free(barerepo);
cl_git_pass(p_mkdir("empty_standard_repo/subdir", 0777));
cl_git_mkfile("empty_standard_repo/subdir/something.txt", "something");
cl_git_fail(git_repository_open_bare(
&barerepo, "empty_standard_repo/subdir"));
cl_git_pass(git_repository_open_ext(
&barerepo, "empty_standard_repo/subdir", GIT_REPOSITORY_OPEN_BARE, NULL));
cl_assert(git_repository_is_bare(barerepo));
git_repository_free(barerepo);
cl_git_pass(p_mkdir("alternate/subdir", 0777));
cl_git_pass(p_mkdir("alternate/subdir/sub2", 0777));
cl_git_mkfile("alternate/subdir/sub2/something.txt", "something");
cl_git_fail(git_repository_open_bare(&barerepo, "alternate/subdir/sub2"));
cl_git_pass(git_repository_open_ext(
&barerepo, "alternate/subdir/sub2",
GIT_REPOSITORY_OPEN_BARE|GIT_REPOSITORY_OPEN_CROSS_FS, NULL));
cl_assert(git_repository_is_bare(barerepo));
git_repository_free(barerepo);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/extensions.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "sysdir.h"
#include <ctype.h>
git_repository *repo;
void test_repo_extensions__initialize(void)
{
git_config *config;
repo = cl_git_sandbox_init("empty_bare.git");
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_set_int32(config, "core.repositoryformatversion", 1));
git_config_free(config);
}
void test_repo_extensions__cleanup(void)
{
cl_git_sandbox_cleanup();
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, NULL, 0));
}
void test_repo_extensions__builtin(void)
{
git_repository *extended;
cl_repo_set_string(repo, "extensions.noop", "foobar");
cl_git_pass(git_repository_open(&extended, "empty_bare.git"));
cl_assert(git_repository_path(extended) != NULL);
cl_assert(git__suffixcmp(git_repository_path(extended), "/") == 0);
git_repository_free(extended);
}
void test_repo_extensions__negate_builtin(void)
{
const char *in[] = { "foo", "!noop", "baz" };
git_repository *extended;
cl_repo_set_string(repo, "extensions.noop", "foobar");
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
cl_git_fail(git_repository_open(&extended, "empty_bare.git"));
git_repository_free(extended);
}
void test_repo_extensions__unsupported(void)
{
git_repository *extended = NULL;
cl_repo_set_string(repo, "extensions.unknown", "foobar");
cl_git_fail(git_repository_open(&extended, "empty_bare.git"));
git_repository_free(extended);
}
void test_repo_extensions__adds_extension(void)
{
const char *in[] = { "foo", "!noop", "newextension", "baz" };
git_repository *extended;
cl_repo_set_string(repo, "extensions.newextension", "foobar");
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_EXTENSIONS, in, ARRAY_SIZE(in)));
cl_git_pass(git_repository_open(&extended, "empty_bare.git"));
cl_assert(git_repository_path(extended) != NULL);
cl_assert(git__suffixcmp(git_repository_path(extended), "/") == 0);
git_repository_free(extended);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/env.c
|
#include "clar_libgit2.h"
#include "futils.h"
#include "sysdir.h"
#include <ctype.h>
static void clear_git_env(void)
{
cl_setenv("GIT_DIR", NULL);
cl_setenv("GIT_CEILING_DIRECTORIES", NULL);
cl_setenv("GIT_INDEX_FILE", NULL);
cl_setenv("GIT_NAMESPACE", NULL);
cl_setenv("GIT_OBJECT_DIRECTORY", NULL);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL);
cl_setenv("GIT_WORK_TREE", NULL);
cl_setenv("GIT_COMMON_DIR", NULL);
}
void test_repo_env__initialize(void)
{
clear_git_env();
}
void test_repo_env__cleanup(void)
{
cl_git_sandbox_cleanup();
if (git_path_isdir("attr"))
git_futils_rmdir_r("attr", NULL, GIT_RMDIR_REMOVE_FILES);
if (git_path_isdir("testrepo.git"))
git_futils_rmdir_r("testrepo.git", NULL, GIT_RMDIR_REMOVE_FILES);
if (git_path_isdir("peeled.git"))
git_futils_rmdir_r("peeled.git", NULL, GIT_RMDIR_REMOVE_FILES);
clear_git_env();
}
static int GIT_FORMAT_PRINTF(2, 3) cl_setenv_printf(const char *name, const char *fmt, ...)
{
int ret;
va_list args;
git_buf buf = GIT_BUF_INIT;
va_start(args, fmt);
cl_git_pass(git_buf_vprintf(&buf, fmt, args));
va_end(args);
ret = cl_setenv(name, git_buf_cstr(&buf));
git_buf_dispose(&buf);
return ret;
}
/* Helper functions for test_repo_open__env, passing through the file and line
* from the caller rather than those of the helper. The expression strings
* distinguish between the possible failures within the helper. */
static void env_pass_(const char *path, const char *file, const char *func, int line)
{
git_repository *repo;
cl_git_expect(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
cl_git_expect(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
cl_assert_at_line(git__suffixcmp(git_repository_path(repo), "attr/.git/") == 0, file, func, line);
cl_assert_at_line(git__suffixcmp(git_repository_workdir(repo), "attr/") == 0, file, func, line);
cl_assert_at_line(!git_repository_is_bare(repo), file, func, line);
git_repository_free(repo);
}
#define env_pass(path) env_pass_((path), __FILE__, __func__, __LINE__)
#define cl_git_fail_at_line(expr, file, func, line) clar__assert((expr) < 0, file, func, line, "Expected function call to fail: " #expr, NULL, 1)
static void env_fail_(const char *path, const char *file, const char *func, int line)
{
git_repository *repo;
cl_git_fail_at_line(git_repository_open_ext(NULL, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, func, line);
cl_git_fail_at_line(git_repository_open_ext(&repo, path, GIT_REPOSITORY_OPEN_FROM_ENV, NULL), file, func, line);
}
#define env_fail(path) env_fail_((path), __FILE__, __func__, __LINE__)
static void env_cd_(
const char *path,
void (*passfail_)(const char *, const char *, const char *, int),
const char *file, const char *func, int line)
{
git_buf cwd_buf = GIT_BUF_INIT;
cl_git_pass(git_path_prettify_dir(&cwd_buf, ".", NULL));
cl_must_pass(p_chdir(path));
passfail_(NULL, file, func, line);
cl_must_pass(p_chdir(git_buf_cstr(&cwd_buf)));
git_buf_dispose(&cwd_buf);
}
#define env_cd_pass(path) env_cd_((path), env_pass_, __FILE__, __func__, __LINE__)
#define env_cd_fail(path) env_cd_((path), env_fail_, __FILE__, __func__, __LINE__)
static void env_check_objects_(bool a, bool t, bool p, const char *file, const char *func, int line)
{
git_repository *repo;
git_oid oid_a, oid_t, oid_p;
git_object *object;
cl_git_pass(git_oid_fromstr(&oid_a, "45141a79a77842c59a63229403220a4e4be74e3d"));
cl_git_pass(git_oid_fromstr(&oid_t, "1385f264afb75a56a5bec74243be9b367ba4ca08"));
cl_git_pass(git_oid_fromstr(&oid_p, "0df1a5865c8abfc09f1f2182e6a31be550e99f07"));
cl_git_expect(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL), 0, file, func, line);
if (a) {
cl_git_expect(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), 0, file, func, line);
git_object_free(object);
} else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_a, GIT_OBJECT_BLOB), file, func, line);
}
if (t) {
cl_git_expect(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), 0, file, func, line);
git_object_free(object);
} else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_t, GIT_OBJECT_BLOB), file, func, line);
}
if (p) {
cl_git_expect(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), 0, file, func, line);
git_object_free(object);
} else {
cl_git_fail_at_line(git_object_lookup(&object, repo, &oid_p, GIT_OBJECT_COMMIT), file, func, line);
}
git_repository_free(repo);
}
#define env_check_objects(a, t, t2) env_check_objects_((a), (t), (t2), __FILE__, __func__, __LINE__)
void test_repo_env__open(void)
{
git_repository *repo = NULL;
git_buf repo_dir_buf = GIT_BUF_INIT;
const char *repo_dir = NULL;
git_index *index = NULL;
const char *t_obj = "testrepo.git/objects";
const char *p_obj = "peeled.git/objects";
clear_git_env();
cl_fixture_sandbox("attr");
cl_fixture_sandbox("testrepo.git");
cl_fixture_sandbox("peeled.git");
cl_git_pass(p_rename("attr/.gitted", "attr/.git"));
cl_git_pass(git_path_prettify_dir(&repo_dir_buf, "attr", NULL));
repo_dir = git_buf_cstr(&repo_dir_buf);
/* GIT_DIR that doesn't exist */
cl_setenv("GIT_DIR", "does-not-exist");
env_fail(NULL);
/* Explicit start_path overrides GIT_DIR */
env_pass("attr");
env_pass("attr/.git");
env_pass("attr/sub");
env_pass("attr/sub/sub");
/* GIT_DIR with relative paths */
cl_setenv("GIT_DIR", "attr/.git");
env_pass(NULL);
cl_setenv("GIT_DIR", "attr");
env_fail(NULL);
cl_setenv("GIT_DIR", "attr/sub");
env_fail(NULL);
cl_setenv("GIT_DIR", "attr/sub/sub");
env_fail(NULL);
/* GIT_DIR with absolute paths */
cl_setenv_printf("GIT_DIR", "%s/.git", repo_dir);
env_pass(NULL);
cl_setenv("GIT_DIR", repo_dir);
env_fail(NULL);
cl_setenv_printf("GIT_DIR", "%s/sub", repo_dir);
env_fail(NULL);
cl_setenv_printf("GIT_DIR", "%s/sub/sub", repo_dir);
env_fail(NULL);
cl_setenv("GIT_DIR", NULL);
/* Searching from the current directory */
env_cd_pass("attr");
env_cd_pass("attr/.git");
env_cd_pass("attr/sub");
env_cd_pass("attr/sub/sub");
/* A ceiling directory blocks searches from ascending into that
* directory, but doesn't block the start_path itself. */
cl_setenv("GIT_CEILING_DIRECTORIES", repo_dir);
env_cd_pass("attr");
env_cd_fail("attr/sub");
env_cd_fail("attr/sub/sub");
cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub", repo_dir);
env_cd_pass("attr");
env_cd_pass("attr/sub");
env_cd_fail("attr/sub/sub");
/* Multiple ceiling directories */
cl_setenv_printf("GIT_CEILING_DIRECTORIES", "123%c%s/sub%cabc",
GIT_PATH_LIST_SEPARATOR, repo_dir, GIT_PATH_LIST_SEPARATOR);
env_cd_pass("attr");
env_cd_pass("attr/sub");
env_cd_fail("attr/sub/sub");
cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub",
repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir);
env_cd_pass("attr");
env_cd_fail("attr/sub");
env_cd_fail("attr/sub/sub");
cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s/sub%c%s",
repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir);
env_cd_pass("attr");
env_cd_fail("attr/sub");
env_cd_fail("attr/sub/sub");
cl_setenv_printf("GIT_CEILING_DIRECTORIES", "%s%c%s/sub/sub",
repo_dir, GIT_PATH_LIST_SEPARATOR, repo_dir);
env_cd_pass("attr");
env_cd_fail("attr/sub");
env_cd_fail("attr/sub/sub");
cl_setenv("GIT_CEILING_DIRECTORIES", NULL);
/* Index files */
cl_setenv("GIT_INDEX_FILE", cl_fixture("gitgit.index"));
cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert_equal_s(git_index_path(index), cl_fixture("gitgit.index"));
cl_assert_equal_i(git_index_entrycount(index), 1437);
git_index_free(index);
git_repository_free(repo);
cl_setenv("GIT_INDEX_FILE", NULL);
/* Namespaces */
cl_setenv("GIT_NAMESPACE", "some-namespace");
cl_git_pass(git_repository_open_ext(&repo, "attr", GIT_REPOSITORY_OPEN_FROM_ENV, NULL));
cl_assert_equal_s(git_repository_get_namespace(repo), "some-namespace");
git_repository_free(repo);
cl_setenv("GIT_NAMESPACE", NULL);
/* Object directories and alternates */
env_check_objects(true, false, false);
cl_setenv("GIT_OBJECT_DIRECTORY", t_obj);
env_check_objects(false, true, false);
cl_setenv("GIT_OBJECT_DIRECTORY", NULL);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", t_obj);
env_check_objects(true, true, false);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL);
cl_setenv("GIT_OBJECT_DIRECTORY", p_obj);
env_check_objects(false, false, true);
cl_setenv("GIT_OBJECT_DIRECTORY", NULL);
cl_setenv("GIT_OBJECT_DIRECTORY", t_obj);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", p_obj);
env_check_objects(false, true, true);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL);
cl_setenv("GIT_OBJECT_DIRECTORY", NULL);
cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES",
"%s%c%s", t_obj, GIT_PATH_LIST_SEPARATOR, p_obj);
env_check_objects(true, true, true);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL);
cl_setenv_printf("GIT_ALTERNATE_OBJECT_DIRECTORIES",
"%s%c%s", p_obj, GIT_PATH_LIST_SEPARATOR, t_obj);
env_check_objects(true, true, true);
cl_setenv("GIT_ALTERNATE_OBJECT_DIRECTORIES", NULL);
cl_fixture_cleanup("peeled.git");
cl_fixture_cleanup("testrepo.git");
cl_fixture_cleanup("attr");
git_buf_dispose(&repo_dir_buf);
clear_git_env();
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/discover.c
|
#include "clar_libgit2.h"
#include "odb.h"
#include "futils.h"
#include "repository.h"
#define TEMP_REPO_FOLDER "temprepo/"
#define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git"
#define SUB_REPOSITORY_FOLDER_NAME "sub_repo"
#define SUB_REPOSITORY_FOLDER DISCOVER_FOLDER "/" SUB_REPOSITORY_FOLDER_NAME
#define SUB_REPOSITORY_GITDIR SUB_REPOSITORY_FOLDER "/.git"
#define SUB_REPOSITORY_FOLDER_SUB SUB_REPOSITORY_FOLDER "/sub"
#define SUB_REPOSITORY_FOLDER_SUB_SUB SUB_REPOSITORY_FOLDER_SUB "/subsub"
#define SUB_REPOSITORY_FOLDER_SUB_SUB_SUB SUB_REPOSITORY_FOLDER_SUB_SUB "/subsubsub"
#define REPOSITORY_ALTERNATE_FOLDER DISCOVER_FOLDER "/alternate_sub_repo"
#define REPOSITORY_ALTERNATE_FOLDER_SUB REPOSITORY_ALTERNATE_FOLDER "/sub"
#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB "/subsub"
#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/subsubsub"
#define ALTERNATE_MALFORMED_FOLDER1 DISCOVER_FOLDER "/alternate_malformed_repo1"
#define ALTERNATE_MALFORMED_FOLDER2 DISCOVER_FOLDER "/alternate_malformed_repo2"
#define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3"
#define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo"
static void ensure_repository_discover(const char *start_path,
const char *ceiling_dirs,
const char *expected_path)
{
git_buf found_path = GIT_BUF_INIT, resolved = GIT_BUF_INIT;
git_buf_attach(&resolved, p_realpath(expected_path, NULL), 0);
cl_assert(resolved.size > 0);
cl_git_pass(git_path_to_dir(&resolved));
cl_git_pass(git_repository_discover(&found_path, start_path, 1, ceiling_dirs));
cl_assert_equal_s(found_path.ptr, resolved.ptr);
git_buf_dispose(&resolved);
git_buf_dispose(&found_path);
}
static void write_file(const char *path, const char *content)
{
git_file file;
int error;
if (git_path_exists(path)) {
cl_git_pass(p_unlink(path));
}
file = git_futils_creat_withpath(path, 0777, 0666);
cl_assert(file >= 0);
error = p_write(file, content, strlen(content) * sizeof(char));
p_close(file);
cl_git_pass(error);
}
/*no check is performed on ceiling_dirs length, so be sure it's long enough */
static void append_ceiling_dir(git_buf *ceiling_dirs, const char *path)
{
git_buf pretty_path = GIT_BUF_INIT;
char ceiling_separator[2] = { GIT_PATH_LIST_SEPARATOR, '\0' };
cl_git_pass(git_path_prettify_dir(&pretty_path, path, NULL));
if (ceiling_dirs->size > 0)
git_buf_puts(ceiling_dirs, ceiling_separator);
git_buf_puts(ceiling_dirs, pretty_path.ptr);
git_buf_dispose(&pretty_path);
cl_assert(git_buf_oom(ceiling_dirs) == 0);
}
static git_buf discovered;
static git_buf ceiling_dirs;
void test_repo_discover__initialize(void)
{
git_repository *repo;
const mode_t mode = 0777;
git_futils_mkdir_r(DISCOVER_FOLDER, mode);
git_buf_init(&discovered, 0);
git_buf_init(&ceiling_dirs, 0);
append_ceiling_dir(&ceiling_dirs, TEMP_REPO_FOLDER);
cl_git_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1));
git_repository_free(repo);
cl_git_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
cl_git_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode));
cl_git_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode));
write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT);
write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode));
write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode));
write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode));
write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n");
cl_git_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode));
write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist");
git_repository_free(repo);
}
void test_repo_discover__cleanup(void)
{
git_buf_dispose(&discovered);
git_buf_dispose(&ceiling_dirs);
cl_git_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, NULL, GIT_RMDIR_REMOVE_FILES));
}
void test_repo_discover__discovering_repo_with_exact_path_succeeds(void)
{
cl_git_pass(git_repository_discover(&discovered, DISCOVER_FOLDER, 0, ceiling_dirs.ptr));
cl_git_pass(git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER, 0, ceiling_dirs.ptr));
}
void test_repo_discover__discovering_nonexistent_dir_fails(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, DISCOVER_FOLDER "-nonexistent", 0, NULL));
}
void test_repo_discover__discovering_repo_with_subdirectory_succeeds(void)
{
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
}
void test_repo_discover__discovering_repository_with_alternative_gitdir_succeeds(void)
{
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs.ptr, DISCOVER_FOLDER);
}
void test_repo_discover__discovering_repository_with_malformed_alternative_gitdir_fails(void)
{
cl_git_fail(git_repository_discover(&discovered, ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs.ptr));
cl_git_fail(git_repository_discover(&discovered, ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs.ptr));
cl_git_fail(git_repository_discover(&discovered, ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs.ptr));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs.ptr));
}
void test_repo_discover__discovering_repository_with_ceiling(void)
{
append_ceiling_dir(&ceiling_dirs, SUB_REPOSITORY_FOLDER_SUB);
/* this must pass as ceiling_directories cannot prevent the current
* working directory to be checked */
ensure_repository_discover(SUB_REPOSITORY_FOLDER, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs.ptr));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs.ptr));
}
void test_repo_discover__other_ceiling(void)
{
append_ceiling_dir(&ceiling_dirs, SUB_REPOSITORY_FOLDER);
/* this must pass as ceiling_directories cannot predent the current
* working directory to be checked */
ensure_repository_discover(SUB_REPOSITORY_FOLDER, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs.ptr));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs.ptr));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_discover(&discovered, SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs.ptr));
}
void test_repo_discover__ceiling_should_not_affect_gitdir_redirection(void)
{
append_ceiling_dir(&ceiling_dirs, SUB_REPOSITORY_FOLDER);
/* gitfile redirection should not be affected by ceiling directories */
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs.ptr, DISCOVER_FOLDER);
}
void test_repo_discover__discovery_starting_at_file_succeeds(void)
{
int fd;
cl_assert((fd = p_creat(SUB_REPOSITORY_FOLDER "/file", 0600)) >= 0);
cl_assert(p_close(fd) == 0);
ensure_repository_discover(SUB_REPOSITORY_FOLDER "/file", ceiling_dirs.ptr, SUB_REPOSITORY_GITDIR);
}
void test_repo_discover__discovery_starting_at_system_root_causes_no_hang(void)
{
#ifdef GIT_WIN32
git_buf out = GIT_BUF_INIT;
cl_git_fail(git_repository_discover(&out, "C:/", 0, NULL));
cl_git_fail(git_repository_discover(&out, "//localhost/", 0, NULL));
#endif
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/headtree.c
|
#include "clar_libgit2.h"
#include "repository.h"
#include "repo_helpers.h"
#include "posix.h"
static git_repository *repo;
static git_tree *tree;
void test_repo_headtree__initialize(void)
{
repo = cl_git_sandbox_init("testrepo.git");
tree = NULL;
}
void test_repo_headtree__cleanup(void)
{
git_tree_free(tree);
cl_git_sandbox_cleanup();
}
void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void)
{
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_assert(git_oid_streq(git_tree_id(tree), "az"));
}
void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(void)
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
cl_assert(git_oid_streq(git_tree_id(tree), "az"));
}
void test_repo_headtree__when_head_is_unborn_returns_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(true, git_repository_head_unborn(repo));
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head_tree(&tree, repo));
}
void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void)
{
delete_head(repo);
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head_tree(&tree, repo));
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/state.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "refs.h"
#include "posix.h"
#include "futils.h"
static git_repository *_repo;
static git_buf _path;
void test_repo_state__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_state__cleanup(void)
{
cl_git_sandbox_cleanup();
git_buf_dispose(&_path);
}
static void setup_simple_state(const char *filename)
{
cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), filename));
git_futils_mkpath2file(git_buf_cstr(&_path), 0777);
cl_git_mkfile(git_buf_cstr(&_path), "dummy");
}
static void assert_repo_state(git_repository_state_t state)
{
cl_assert_equal_i(state, git_repository_state(_repo));
}
void test_repo_state__none_with_HEAD_attached(void)
{
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__none_with_HEAD_detached(void)
{
cl_git_pass(git_repository_detach_head(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__merge(void)
{
setup_simple_state(GIT_MERGE_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_MERGE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__revert(void)
{
setup_simple_state(GIT_REVERT_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REVERT);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__revert_sequence(void)
{
setup_simple_state(GIT_REVERT_HEAD_FILE);
setup_simple_state(GIT_SEQUENCER_TODO_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REVERT_SEQUENCE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__cherry_pick(void)
{
setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_CHERRYPICK);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__cherrypick_sequence(void)
{
setup_simple_state(GIT_CHERRYPICK_HEAD_FILE);
setup_simple_state(GIT_SEQUENCER_TODO_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__bisect(void)
{
setup_simple_state(GIT_BISECT_LOG_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_BISECT);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase_interactive(void)
{
setup_simple_state(GIT_REBASE_MERGE_INTERACTIVE_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_INTERACTIVE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase_merge(void)
{
setup_simple_state(GIT_REBASE_MERGE_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_REBASE_MERGE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_REBASING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_REBASE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__apply_mailbox(void)
{
setup_simple_state(GIT_REBASE_APPLY_APPLYING_FILE);
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
void test_repo_state__apply_mailbox_or_rebase(void)
{
setup_simple_state(GIT_REBASE_APPLY_DIR "whatever");
assert_repo_state(GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE);
cl_git_pass(git_repository_state_cleanup(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/setters.c
|
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "buffer.h"
#include "posix.h"
#include "util.h"
#include "path.h"
#include "futils.h"
static git_repository *repo;
void test_repo_setters__initialize(void)
{
cl_fixture_sandbox("testrepo.git");
cl_git_pass(git_repository_open(&repo, "testrepo.git"));
cl_must_pass(p_mkdir("new_workdir", 0777));
}
void test_repo_setters__cleanup(void)
{
git_repository_free(repo);
repo = NULL;
cl_fixture_cleanup("testrepo.git");
cl_fixture_cleanup("new_workdir");
}
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
{
cl_assert(git_repository_is_bare(repo) == 1);
cl_assert(git_repository_workdir(repo) == NULL);
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git_repository_workdir(repo) != NULL);
cl_assert(git_repository_is_bare(repo) == 0);
}
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
{
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));
cl_assert(git__suffixcmp(git_repository_workdir(repo), "new_workdir/") == 0);
}
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
git_config *cfg;
git_buf buf = GIT_BUF_INIT;
git_buf content = GIT_BUF_INIT;
cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));
cl_assert(git_path_isfile("./new_workdir/.git"));
cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
git_buf_dispose(&content);
cl_git_pass(git_repository_config(&cfg, repo));
cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);
git_buf_dispose(&buf);
git_config_free(cfg);
}
void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_one_properly_honors_the_refcount(void)
{
git_index *new_index;
cl_git_pass(git_index_open(&new_index, "./my-index"));
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_repository_set_index(repo, new_index);
cl_assert(((git_refcount *)new_index)->refcount.val == 2);
git_repository_free(repo);
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_index_free(new_index);
/*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
}
void test_repo_setters__setting_a_new_odb_on_a_repo_which_already_loaded_one_properly_honors_the_refcount(void)
{
git_odb *new_odb;
cl_git_pass(git_odb_open(&new_odb, "./testrepo.git/objects"));
cl_assert(((git_refcount *)new_odb)->refcount.val == 1);
git_repository_set_odb(repo, new_odb);
cl_assert(((git_refcount *)new_odb)->refcount.val == 2);
git_repository_free(repo);
cl_assert(((git_refcount *)new_odb)->refcount.val == 1);
git_odb_free(new_odb);
/*
* Ensure the cleanup method won't try to free the repo as it's already been taken care of
*/
repo = NULL;
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/hashfile.c
|
#include "clar_libgit2.h"
#include "buffer.h"
static git_repository *_repo;
void test_repo_hashfile__initialize(void)
{
_repo = cl_git_sandbox_init("status");
}
void test_repo_hashfile__cleanup(void)
{
cl_fixture_cleanup("absolute");
cl_git_sandbox_cleanup();
_repo = NULL;
}
void test_repo_hashfile__simple(void)
{
git_oid a, b;
git_buf full = GIT_BUF_INIT;
/* hash with repo relative path */
cl_git_pass(git_odb_hashfile(&a, "status/current_file", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "current_file", GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
cl_git_pass(git_buf_joinpath(&full, git_repository_workdir(_repo), "current_file"));
/* hash with full path */
cl_git_pass(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
/* hash with invalid type */
cl_git_fail(git_odb_hashfile(&a, full.ptr, GIT_OBJECT_ANY));
cl_git_fail(git_repository_hashfile(&b, _repo, full.ptr, GIT_OBJECT_OFS_DELTA, NULL));
git_buf_dispose(&full);
}
void test_repo_hashfile__filtered_in_workdir(void)
{
git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
cl_git_pass(git_buf_joinpath(&root, cwd, "status"));
cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
/* create some sample content with CRLF in it */
cl_git_mkfile("status/testfile.txt", "content\r\n");
cl_git_mkfile("status/testfile.bin", "other\r\nstuff\r\n");
/* not equal hashes because of filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, NULL));
cl_assert(git_oid_cmp(&a, &b));
/* not equal hashes because of filtering when specified by absolute path */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert(git_oid_cmp(&a, &b));
/* equal hashes because filter is binary */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
/* equal hashes because filter is binary when specified by absolute path */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
/* equal hashes when 'as_file' points to binary filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, "foo.bin"));
cl_assert_equal_oid(&a, &b);
/* equal hashes when 'as_file' points to binary filtering (absolute path) */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "foo.bin"));
cl_assert_equal_oid(&a, &b);
/* not equal hashes when 'as_file' points to text filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, "foo.txt"));
cl_assert(git_oid_cmp(&a, &b));
/* not equal hashes when 'as_file' points to text filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "foo.txt"));
cl_assert(git_oid_cmp(&a, &b));
/* equal hashes when 'as_file' is empty and turns off filtering */
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_BLOB, ""));
cl_assert_equal_oid(&a, &b);
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, "testfile.bin", GIT_OBJECT_BLOB, ""));
cl_assert_equal_oid(&a, &b);
cl_git_pass(git_odb_hashfile(&a, "status/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, ""));
cl_assert_equal_oid(&a, &b);
cl_git_pass(git_odb_hashfile(&a, "status/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, ""));
cl_assert_equal_oid(&a, &b);
/* some hash type failures */
cl_git_fail(git_odb_hashfile(&a, "status/testfile.txt", 0));
cl_git_fail(git_repository_hashfile(&b, _repo, "testfile.txt", GIT_OBJECT_ANY, NULL));
git_buf_dispose(&txt);
git_buf_dispose(&bin);
git_buf_dispose(&root);
}
void test_repo_hashfile__filtered_outside_workdir(void)
{
git_buf root = GIT_BUF_INIT, txt = GIT_BUF_INIT, bin = GIT_BUF_INIT;
char cwd[GIT_PATH_MAX];
git_oid a, b;
cl_must_pass(p_getcwd(cwd, GIT_PATH_MAX));
cl_must_pass(p_mkdir("absolute", 0777));
cl_git_pass(git_buf_joinpath(&root, cwd, "absolute"));
cl_git_pass(git_buf_joinpath(&txt, root.ptr, "testfile.txt"));
cl_git_pass(git_buf_joinpath(&bin, root.ptr, "testfile.bin"));
cl_repo_set_bool(_repo, "core.autocrlf", true);
cl_git_append2file("status/.gitattributes", "*.txt text\n*.bin binary\n\n");
/* create some sample content with CRLF in it */
cl_git_mkfile("absolute/testfile.txt", "content\r\n");
cl_git_mkfile("absolute/testfile.bin", "other\r\nstuff\r\n");
/* not equal hashes because of filtering */
cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, "testfile.txt"));
cl_assert(git_oid_cmp(&a, &b));
/* equal hashes because filter is binary */
cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, "testfile.bin"));
cl_assert_equal_oid(&a, &b);
/*
* equal hashes because no filtering occurs for absolute paths outside the working
* directory unless as_path is specified
*/
cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.txt", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, txt.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
cl_git_pass(git_odb_hashfile(&a, "absolute/testfile.bin", GIT_OBJECT_BLOB));
cl_git_pass(git_repository_hashfile(&b, _repo, bin.ptr, GIT_OBJECT_BLOB, NULL));
cl_assert_equal_oid(&a, &b);
git_buf_dispose(&txt);
git_buf_dispose(&bin);
git_buf_dispose(&root);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/new.c
|
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
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);
}
void test_repo_new__is_bare_until_workdir_set(void)
{
git_repository *repo;
cl_git_pass(git_repository_new(&repo));
cl_assert_equal_b(true, git_repository_is_bare(repo));
cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
cl_assert_equal_b(false, git_repository_is_bare(repo));
git_repository_free(repo);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/repo_helpers.c
|
#include "clar_libgit2.h"
#include "refs.h"
#include "repo_helpers.h"
#include "posix.h"
void make_head_unborn(git_repository* repo, const char *target)
{
git_reference *head;
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, target, 1, NULL));
git_reference_free(head);
}
void delete_head(git_repository* repo)
{
git_buf head_path = GIT_BUF_INIT;
cl_git_pass(git_buf_joinpath(&head_path, git_repository_path(repo), GIT_HEAD_FILE));
cl_git_pass(p_unlink(git_buf_cstr(&head_path)));
git_buf_dispose(&head_path);
}
void create_tmp_global_config(const char *dirname, const char *key, const char *val)
{
git_buf path = GIT_BUF_INIT;
git_config *config;
cl_git_pass(git_libgit2_opts(GIT_OPT_SET_SEARCH_PATH,
GIT_CONFIG_LEVEL_GLOBAL, dirname));
cl_must_pass(p_mkdir(dirname, 0777));
cl_git_pass(git_buf_joinpath(&path, dirname, ".gitconfig"));
cl_git_pass(git_config_open_ondisk(&config, path.ptr));
cl_git_pass(git_config_set_string(config, key, val));
git_config_free(config);
git_buf_dispose(&path);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/message.c
|
#include "clar_libgit2.h"
#include "buffer.h"
#include "refs.h"
#include "posix.h"
static git_repository *_repo;
void test_repo_message__initialize(void)
{
_repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_message__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_repo_message__none(void)
{
git_buf actual = GIT_BUF_INIT;
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
}
void test_repo_message__message(void)
{
git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
cl_git_mkfile(git_buf_cstr(&path), expected);
cl_git_pass(git_repository_message(&actual, _repo));
cl_assert_equal_s(expected, git_buf_cstr(&actual));
git_buf_dispose(&actual);
cl_git_pass(p_unlink(git_buf_cstr(&path)));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
git_buf_dispose(&path);
}
|
0 |
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests
|
repos/gyro/.gyro/zig-libgit2-mattnite-github.com-0537beea/pkg/libgit2/tests/repo/config.c
|
#include "clar_libgit2.h"
#include "sysdir.h"
#include "futils.h"
#include <ctype.h>
static git_buf path = GIT_BUF_INIT;
void test_repo_config__initialize(void)
{
cl_fixture_sandbox("empty_standard_repo");
cl_git_pass(cl_rename(
"empty_standard_repo/.gitted", "empty_standard_repo/.git"));
git_buf_clear(&path);
cl_must_pass(p_mkdir("alternate", 0777));
cl_git_pass(git_path_prettify(&path, "alternate", NULL));
}
void test_repo_config__cleanup(void)
{
cl_sandbox_set_search_path_defaults();
git_buf_dispose(&path);
cl_git_pass(
git_futils_rmdir_r("alternate", NULL, GIT_RMDIR_REMOVE_FILES));
cl_assert(!git_path_isdir("alternate"));
cl_fixture_cleanup("empty_standard_repo");
}
void test_repo_config__can_open_global_when_there_is_no_file(void)
{
git_repository *repo;
git_config *config, *global;
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_open_level(
&global, config, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_set_string(global, "test.set", "42"));
git_config_free(global);
git_config_free(config);
git_repository_free(repo);
}
void test_repo_config__can_open_missing_global_with_separators(void)
{
git_repository *repo;
git_config *config, *global;
cl_git_pass(git_buf_printf(
&path, "%c%s", GIT_PATH_LIST_SEPARATOR, "dummy"));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
git_buf_dispose(&path);
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
cl_git_pass(git_repository_config(&config, repo));
cl_git_pass(git_config_open_level(
&global, config, GIT_CONFIG_LEVEL_GLOBAL));
cl_git_pass(git_config_set_string(global, "test.set", "42"));
git_config_free(global);
git_config_free(config);
git_repository_free(repo);
}
#include "repository.h"
void test_repo_config__read_with_no_configs_at_all(void)
{
git_repository *repo;
int val;
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
/* with none */
cl_must_pass(p_unlink("empty_standard_repo/.git/config"));
cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(GIT_ABBREV_DEFAULT, val);
git_repository_free(repo);
/* with no local config, just system */
cl_sandbox_set_search_path_defaults();
cl_must_pass(p_mkdir("alternate/1", 0777));
cl_git_pass(git_buf_joinpath(&path, path.ptr, "1"));
cl_git_rewritefile("alternate/1/gitconfig", "[core]\n\tabbrev = 10\n");
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_SYSTEM, path.ptr));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(10, val);
git_repository_free(repo);
/* with just xdg + system */
cl_must_pass(p_mkdir("alternate/2", 0777));
path.ptr[path.size - 1] = '2';
cl_git_rewritefile("alternate/2/config", "[core]\n\tabbrev = 20\n");
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_XDG, path.ptr));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(20, val);
git_repository_free(repo);
/* with global + xdg + system */
cl_must_pass(p_mkdir("alternate/3", 0777));
path.ptr[path.size - 1] = '3';
cl_git_rewritefile("alternate/3/.gitconfig", "[core]\n\tabbrev = 30\n");
cl_git_pass(git_libgit2_opts(
GIT_OPT_SET_SEARCH_PATH, GIT_CONFIG_LEVEL_GLOBAL, path.ptr));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(30, val);
git_repository_free(repo);
/* with all configs */
cl_git_rewritefile("empty_standard_repo/.git/config", "[core]\n\tabbrev = 40\n");
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(40, val);
git_repository_free(repo);
/* with all configs but delete the files ? */
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(40, val);
cl_must_pass(p_unlink("empty_standard_repo/.git/config"));
cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
cl_must_pass(p_unlink("alternate/1/gitconfig"));
cl_assert(!git_path_isfile("alternate/1/gitconfig"));
cl_must_pass(p_unlink("alternate/2/config"));
cl_assert(!git_path_isfile("alternate/2/config"));
cl_must_pass(p_unlink("alternate/3/.gitconfig"));
cl_assert(!git_path_isfile("alternate/3/.gitconfig"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(40, val);
git_repository_free(repo);
/* reopen */
cl_assert(!git_path_isfile("empty_standard_repo/.git/config"));
cl_assert(!git_path_isfile("alternate/3/.gitconfig"));
cl_git_pass(git_repository_open(&repo, "empty_standard_repo"));
git_repository__configmap_lookup_cache_clear(repo);
val = -1;
cl_git_pass(git_repository__configmap_lookup(&val, repo, GIT_CONFIGMAP_ABBREV));
cl_assert_equal_i(7, val);
git_repository_free(repo);
cl_assert(!git_path_exists("empty_standard_repo/.git/config"));
cl_assert(!git_path_exists("alternate/3/.gitconfig"));
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.