void test_network_remote_rename__cannot_overwrite_an_existing_remote(void) { git_strarray problems = {0}; cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(&problems, _repo, _remote_name, "test")); cl_assert_equal_i(GIT_EEXISTS, git_remote_rename(&problems, _repo, _remote_name, "test_with_pushurl")); }
/** * Give the remote a new name * * @param repo S4 class git_repository * @param oldname The old name of the remote * @param newname The new name of the remote * @return R_NilValue */ SEXP git2r_remote_rename(SEXP repo, SEXP oldname, SEXP newname) { int err; git_strarray problems = {0}; git_repository *repository = NULL; if (git2r_arg_check_string(oldname)) git2r_error(__func__, NULL, "'oldname'", git2r_err_string_arg); if (git2r_arg_check_string(newname)) git2r_error(__func__, NULL, "'newname'", git2r_err_string_arg); repository = git2r_repository_open(repo); if (!repository) git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL); err = git_remote_rename( &problems, repository, CHAR(STRING_ELT(oldname, 0)), CHAR(STRING_ELT(newname, 0))); if (err) goto cleanup; git_strarray_free(&problems); cleanup: if (repository) git_repository_free(repository); if (err) git2r_error(__func__, giterr_last(), NULL, NULL); return R_NilValue; }
/** * Give the remote a new name * * @param repo S4 class git_repository * @param oldname The old name of the remote * @param newname The new name of the remote * @return R_NilValue */ SEXP git2r_remote_rename(SEXP repo, SEXP oldname, SEXP newname) { int err; git_strarray problems = {0}; git_repository *repository = NULL; if (git2r_arg_check_string(oldname)) git2r_error(git2r_err_string_arg, __func__, "oldname"); if (git2r_arg_check_string(newname)) git2r_error(git2r_err_string_arg, __func__, "newname"); repository = git2r_repository_open(repo); if (!repository) git2r_error(git2r_err_invalid_repository, __func__, NULL); err = git_remote_rename( &problems, repository, CHAR(STRING_ELT(oldname, 0)), CHAR(STRING_ELT(newname, 0))); if (GIT_OK != err) goto cleanup; git_strarray_free(&problems); cleanup: if (repository) git_repository_free(repository); if (GIT_OK != err) git2r_error(git2r_err_from_libgit2, __func__, giterr_last()->message); return R_NilValue; }
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_remoterename__renaming_a_remote_updates_branch_related_configuration_entries(void) { assert_config_entry_value(_repo, "branch.master.remote", "test"); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); assert_config_entry_value(_repo, "branch.master.remote", "just/renamed"); }
void test_network_remote_rename__nonexistent_returns_enotfound(void) { git_strarray problems = {0}; int err = git_remote_rename(&problems, _repo, "nonexistent", "renamed"); cl_assert_equal_i(GIT_ENOTFOUND, err); }
void test_network_remote_rename__new_name_must_conform_to_reference_naming_conventions(void) { git_strarray problems = {0}; cl_assert_equal_i( GIT_EINVALIDSPEC, git_remote_rename(&problems, _repo, _remote_name, "new@{name")); }
void test_network_remote_rename__new_name_can_contain_dots(void) { git_strarray problems = {0}; cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just.renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); assert_config_entry_existence(_repo, "remote.just.renamed.fetch", true); }
void test_network_remote_rename__cannot_rename_an_inmemory_remote(void) { git_remote *remote; cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "file:///blah")); cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL)); git_remote_free(remote); }
void test_network_remote_rename__renaming_a_remote_updates_default_fetchrefspec(void) { git_strarray problems = {0}; cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*"); }
void test_network_remoterename__renaming_a_remote_moves_related_configuration_section(void) { assert_config_entry_existence(_repo, "remote.test.fetch", true); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); assert_config_entry_existence(_repo, "remote.test.fetch", false); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true); }
void test_network_remote_rename__renaming_a_remote_updates_branch_related_configuration_entries(void) { git_strarray problems = {0}; assert_config_entry_value(_repo, "branch.master.remote", "test"); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); assert_config_entry_value(_repo, "branch.master.remote", "just/renamed"); }
void test_network_remoterename__renaming_a_remote_moves_the_underlying_reference(void) { git_reference *underlying; cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed")); cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/test/master")); git_reference_free(underlying); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/test/master")); cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master")); git_reference_free(underlying); }
void test_network_remote_rename__renaming_a_remote_moves_related_configuration_section(void) { git_strarray problems = {0}; assert_config_entry_existence(_repo, "remote.test.fetch", true); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); assert_config_entry_existence(_repo, "remote.test.fetch", false); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", true); }
void test_network_remoterename__renamed_name_is_persisted(void) { git_remote *renamed; git_repository *another_repo; cl_git_fail(git_remote_load(&renamed, _repo, "just/renamed")); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); cl_git_pass(git_repository_open(&another_repo, "testrepo.git")); cl_git_pass(git_remote_load(&renamed, _repo, "just/renamed")); git_remote_free(renamed); git_repository_free(another_repo); }
void test_network_remoterename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void) { git_config *config; git_remote_free(_remote); cl_git_pass(git_repository_config__weakptr(&config, _repo)); cl_git_pass(git_config_delete(config, "remote.test.fetch")); cl_git_pass(git_remote_load(&_remote, _repo, "test")); assert_config_entry_existence(_repo, "remote.test.fetch", false); cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false); }
void test_network_remoterename__renaming_an_inmemory_remote_persists_it(void) { git_remote *remote; assert_config_entry_existence(_repo, "remote.durable.url", false); cl_git_pass(git_remote_new(&remote, _repo, NULL, "git://github.com/libgit2/durable.git", NULL)); assert_config_entry_existence(_repo, "remote.durable.url", false); cl_git_pass(git_remote_rename(remote, "durable", dont_call_me_cb, NULL)); assert_config_entry_value(_repo, "remote.durable.url", "git://github.com/libgit2/durable.git"); git_remote_free(remote); }
void test_network_remote_rename__renaming_a_remote_moves_the_underlying_reference(void) { git_reference *underlying; git_strarray problems = {0}; cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed")); cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/test/master")); git_reference_free(underlying); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&underlying, _repo, "refs/remotes/test/master")); cl_git_pass(git_reference_lookup(&underlying, _repo, "refs/remotes/just/renamed/master")); git_reference_free(underlying); }
/* * call-seq: * remote.rename!(new_name) -> array or nil * * Renames a remote * * All remote-tracking branches and configuration settings * for the remote are updated. * * Returns +nil+ if everything was updated or array of fetch refspecs * that haven't been automatically updated and need potential manual * tweaking. * * A temporary in-memory remote, created with Remote.new * cannot be given a name with this method. * remote = Rugged::Remote.lookup(@repo, 'origin') * remote.rename!('upstream') #=> nil * */ static VALUE rb_git_remote_rename(VALUE self, VALUE rb_new_name) { git_remote *remote; int error = 0; VALUE rb_refspec_ary = rb_ary_new(); Check_Type(rb_new_name, T_STRING); Data_Get_Struct(self, git_remote, remote); error = git_remote_rename( remote, StringValueCStr(rb_new_name), cb_remote__rename_problem, (void *)rb_refspec_ary); rugged_exception_check(error); return RARRAY_LEN(rb_refspec_ary) == 0 ? Qnil : rb_refspec_ary; }
void test_network_remote_rename__renamed_name_is_persisted(void) { git_remote *renamed; git_repository *another_repo; git_strarray problems = {0}; cl_git_fail(git_remote_lookup(&renamed, _repo, "just/renamed")); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); cl_git_pass(git_repository_open(&another_repo, "testrepo.git")); cl_git_pass(git_remote_lookup(&renamed, _repo, "just/renamed")); git_remote_free(renamed); git_repository_free(another_repo); }
void test_network_remoterename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void) { git_config *config; char *expected_refspecs[] = { "+refs/*:refs/*", NULL }; git_remote_free(_remote); cl_git_pass(git_repository_config__weakptr(&config, _repo)); cl_git_pass(git_config_set_string(config, "remote.test.fetch", "+refs/*:refs/*")); cl_git_pass(git_remote_load(&_remote, _repo, "test")); cl_git_pass(git_remote_rename(_remote, "just/renamed", ensure_refspecs, &expected_refspecs)); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*"); }
void test_network_remote_rename__symref_head(void) { int error; git_reference *ref; git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; char idstr[GIT_OID_HEXSZ + 1] = {0}; git_vector refs; cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, 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); cl_git_pass(git_vector_init(&refs, 2, (git_vector_cmp) git_reference_cmp)); cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE)); while ((error = git_branch_next(&ref, &btype, iter)) == 0) { cl_git_pass(git_vector_insert(&refs, ref)); } cl_assert_equal_i(GIT_ITEROVER, error); git_vector_sort(&refs); cl_assert_equal_i(2, refs.length); ref = git_vector_get(&refs, 0); cl_assert_equal_s("refs/remotes/renamed/HEAD", git_reference_name(ref)); cl_assert_equal_s("refs/remotes/renamed/master", git_reference_symbolic_target(ref)); git_reference_free(ref); ref = git_vector_get(&refs, 1); 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); git_vector_free(&refs); cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter)); git_branch_iterator_free(iter); }
int Remote_name__set__(Remote *self, PyObject* py_name) { int err; char* name; name = py_str_to_c_str(py_name, NULL); if (name != NULL) { err = git_remote_rename(self->remote, name, NULL, NULL); free(name); if (err == GIT_OK) return 0; Error_set(err); } return -1; }
void test_network_remote_rename__renaming_a_remote_without_a_fetchrefspec_doesnt_create_one(void) { git_config *config; git_remote *remote; git_strarray problems = {0}; cl_git_pass(git_repository_config__weakptr(&config, _repo)); cl_git_pass(git_config_delete_entry(config, "remote.test.fetch")); cl_git_pass(git_remote_lookup(&remote, _repo, "test")); git_remote_free(remote); assert_config_entry_existence(_repo, "remote.test.fetch", false); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); assert_config_entry_existence(_repo, "remote.just/renamed.fetch", false); }
void test_network_remote_rename__renaming_a_remote_notifies_of_non_default_fetchrefspec(void) { git_config *config; git_remote *remote; git_strarray problems = {0}; cl_git_pass(git_repository_config__weakptr(&config, _repo)); cl_git_pass(git_config_set_string(config, "remote.test.fetch", "+refs/*:refs/*")); cl_git_pass(git_remote_lookup(&remote, _repo, "test")); git_remote_free(remote); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(1, problems.count); cl_assert_equal_s("+refs/*:refs/*", problems.strings[0]); git_strarray_free(&problems); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/*:refs/*"); git_strarray_free(&problems); }
void test_submodule_add__url_relative(void) { git_submodule *sm; git_remote *remote; /* default remote url is https://github.com/libgit2/false.git */ g_repo = cl_git_sandbox_init("testrepo2"); /* make sure we don't default to origin - rename origin -> test_remote */ cl_git_pass(git_remote_load(&remote, g_repo, "origin")); cl_git_pass(git_remote_rename(remote, "test_remote", NULL, NULL)); cl_git_fail(git_remote_load(&remote, g_repo, "origin")); git_remote_free(remote); cl_git_pass( git_submodule_add_setup(&sm, g_repo, "../TestGitRepository", "TestGitRepository", 1) ); git_submodule_free(sm); assert_submodule_url("TestGitRepository", "https://github.com/libgit2/TestGitRepository"); }
void test_submodule_add__url_relative(void) { git_submodule *sm; git_remote *remote; git_strarray problems = {0}; /* default remote url is https://github.com/libgit2/false.git */ g_repo = cl_git_sandbox_init("testrepo2"); /* make sure we don't default to origin - rename origin -> test_remote */ cl_git_pass(git_remote_rename(&problems, g_repo, "origin", "test_remote")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); cl_git_fail(git_remote_lookup(&remote, g_repo, "origin")); cl_git_pass( git_submodule_add_setup(&sm, g_repo, "../TestGitRepository", "TestGitRepository", 1) ); git_submodule_free(sm); assert_submodule_url("TestGitRepository", "https://github.com/libgit2/TestGitRepository"); }
void test_network_remoterename__renaming_an_inmemory_nameless_remote_notifies_the_inability_to_update_the_fetch_refspec(void) { git_remote *remote; char *expected_refspecs[] = { "+refs/heads/*:refs/remotes/volatile/*", NULL }; assert_config_entry_existence(_repo, "remote.volatile.url", false); cl_git_pass(git_remote_new( &remote, _repo, NULL, "git://github.com/libgit2/volatile.git", "+refs/heads/*:refs/remotes/volatile/*")); cl_git_pass(git_remote_rename(remote, "durable", ensure_refspecs, &expected_refspecs)); git_remote_free(remote); }
/* * call-seq: * remotes.rename(remote, new_name) { |str| } -> remote * remotes.rename(name, new_name) { |str| } -> remote * * Renames a remote. * * All remote-tracking branches and configuration settings * for the remote are updated. * * Non-default refspecs cannot be renamed automatically and will be * yielded to the given block. * * Anonymous, in-memory remotes created through * +ReferenceCollection#create_anonymous+ can not be given a name through * this method. * * Returns a new Rugged::Remote object with the new name. */ static VALUE rb_git_remote_collection_rename(VALUE self, VALUE rb_name_or_remote, VALUE rb_new_name) { VALUE rb_repo = rugged_owner(self); git_repository *repo; size_t i; int error, exception; git_strarray problems; if (!rb_block_given_p()) rb_raise(rb_eArgError, "Rugged::RemoteCollection#rename must be called with a block"); Check_Type(rb_new_name, T_STRING); if (rb_obj_is_kind_of(rb_name_or_remote, rb_cRuggedRemote)) rb_name_or_remote = rb_funcall(rb_name_or_remote, rb_intern("name"), 0); if (TYPE(rb_name_or_remote) != T_STRING) rb_raise(rb_eTypeError, "Expecting a String or Rugged::Remote instance"); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); error = git_remote_rename(&problems, repo, StringValueCStr(rb_name_or_remote), StringValueCStr(rb_new_name)); rugged_exception_check(error); for (i = exception = 0; !exception && i < problems.count; ++i) { rb_protect(rb_yield, rb_str_new_utf8(problems.strings[i]), &exception); } git_strarray_free(&problems); if (exception) rb_jump_tag(exception); return rb_git_remote_collection_aref(self, rb_new_name); }
void test_network_remoterename__renaming_a_remote_updates_default_fetchrefspec(void) { cl_git_pass(git_remote_rename(_remote, "just/renamed", dont_call_me_cb, NULL)); assert_config_entry_value(_repo, "remote.just/renamed.fetch", "+refs/heads/*:refs/remotes/just/renamed/*"); }