void test_network_remote_remotes__cannot_add_a_remote_with_an_invalid_name(void) { git_remote *remote = NULL; cl_assert_equal_i( GIT_EINVALIDSPEC, git_remote_create(&remote, _repo, "Inv@{id", "git://github.com/libgit2/libgit2")); cl_assert_equal_p(remote, NULL); cl_assert_equal_i( GIT_EINVALIDSPEC, git_remote_create(&remote, _repo, "", "git://github.com/libgit2/libgit2")); cl_assert_equal_p(remote, NULL); }
/** * Add a remote with the default fetch refspec to the repository's * configuration. * * @param repo S4 class git_repository * @param name The name of the remote * @param url The url of the remote * @return R_NilValue */ SEXP git2r_remote_add(SEXP repo, SEXP name, SEXP url) { int err; git_repository *repository = NULL; git_remote *remote = NULL; if (git2r_arg_check_string(name)) git2r_error(__func__, NULL, "'name'", git2r_err_string_arg); if (git2r_arg_check_string(url)) git2r_error(__func__, NULL, "'url'", git2r_err_string_arg); if (!git_remote_is_valid_name(CHAR(STRING_ELT(name, 0)))) git2r_error(__func__, NULL, git2r_err_invalid_remote, NULL); repository = git2r_repository_open(repo); if (!repository) git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL); err = git_remote_create( &remote, repository, CHAR(STRING_ELT(name, 0)), CHAR(STRING_ELT(url, 0))); if (remote) git_remote_free(remote); if (repository) git_repository_free(repository); if (err) git2r_error(__func__, giterr_last(), NULL, NULL); return R_NilValue; }
/** * Add a remote with the default fetch refspec to the repository's * configuration. * * @param repo S4 class git_repository * @param name The name of the remote * @param url The url of the remote * @return R_NilValue */ SEXP git2r_remote_add(SEXP repo, SEXP name, SEXP url) { int err; git_repository *repository = NULL; git_remote *remote = NULL; if (git2r_arg_check_string(name)) git2r_error(git2r_err_string_arg, __func__, "name"); if (git2r_arg_check_string(url)) git2r_error(git2r_err_string_arg, __func__, "url"); if (!git_remote_is_valid_name(CHAR(STRING_ELT(name, 0)))) git2r_error("Error in '%s': Invalid remote name", __func__, NULL); repository = git2r_repository_open(repo); if (!repository) git2r_error(git2r_err_invalid_repository, __func__, NULL); err = git_remote_create(&remote, repository, CHAR(STRING_ELT(name, 0)), CHAR(STRING_ELT(url, 0))); if (remote) git_remote_free(remote); if (repository) git_repository_free(repository); if (GIT_OK != err) git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message); return R_NilValue; }
static int remote_mirror_cb(git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { int error; git_remote *remote; git_remote_callbacks *callbacks = (git_remote_callbacks *) payload; if ((error = git_remote_create(&remote, repo, name, url)) < 0) return error; if ((error = git_remote_set_callbacks(remote, callbacks)) < 0) { git_remote_free(remote); return error; } git_remote_clear_refspecs(remote); if ((error = git_remote_add_fetch(remote, "+refs/*:refs/*")) < 0) { git_remote_free(remote); return error; } *out = remote; return 0; }
void test_network_fetchlocal__clone_into_mirror(void) { git_buf path = GIT_BUF_INIT; git_repository *repo; git_remote *remote; git_reference *head; cl_git_pass(git_repository_init(&repo, "./foo.git", true)); cl_git_pass(git_remote_create(&remote, repo, "origin", cl_git_fixture_url("testrepo.git"))); git_remote_clear_refspecs(remote); cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*")); cl_git_pass(git_clone_into(repo, remote, NULL, NULL, NULL)); cl_git_pass(git_reference_lookup(&head, repo, "HEAD")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); git_remote_free(remote); git_reference_free(head); git_repository_free(repo); git_buf_free(&path); cl_fixture_cleanup("./foo.git"); }
void test_network_remote_local__update_tips_for_new_remote(void) { git_repository *src_repo; git_repository *dst_repo; git_remote *new_remote; git_reference* branch; /* Copy test repo */ cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&src_repo, "testrepo.git")); /* Set up an empty bare repo to push into */ cl_git_pass(git_repository_init(&dst_repo, "./localbare.git", 1)); /* Push to bare repo */ cl_git_pass(git_remote_create(&new_remote, src_repo, "bare", "./localbare.git")); cl_git_pass(git_remote_push(new_remote, &push_array, NULL)); /* Make sure remote branch has been created */ cl_git_pass(git_branch_lookup(&branch, src_repo, "bare/master", GIT_BRANCH_REMOTE)); git_reference_free(branch); git_remote_free(new_remote); git_repository_free(dst_repo); cl_fixture_cleanup("localbare.git"); git_repository_free(src_repo); cl_fixture_cleanup("testrepo.git"); }
void test_network_fetchlocal__complete(void) { git_repository *repo; git_remote *origin; int callcount = 0; git_strarray refnames = {0}; const char *url = cl_git_fixture_url("testrepo.git"); git_fetch_options options = GIT_FETCH_OPTIONS_INIT; options.callbacks.transfer_progress = transfer_cb; options.callbacks.payload = &callcount; cl_set_cleanup(&cleanup_local_repo, "foo"); cl_git_pass(git_repository_init(&repo, "foo", true)); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(19, (int)refnames.count); cl_assert(callcount > 0); git_strarray_free(&refnames); git_remote_free(origin); git_repository_free(repo); }
void test_network_remote_remotes__nonmatch_upstream_refspec(void) { git_config *config; git_remote *remote; char *specstr[] = { "refs/tags/*:refs/tags/*", }; git_strarray specs = { specstr, 1, }; cl_git_pass(git_remote_create(&remote, _repo, "taggy", git_repository_path(_repo))); /* * Set the current branch's upstream remote to a dummy ref so we call into the code * which tries to check for the current branch's upstream in the refspecs */ cl_git_pass(git_repository_config(&config, _repo)); cl_git_pass(git_config_set_string(config, "branch.master.remote", "taggy")); cl_git_pass(git_config_set_string(config, "branch.master.merge", "refs/heads/foo")); cl_git_pass(git_remote_fetch(remote, &specs, NULL, NULL)); git_remote_free(remote); }
void test_network_remote_local__push_delete(void) { git_repository *src_repo; git_repository *dst_repo; git_remote *remote; git_reference *ref; char *spec_push[] = { "refs/heads/master" }; char *spec_delete[] = { ":refs/heads/master" }; git_strarray specs = { spec_push, 1, }; src_repo = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_repository_init(&dst_repo, "target.git", 1)); cl_git_pass(git_remote_create(&remote, src_repo, "origin", "./target.git")); /* Push the master branch and verify it's there */ cl_git_pass(git_remote_push(remote, &specs, NULL)); cl_git_pass(git_reference_lookup(&ref, dst_repo, "refs/heads/master")); git_reference_free(ref); specs.strings = spec_delete; cl_git_pass(git_remote_push(remote, &specs, NULL)); cl_git_fail(git_reference_lookup(&ref, dst_repo, "refs/heads/master")); git_remote_free(remote); git_repository_free(dst_repo); cl_fixture_cleanup("target.git"); cl_git_sandbox_cleanup(); }
void test_online_clone__clone_mirror(void) { git_buf path = GIT_BUF_INIT; git_remote *remote; git_reference *head; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; bool fetch_progress_cb_was_called = false; cl_git_pass(git_repository_init(&g_repo, "./foo.git", true)); cl_git_pass(git_remote_create(&remote, g_repo, "origin", LIVE_REPO_URL)); callbacks.transfer_progress = &fetch_progress; callbacks.payload = &fetch_progress_cb_was_called; git_remote_set_callbacks(remote, &callbacks); git_remote_clear_refspecs(remote); cl_git_pass(git_remote_add_fetch(remote, "+refs/*:refs/*")); cl_git_pass(git_clone_into(g_repo, remote, NULL, NULL, NULL)); cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); cl_assert_equal_i(true, fetch_progress_cb_was_called); git_remote_free(remote); git_reference_free(head); git_buf_free(&path); git_repository_free(g_repo); g_repo = NULL; cl_fixture_cleanup("./foo.git"); }
static int create_and_configure_origin( git_remote **out, git_repository *repo, const char *url, const git_clone_options *options) { int error; git_remote *origin = NULL; const char *name; name = options->remote_name ? options->remote_name : "origin"; if ((error = git_remote_create(&origin, repo, name, url)) < 0) goto on_error; if (options->ignore_cert_errors) git_remote_check_cert(origin, 0); if ((error = git_remote_set_callbacks(origin, &options->remote_callbacks)) < 0) goto on_error; if ((error = git_remote_save(origin)) < 0) goto on_error; *out = origin; return 0; on_error: git_remote_free(origin); return error; }
void test_network_fetchlocal__partial(void) { git_repository *repo = cl_git_sandbox_init("partial-testrepo"); git_remote *origin; int callcount = 0; git_strarray refnames = {0}; const char *url; git_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; callbacks.transfer_progress = transfer_cb; callbacks.payload = &callcount; cl_set_cleanup(&cleanup_sandbox, NULL); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(1, (int)refnames.count); url = cl_git_fixture_url("testrepo.git"); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url)); git_remote_set_callbacks(origin, &callbacks); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_download(origin)); cl_git_pass(git_remote_update_tips(origin, NULL, NULL)); git_strarray_free(&refnames); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(20, (int)refnames.count); /* 18 remote + 1 local */ cl_assert(callcount > 0); git_strarray_free(&refnames); git_remote_free(origin); }
void test_network_remote_remotes__cannot_add_a_nameless_remote(void) { git_remote *remote; cl_assert_equal_i( GIT_EINVALIDSPEC, git_remote_create(&remote, _repo, NULL, "git://github.com/libgit2/libgit2")); }
void assert_cannot_create_remote(const char *name, int expected_error) { git_remote *remote = NULL; cl_git_fail_with( git_remote_create(&remote, _repo, name, "git://github.com/libgit2/libgit2"), expected_error); cl_assert_equal_p(remote, NULL); }
void test_network_fetchlocal__prune(void) { git_repository *repo; git_remote *origin; int callcount = 0; git_strarray refnames = {0}; git_reference *ref; git_repository *remote_repo = cl_git_sandbox_init("testrepo.git"); const char *url = cl_git_path_url(git_repository_path(remote_repo)); git_fetch_options options = GIT_FETCH_OPTIONS_INIT; options.callbacks.transfer_progress = transfer_cb; options.callbacks.payload = &callcount; cl_set_cleanup(&cleanup_local_repo, "foo"); cl_git_pass(git_repository_init(&repo, "foo", true)); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(19, (int)refnames.count); cl_assert(callcount > 0); git_strarray_free(&refnames); git_remote_free(origin); cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/br2")); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(18, (int)refnames.count); git_strarray_free(&refnames); git_remote_free(origin); cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/packed")); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(17, (int)refnames.count); git_strarray_free(&refnames); git_remote_free(origin); git_repository_free(repo); }
static int default_remote_create( git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { GIT_UNUSED(payload); return git_remote_create(out, repo, name, url); }
int custom_origin_name_remote_create( git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { GIT_UNUSED(name); GIT_UNUSED(payload); return git_remote_create(out, repo, "my_origin", url); }
void test_online_fetch__fetch_twice(void) { git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "git://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_download(remote)); git_remote_disconnect(remote); git_remote_connect(remote, GIT_DIRECTION_FETCH); cl_git_pass(git_remote_download(remote)); git_remote_disconnect(remote); git_remote_free(remote); }
static int default_remote_create( git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { int error; git_remote_callbacks *callbacks = payload; if ((error = git_remote_create(out, repo, name, url)) < 0) return error; return git_remote_set_callbacks(*out, callbacks); }
void test_refs_branches_remote__ambiguous_remote_returns_error(void) { git_remote *remote; /* Create the remote */ cl_git_pass(git_remote_create(&remote, g_repo, "addtest", "http://github.com/libgit2/libgit2")); /* Update the remote fetch spec */ cl_git_pass(git_remote_set_fetchspec(remote, "refs/heads/*:refs/remotes/test/*")); cl_git_pass(git_remote_save(remote)); git_remote_free(remote); cl_git_fail_with(git_branch_remote_name(NULL, 0, g_repo, remote_tracking_branch_name), GIT_EAMBIGUOUS); }
PyObject * Repository_create_remote(Repository *self, PyObject *args) { git_remote *remote; char *name = NULL, *url = NULL; int err; if (!PyArg_ParseTuple(args, "ss", &name, &url)) return NULL; err = git_remote_create(&remote, self->repo, name, url); if (err < 0) return Error_set(err); return (PyObject*) wrap_remote(remote, self); }
void test_network_remote_defaultbranch__no_default_branch(void) { git_remote *remote_b; const git_remote_head **heads; size_t len; git_buf buf = GIT_BUF_INIT; cl_git_pass(git_remote_create(&remote_b, g_repo_b, "self", git_repository_path(g_repo_b))); cl_git_pass(git_remote_connect(remote_b, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_ls(&heads, &len, remote_b)); cl_assert_equal_i(0, len); cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, remote_b)); git_remote_free(remote_b); }
PyObject * Repository_remote_create(Repository *self, PyObject *args) { git_remote *remote; char *name = NULL, *url = NULL; int err; if (!PyArg_ParseTuple(args, "ss", &name, &url)) return NULL; err = git_remote_create(&remote, self->repo, name, url); if (err < 0) return Error_set(err); return INSTANCIATE_CLASS(RemoteType, Py_BuildValue("Os", self, name)); }
static int custom_remote_ssh_with_paths( git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { int error; GIT_UNUSED(payload); if ((error = git_remote_create(out, repo, name, url)) < 0) return error; return 0; }
void test_online_fetch__ls_disconnected(void) { git_remote *remote; int nr_before = 0, nr_after = 0; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_ls(remote, ls_cb, &nr_before)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(remote, ls_cb, &nr_after)); cl_assert_equal_i(nr_before, nr_after); git_remote_free(remote); }
static int create_and_configure_origin( git_remote **out, git_repository *repo, const char *url, const git_clone_options *options) { int error; git_remote *origin = NULL; if ((error = git_remote_create(&origin, repo, options->remote_name, url)) < 0) goto on_error; git_remote_set_cred_acquire_cb(origin, options->cred_acquire_cb, options->cred_acquire_payload); git_remote_set_autotag(origin, options->remote_autotag); /* * Don't write FETCH_HEAD, we'll check out the remote tracking * branch ourselves based on the server's default. */ git_remote_set_update_fetchhead(origin, 0); if (options->remote_callbacks && (error = git_remote_set_callbacks(origin, options->remote_callbacks)) < 0) goto on_error; if (options->fetch_spec && (error = git_remote_set_fetchspec(origin, options->fetch_spec)) < 0) goto on_error; if (options->push_spec && (error = git_remote_set_pushspec(origin, options->push_spec)) < 0) goto on_error; if (options->pushurl && (error = git_remote_set_pushurl(origin, options->pushurl)) < 0) goto on_error; if ((error = git_remote_save(origin)) < 0) goto on_error; *out = origin; return 0; on_error: git_remote_free(origin); return error; }
static int custom_transport_remote_create( git_remote **out, git_repository *repo, const char *name, const char *url, void *payload) { int error; if ((error = git_remote_create(out, repo, name, url)) < 0) return error; if ((error = git_remote_set_transport(*out, custom_transport, payload)) < 0) return error; return 0; }
void test_online_fetch__ls_disconnected(void) { const git_remote_head **refs; size_t refs_len_before, refs_len_after; git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote)); cl_assert_equal_i(refs_len_before, refs_len_after); git_remote_free(remote); }
void test_online_fetch__remote_symrefs(void) { const git_remote_head **refs; size_t refs_len; git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); cl_assert_equal_s("HEAD", refs[0]->name); cl_assert_equal_s("refs/heads/master", refs[0]->symref_target); git_remote_free(remote); }
emacs_value egit_remote_create(emacs_env *env, emacs_value _repo, emacs_value _name, emacs_value _url) { EGIT_ASSERT_REPOSITORY(_repo); EM_ASSERT_STRING(_name); EM_ASSERT_STRING(_url); git_repository *repo = EGIT_EXTRACT(_repo); char *name = EM_EXTRACT_STRING(_name); char *url = EM_EXTRACT_STRING(_url); git_remote *remote; int retval = git_remote_create(&remote, repo, name, url); free(name); free(url); EGIT_CHECK_ERROR(retval); return egit_wrap(env, EGIT_REMOTE, remote, EM_EXTRACT_USER_PTR(_repo)); }