void test_network_remotelocal__retrieve_advertised_references(void) { int how_many_refs = 0; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); cl_assert_equal_i(how_many_refs, 26); }
void test_odb_foreach__interrupt_foreach(void) { int nobj = 0; cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); git_repository_odb(&_odb, _repo); cl_assert_equal_i(-321, git_odb_foreach(_odb, foreach_stop_cb, &nobj)); cl_assert(nobj == 1000); }
void test_network_remote_local__retrieve_advertised_before_connect(void) { const git_remote_head **refs; size_t refs_len = 0; git_buf_sets(&file_path_buf, cl_git_path_url(cl_fixture("testrepo.git"))); cl_git_pass(git_remote_create_anonymous(&remote, repo, git_buf_cstr(&file_path_buf))); cl_git_fail(git_remote_ls(&refs, &refs_len, remote)); }
void test_network_remotelocal__retrieve_advertised_references(void) { int how_many_refs = 0; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); cl_assert(how_many_refs == 14); /* 1 HEAD + 6 heads + 1 lightweight tag + 3 annotated tags + 3 peeled target */ }
/* * $ git --git-dir tests/resources/testrepo.git count-objects --verbose * count: 47 * size: 4 * in-pack: 1640 * packs: 3 * size-pack: 425 * prune-packable: 0 * garbage: 0 */ void test_odb_foreach__foreach(void) { int nobj = 0; cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); git_repository_odb(&_odb, _repo); cl_git_pass(git_odb_foreach(_odb, foreach_cb, &nobj)); cl_assert_equal_i(47 + 1640, nobj); /* count + in-pack */ }
void test_attr_file__check_attr_examples(void) { git_attr_file *file; git_attr_rule *rule; git_attr_assignment *assign; cl_git_pass(git_attr_file__new(&file)); cl_git_pass(git_attr_file__from_file(NULL, cl_fixture("attr/attr3"), file)); cl_assert_strequal(cl_fixture("attr/attr3"), file->path); cl_assert(file->rules.length == 3); rule = get_rule(0); cl_assert_strequal("*.java", rule->match.pattern); cl_assert(rule->assigns.length == 3); assign = git_attr_rule__lookup_assignment(rule, "diff"); cl_assert_strequal("diff", assign->name); cl_assert_strequal("java", assign->value); assign = git_attr_rule__lookup_assignment(rule, "crlf"); cl_assert_strequal("crlf", assign->name); cl_assert(GIT_ATTR_FALSE == assign->value); assign = git_attr_rule__lookup_assignment(rule, "myAttr"); cl_assert_strequal("myAttr", assign->name); cl_assert(GIT_ATTR_TRUE == assign->value); assign = git_attr_rule__lookup_assignment(rule, "missing"); cl_assert(assign == NULL); rule = get_rule(1); cl_assert_strequal("NoMyAttr.java", rule->match.pattern); cl_assert(rule->assigns.length == 1); assign = get_assign(rule, 0); cl_assert_strequal("myAttr", assign->name); cl_assert(assign->value == NULL); rule = get_rule(2); cl_assert_strequal("README", rule->match.pattern); cl_assert(rule->assigns.length == 1); assign = get_assign(rule, 0); cl_assert_strequal("caveat", assign->name); cl_assert_strequal("unspecified", assign->value); git_attr_file__free(file); }
void test_network_remote_local__retrieve_advertised_references(void) { const git_remote_head **refs; size_t refs_len; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); cl_assert_equal_i(refs_len, 28); }
static void revwalk_basic_setup_walk(const char *fixture) { if (fixture) { _fixture = fixture; _repo = cl_git_sandbox_init(fixture); } else { cl_git_pass(git_repository_open(&_repo, cl_fixture("testrepo.git"))); } cl_git_pass(git_revwalk_new(&_walk, _repo)); }
/* * $ git blame -n b.txt * orig line no final line no * commit V author timestamp V * da237394 1 (Ben Straub 2013-02-12 15:11:30 -0800 1 * da237394 2 (Ben Straub 2013-02-12 15:11:30 -0800 2 * da237394 3 (Ben Straub 2013-02-12 15:11:30 -0800 3 * da237394 4 (Ben Straub 2013-02-12 15:11:30 -0800 4 * ^b99f7ac 1 (Ben Straub 2013-02-12 15:10:12 -0800 5 * 63d671eb 6 (Ben Straub 2013-02-12 15:13:04 -0800 6 * 63d671eb 7 (Ben Straub 2013-02-12 15:13:04 -0800 7 * 63d671eb 8 (Ben Straub 2013-02-12 15:13:04 -0800 8 * 63d671eb 9 (Ben Straub 2013-02-12 15:13:04 -0800 9 * 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10 * aa06ecca 6 (Ben Straub 2013-02-12 15:14:46 -0800 11 * aa06ecca 7 (Ben Straub 2013-02-12 15:14:46 -0800 12 * aa06ecca 8 (Ben Straub 2013-02-12 15:14:46 -0800 13 * aa06ecca 9 (Ben Straub 2013-02-12 15:14:46 -0800 14 * aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15 */ void test_blame_simple__trivial_blamerepo(void) { cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git"))); cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", NULL)); cl_assert_equal_i(4, git_blame_get_hunk_count(g_blame)); check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "da237394", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 2, 6, 5, 0, "63d671eb", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 3, 11, 5, 0, "aa06ecca", "b.txt"); }
/* * At the beginning of the test: * - config9 has: core.global does not exist * - config15 has: core.global=17 * - config16 has: core.global=29 * * And also: * - config9 has: core.system does not exist * - config15 has: core.system does not exist * - config16 has: core.system=11 */ void test_config_read__fallback_from_local_to_global_and_from_global_to_system(void) { git_config *cfg; int32_t i; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), GIT_CONFIG_LEVEL_LOCAL, NULL, 0)); cl_git_pass(git_config_get_int32(&i, cfg, "core.global")); cl_assert_equal_i(17, i); cl_git_pass(git_config_get_int32(&i, cfg, "core.system")); cl_assert_equal_i(11, i); git_config_free(cfg); }
void test_status_worktree__cannot_retrieve_the_status_of_a_bare_repository(void) { git_repository *repo; unsigned int status = 0; cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_assert_equal_i(GIT_EBAREREPO, git_status_file(&status, repo, "dummy")); git_repository_free(repo); }
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); }
void test_config_read__escaping_quotes(void) { git_config *cfg; const char *str; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config13"))); cl_git_pass(git_config_get_string(&str, cfg, "core.editor")); cl_assert(strcmp(str, "\"C:/Program Files/Nonsense/bah.exe\" \"--some option\"") == 0); git_config_free(cfg); }
/* * If \ is the last non-space character on the line, we read the next * one, separating each line with SP. */ void test_config_read__multiline_value(void) { git_config *cfg; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2"))); cl_git_pass(git_config_get_string_buf(&buf, cfg, "this.That.and")); cl_assert_equal_s("one one one two two three three", git_buf_cstr(&buf)); git_config_free(cfg); }
void test_network_remotelocal__initialize(void) { cl_fixture("remotelocal"); cl_git_pass(git_repository_init(&repo, "remotelocal/", 0)); cl_assert(repo != NULL); build_local_file_url(&file_path_buf, "testrepo.git"); cl_git_pass(git_remote_new(&remote, repo, git_buf_cstr(&file_path_buf), NULL)); cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH)); }
void test_config_read__iterator_invalid_glob(void) { git_config *cfg; git_config_iterator *iter; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); cl_git_fail(git_config_iterator_glob_new(&iter, cfg, "*")); git_config_free(cfg); }
/* * $ git blame -n b.txt -L 8 * orig line no final line no * commit V author timestamp V * 63d671eb 8 (Ben Straub 2013-02-12 15:13:04 -0800 8 * 63d671eb 9 (Ben Straub 2013-02-12 15:13:04 -0800 9 * 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10 * aa06ecca 6 (Ben Straub 2013-02-12 15:14:46 -0800 11 * aa06ecca 7 (Ben Straub 2013-02-12 15:14:46 -0800 12 * aa06ecca 8 (Ben Straub 2013-02-12 15:14:46 -0800 13 * aa06ecca 9 (Ben Straub 2013-02-12 15:14:46 -0800 14 * aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15 */ void test_blame_simple__can_restrict_lines_min(void) { git_blame_options opts = GIT_BLAME_OPTIONS_INIT; cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git"))); opts.min_line = 8; cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts)); cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame)); check_blame_hunk_index(g_repo, g_blame, 0, 8, 3, 0, "63d671eb", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 1, 11, 5, 0, "aa06ecca", "b.txt"); }
void test_config_configlevel__can_read_from_a_single_level_focused_file_after_parent_config_has_been_freed(void) { git_config *cfg; git_config *single_level_cfg; const char *s; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config18"), GIT_CONFIG_LEVEL_GLOBAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config19"), GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_open_level(&single_level_cfg, cfg, GIT_CONFIG_LEVEL_LOCAL)); git_config_free(cfg); cl_git_pass(git_config_get_string(&s, single_level_cfg, "core.stringglobal")); cl_assert_equal_s("don't find me!", s); git_config_free(single_level_cfg); }
/* * If \ is the last non-space character on the line, we read the next * one, separating each line with SP. */ void test_config_read__multiline_value(void) { git_config *cfg; const char *str; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config2"))); cl_git_pass(git_config_get_string(&str, cfg, "this.That.and")); cl_assert_equal_s(str, "one one one two two three three"); git_config_free(cfg); }
void test_config_read__foreach(void) { git_config *cfg; int count, ret; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); count = 0; cl_git_pass(git_config_foreach(cfg, count_cfg_entries_and_compare_levels, &count)); cl_assert_equal_i(7, count); count = 3; cl_git_fail(ret = git_config_foreach(cfg, cfg_callback_countdown, &count)); cl_assert_equal_i(-100, ret); git_config_free(cfg); }
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_config_read__iterator(void) { const char *keys[] = { "core.dummy2", "core.verylong", "core.dummy", "remote.ab.url", "remote.abba.url", "core.dummy2", "core.global" }; git_config *cfg; git_config_iterator *iter; git_config_entry *entry; int count, ret; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, NULL, 0)); count = 0; cl_git_pass(git_config_iterator_new(&iter, cfg)); while ((ret = git_config_next(&entry, iter)) == 0) { cl_assert_equal_s(entry->name, keys[count]); count++; } git_config_iterator_free(iter); cl_assert_equal_i(GIT_ITEROVER, ret); cl_assert_equal_i(7, count); count = 3; cl_git_pass(git_config_iterator_new(&iter, cfg)); git_config_iterator_free(iter); git_config_free(cfg); }
void test_reset_hard__cannot_reset_in_a_bare_repository(void) { git_repository *bare; cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git"))); cl_assert(git_repository_is_bare(bare) == true); cl_git_pass(git_revparse_single(&target, bare, KNOWN_COMMIT_IN_BARE_REPO)); cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_HARD, NULL)); git_repository_free(bare); }
void test_clone_nonetwork__local_bare(void) { git_buf src = GIT_BUF_INIT; build_local_file_url(&src, cl_fixture("testrepo.git")); #if DO_LOCAL_TEST cl_set_cleanup(&cleanup_repository, "./local.git"); cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL)); #endif git_buf_free(&src); }
/* * $ git blame -n b.txt -L ,6 * orig line no final line no * commit V author timestamp V * da237394 1 (Ben Straub 2013-02-12 15:11:30 -0800 1 * da237394 2 (Ben Straub 2013-02-12 15:11:30 -0800 2 * da237394 3 (Ben Straub 2013-02-12 15:11:30 -0800 3 * da237394 4 (Ben Straub 2013-02-12 15:11:30 -0800 4 * ^b99f7ac 1 (Ben Straub 2013-02-12 15:10:12 -0800 5 * 63d671eb 6 (Ben Straub 2013-02-12 15:13:04 -0800 6 */ void test_blame_simple__can_restrict_lines_max(void) { git_blame_options opts = GIT_BLAME_OPTIONS_INIT; cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git"))); opts.max_line = 6; cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts)); cl_assert_equal_i(3, git_blame_get_hunk_count(g_blame)); check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "da237394", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 1, 5, 1, 1, "b99f7ac0", "b.txt"); check_blame_hunk_index(g_repo, g_blame, 2, 6, 1, 0, "63d671eb", "b.txt"); }
void test_odb_foreach__one_pack(void) { git_odb_backend *backend = NULL; cl_git_pass(git_odb_new(&_odb)); cl_git_pass(git_odb_backend_one_pack(&backend, cl_fixture("testrepo.git/objects/pack/pack-a81e489679b7d3418f9ab594bda8ceb37dd4c695.idx"))); cl_git_pass(git_odb_add_backend(_odb, backend, 1)); _repo = NULL; nobj = 0; cl_git_pass(git_odb_foreach(_odb, foreach_cb, NULL)); cl_assert(nobj == 1628); }
void test_index_tests__add_bypath_to_a_bare_repository_returns_EBAREPO(void) { git_repository *bare_repo; git_index *index; cl_git_pass(git_repository_open(&bare_repo, cl_fixture("testrepo.git"))); cl_git_pass(git_repository_index(&index, bare_repo)); cl_assert_equal_i(GIT_EBAREREPO, git_index_add_bypath(index, "test.txt")); git_index_free(index); git_repository_free(bare_repo); }
void test_reset_mixed__cannot_reset_in_a_bare_repository(void) { git_repository *bare; cl_git_pass(git_repository_open(&bare, cl_fixture("testrepo.git"))); cl_assert(git_repository_is_bare(bare) == true); retrieve_target_from_oid(&target, bare, KNOWN_COMMIT_IN_BARE_REPO); cl_assert_equal_i(GIT_EBAREREPO, git_reset(bare, target, GIT_RESET_MIXED)); git_repository_free(bare); }
void test_object_cache__cache_everything(void) { int i, start; git_oid oid; git_odb_object *odb_obj; git_object *obj; git_odb *odb; git_libgit2_opts( GIT_OPT_SET_CACHE_OBJECT_LIMIT, (int)GIT_OBJ_BLOB, (size_t)32767); 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_OBJ_ANY)); cl_assert(g_data[i].type == git_object_type(obj)); git_object_free(obj); } cl_assert_equal_i(count + 1, (int)git_cache_size(&g_repo->objects)); } cl_assert_equal_i(i, (int)git_cache_size(&g_repo->objects) - start); git_odb_free(odb); 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_OBJ_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)); } }
void test_config_read__iterator_glob(void) { git_config *cfg; cl_git_pass(git_config_open_ondisk(&cfg, cl_fixture("config/config9"))); check_glob_iter(cfg, "core.*", 3); check_glob_iter(cfg, "remote\\.ab.*", 2); check_glob_iter(cfg, ".*url$", 2); check_glob_iter(cfg, ".*dummy.*", 2); check_glob_iter(cfg, ".*nomatch.*", 0); git_config_free(cfg); }