void test_transport_register__custom_transport_ssh(void) { git_transport *transport; #ifndef GIT_SSH cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://*****:*****@somehost:somepath"), -1); #else cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath")); #endif cl_git_pass(git_transport_register("ssh", dummy_transport, NULL)); cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath")); cl_assert(transport == &_transport); cl_git_pass(git_transport_unregister("ssh")); #ifndef GIT_SSH cl_git_fail_with(git_transport_new(&transport, NULL, "ssh://*****:*****@somehost:somepath"), -1); #else cl_git_pass(git_transport_new(&transport, NULL, "git@somehost:somepath")); #endif }
void test_diff_parse__nonpatches_fail_with_notfound(void) { git_diff *diff; const char *not = PATCH_NOT_A_PATCH; const char *not_with_leading = "Leading text.\n" PATCH_NOT_A_PATCH; const char *not_with_trailing = PATCH_NOT_A_PATCH "Trailing text.\n"; const char *not_with_both = "Lead.\n" PATCH_NOT_A_PATCH "Trail.\n"; cl_git_fail_with(GIT_ENOTFOUND, git_diff_from_buffer(&diff, not, strlen(not))); cl_git_fail_with(GIT_ENOTFOUND, git_diff_from_buffer(&diff, not_with_leading, strlen(not_with_leading))); cl_git_fail_with(GIT_ENOTFOUND, git_diff_from_buffer(&diff, not_with_trailing, strlen(not_with_trailing))); cl_git_fail_with(GIT_ENOTFOUND, git_diff_from_buffer(&diff, not_with_both, strlen(not_with_both))); }
void test_stash_drop__cannot_drop_a_non_existing_stashed_state(void) { push_three_states(); cl_git_fail_with(git_stash_drop(repo, 666), GIT_ENOTFOUND); cl_git_fail_with(git_stash_drop(repo, 42), GIT_ENOTFOUND); cl_git_fail_with(git_stash_drop(repo, 3), GIT_ENOTFOUND); }
void test_config_write__locking(void) { git_config *cfg, *cfg2; git_config_entry *entry; git_transaction *tx; const char *filename = "locked-file"; /* Open the config and lock it */ cl_git_mkfile(filename, "[section]\n\tname = value\n"); cl_git_pass(git_config_open_ondisk(&cfg, filename)); cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_lock(&tx, cfg)); /* Change entries in the locked backend */ cl_git_pass(git_config_set_string(cfg, "section.name", "other value")); cl_git_pass(git_config_set_string(cfg, "section2.name3", "more value")); /* We can see that the file we read from hasn't changed */ cl_git_pass(git_config_open_ondisk(&cfg2, filename)); cl_git_pass(git_config_get_entry(&entry, cfg2, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg2, "section2.name3")); git_config_free(cfg2); /* And we also get the old view when we read from the locked config */ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("value", entry->value); git_config_entry_free(entry); cl_git_fail_with(GIT_ENOTFOUND, git_config_get_entry(&entry, cfg, "section2.name3")); cl_git_pass(git_transaction_commit(tx)); git_transaction_free(tx); /* Now that we've unlocked it, we should see both updates */ cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("other value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3")); cl_assert_equal_s("more value", entry->value); git_config_entry_free(entry); git_config_free(cfg); /* We should also see the changes after reopening the config */ cl_git_pass(git_config_open_ondisk(&cfg, filename)); cl_git_pass(git_config_get_entry(&entry, cfg, "section.name")); cl_assert_equal_s("other value", entry->value); git_config_entry_free(entry); cl_git_pass(git_config_get_entry(&entry, cfg, "section2.name3")); cl_assert_equal_s("more value", entry->value); git_config_entry_free(entry); git_config_free(cfg); }
void test_online_clone__certificate_invalid(void) { g_options.fetch_opts.callbacks.certificate_check = fail_certificate_check; cl_git_fail_with(git_clone(&g_repo, "https://github.com/libgit2/TestGitRepository", "./foo", &g_options), GIT_ECERTIFICATE); #ifdef GIT_SSH cl_git_fail_with(git_clone(&g_repo, "ssh://github.com/libgit2/TestGitRepository", "./foo", &g_options), GIT_ECERTIFICATE); #endif }
static void assert_invalid_config_key_name(const char *name) { cl_git_fail_with(git_config_get_string(&value, cfg, name), GIT_EINVALIDSPEC); cl_git_fail_with(git_config_set_string(cfg, name, "42"), GIT_EINVALIDSPEC); cl_git_fail_with(git_config_delete_entry(cfg, name), GIT_EINVALIDSPEC); cl_git_fail_with(git_config_get_multivar_foreach(cfg, name, "*", NULL, NULL), GIT_EINVALIDSPEC); cl_git_fail_with(git_config_set_multivar(cfg, name, "*", "42"), GIT_EINVALIDSPEC); }
void test_checkout_tree__can_cancel_checkout_from_notify(void) { struct checkout_cancel_at ca; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; assert_on_branch(g_repo, "master"); cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); ca.filename = "new.txt"; ca.error = -5555; ca.count = 0; opts.notify_flags = GIT_CHECKOUT_NOTIFY_UPDATED; opts.notify_cb = checkout_cancel_cb; opts.notify_payload = &ca; opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_assert(!git_path_exists("testrepo/new.txt")); cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), -5555); cl_assert(!git_path_exists("testrepo/new.txt")); /* on case-insensitive FS = a/b.txt, branch_file.txt, new.txt */ /* on case-sensitive FS = README, then above */ if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(3, ca.count); else cl_assert_equal_i(4, ca.count); /* and again with a different stopping point and return code */ ca.filename = "README"; ca.error = 123; ca.count = 0; cl_git_fail_with(git_checkout_tree(g_repo, obj, &opts), 123); cl_assert(!git_path_exists("testrepo/new.txt")); if (git_path_exists("testrepo/.git/CoNfIg")) /* case insensitive */ cl_assert_equal_i(4, ca.count); else cl_assert_equal_i(1, ca.count); git_object_free(obj); }
void test_stream_deprecated__register_tls(void) { git_stream *stream; int error; ctor_called = 0; cl_git_pass(git_stream_register_tls(test_stream_init)); cl_git_pass(git_tls_stream_new(&stream, "localhost", "443")); cl_assert_equal_i(1, ctor_called); cl_assert_equal_p(&test_stream, stream); ctor_called = 0; stream = NULL; cl_git_pass(git_stream_register_tls(NULL)); error = git_tls_stream_new(&stream, "localhost", "443"); /* * We don't have TLS support enabled, or we're on Windows, * which has no arbitrary TLS stream support. */ #if defined(GIT_WIN32) || !defined(GIT_HTTPS) cl_git_fail_with(-1, error); #else cl_git_pass(error); #endif cl_assert_equal_i(0, ctor_called); cl_assert(&test_stream != stream); git_stream_free(stream); }
void test_apply_both__application_failure_leaves_workdir_unmodified(void) { git_diff *diff; git_index *index; const char *diff_file = DIFF_MODIFY_TWO_FILES; struct merge_index_entry workdir_expected[] = { { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" }, { 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" }, { 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" }, { 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" }, { 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" }, { 0100644, "8684724651336001c5dbce74bed6736d2443958d", 0, "veal.txt" }, }; size_t workdir_expected_cnt = sizeof(workdir_expected) / sizeof(struct merge_index_entry); /* mutate the workdir */ cl_git_rewritefile("merge-recursive/veal.txt", "This is a modification.\n"); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, "veal.txt")); cl_git_pass(git_index_write(index)); git_index_free(index); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL)); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); git_diff_free(diff); }
void test_apply_both__index_must_match_workdir(void) { git_diff *diff; git_index *index; git_index_entry idx_entry; const char *diff_file = DIFF_MODIFY_TWO_FILES; /* * Append a line to the end of the file in both the index and the * working directory. Although the appended line would allow for * patch application in each, the line appended is different in * each, so the application should not be allowed. */ cl_git_append2file("merge-recursive/asparagus.txt", "This is a modification.\n"); cl_git_pass(git_repository_index(&index, repo)); memset(&idx_entry, 0, sizeof(git_index_entry)); idx_entry.mode = 0100644; idx_entry.path = "asparagus.txt"; cl_git_pass(git_oid_fromstr(&idx_entry.id, "06d3fefb8726ab1099acc76e02dfb85e034b2538")); cl_git_pass(git_index_add(index, &idx_entry)); cl_git_pass(git_index_write(index)); git_index_free(index); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL)); git_diff_free(diff); }
void test_network_remote_local__push_to_non_bare_remote(void) { char *refspec_strings[] = { "master:master", }; git_strarray array = { refspec_strings, 1, }; /* Shouldn't be able to push to a non-bare remote */ git_remote *localremote; git_fetch_options fetch_opts = GIT_FETCH_OPTIONS_INIT; /* Get some commits */ connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_fetch(remote, &array, &fetch_opts, NULL)); /* Set up an empty non-bare repo to push into */ { git_repository *remoterepo = NULL; cl_git_pass(git_repository_init(&remoterepo, "localnonbare", 0)); git_repository_free(remoterepo); } /* Connect to the bare repo */ cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localnonbare")); cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL, NULL, NULL)); /* Try to push */ cl_git_fail_with(GIT_EBAREREPO, git_remote_upload(localremote, &push_array, NULL)); /* Clean up */ git_remote_free(localremote); cl_fixture_cleanup("localbare.git"); }
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_network_remote_remotes__error_when_no_push_available(void) { git_remote *r; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; char *specs = { "refs/heads/master", }; git_strarray arr = { &specs, 1, }; cl_git_pass(git_remote_create_anonymous(&r, _repo, cl_fixture("testrepo.git"))); callbacks.transport = git_transport_local; cl_git_pass(git_remote_connect(r, GIT_DIRECTION_PUSH, &callbacks, NULL)); /* Make sure that push is really not available */ r->transport->push = NULL; cl_git_fail_with(-1, git_remote_upload(r, &arr, NULL)); git_remote_free(r); }
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 (!filesystem_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(&_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, _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); #endif }
void test_core_stream__register_tls(void) { git_stream *stream; int error; ctor_called = 0; cl_git_pass(git_stream_register_tls(test_ctor)); cl_git_pass(git_tls_stream_new(&stream, "localhost", "443")); cl_assert_equal_i(1, ctor_called); cl_assert_equal_p(&test_stream, stream); ctor_called = 0; stream = NULL; cl_git_pass(git_stream_register_tls(NULL)); error = git_tls_stream_new(&stream, "localhost", "443"); /* We don't have arbitrary TLS stream support on Windows * or when openssl support is disabled (except on OSX * with Security framework). */ #if defined(GIT_WIN32) || \ (!defined(GIT_SECURE_TRANSPORT) && !defined(GIT_OPENSSL)) cl_git_fail_with(-1, error); #else cl_git_pass(error); #endif cl_assert_equal_i(0, ctor_called); cl_assert(&test_stream != stream); git_stream_free(stream); }
void test_refs_branches_remote__no_matching_remote_returns_error(void) { const char *unknown = "refs/remotes/nonexistent/master"; cl_git_fail_with(git_branch_remote_name( NULL, 0, g_repo, unknown), GIT_ENOTFOUND); }
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_network_remote_defaultbranch__detached_sharing_nonbranch_id(void) { git_oid id, id_cloned; git_reference *ref; git_buf buf = GIT_BUF_INIT; git_repository *cloned_repo; cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD")); cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL)); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master")); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good")); cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH)); cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, g_remote)); cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./local-detached", NULL)); cl_assert(git_repository_head_detached(cloned_repo)); cl_git_pass(git_reference_name_to_id(&id_cloned, g_repo_a, "HEAD")); cl_assert(git_oid_equal(&id, &id_cloned)); git_repository_free(cloned_repo); }
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) { git_reference *ref; git_buf log_path = GIT_BUF_INIT; git_oid id; /* Create a new branch pointing at the HEAD */ git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_reference_free(ref); git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head"); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path))); /* delete the ref manually, leave the reflog */ cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); /* new ref creation should fail since new-dir contains reflogs still */ git_oid_fromstr(&id, current_master_tip); cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); git_buf_dispose(&log_path); }
void test_network_remote_rename__overwrite_ref_in_target(void) { git_oid id; char idstr[GIT_OID_HEXSZ + 1] = {0}; git_reference *ref; git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); /* make sure there's only one remote-tracking branch */ cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE)); cl_git_pass(git_branch_next(&ref, &btype, iter)); cl_assert_equal_s("refs/remotes/renamed/master", git_reference_name(ref)); git_oid_fmt(idstr, git_reference_target(ref)); cl_assert_equal_s("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", idstr); git_reference_free(ref); cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter)); git_branch_iterator_free(iter); }
void test_network_remote_remotes__returns_ENOTFOUND_when_neither_url_nor_pushurl(void) { git_remote *remote = NULL; cl_git_fail_with( git_remote_lookup(&remote, _repo, "no-remote-url"), GIT_ENOTFOUND); }
void test_online_clone__can_cancel(void) { g_options.fetch_opts.callbacks.transfer_progress = cancel_at_half; cl_git_fail_with( git_clone(&g_repo, LIVE_REPO_URL, "./foo", &g_options), 4321); }
void test_network_remote_delete__remove_remote_tracking_branches(void) { git_reference *ref; cl_git_pass(git_remote_delete(_remote)); cl_git_fail_with(GIT_ENOTFOUND, git_reference_lookup(&ref, _repo, "refs/remotes/test/master")); }
void test_refs_branches_remote__local_remote_returns_error(void) { const char *local = "refs/heads/master"; cl_git_fail_with(git_branch_remote_name( NULL, 0, g_repo, local), GIT_ERROR); }
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_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_core_filebuf__detects_directory(void) { git_filebuf file = GIT_FILEBUF_INIT, fail = GIT_FILEBUF_INIT; cl_must_pass(p_mkdir("foo", 0777)); cl_git_fail_with(GIT_EDIRECTORY, git_filebuf_open(&file, "foo", 0, 0666)); cl_must_pass(p_rmdir("foo")); }
void test_stash_apply__progress_cb_can_abort(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.progress_cb = aborting_progress_cb; cl_git_fail_with(-44, git_stash_apply(repo, 0, &opts)); }
void test_transport_register__custom_transport_error_doubleregister(void) { cl_git_pass(git_transport_register("something", dummy_transport, NULL)); cl_git_fail_with(git_transport_register("something", dummy_transport, NULL), GIT_EEXISTS); cl_git_pass(git_transport_unregister("something")); }
void test_network_remote_remotes__error_when_not_found(void) { git_remote *r; cl_git_fail_with(git_remote_lookup(&r, _repo, "does-not-exist"), GIT_ENOTFOUND); cl_assert(giterr_last() != NULL); cl_assert(giterr_last()->klass == GITERR_CONFIG); }