static int setup_remotes_and_fetch( git_repository *repo, const char *origin_url, git_transfer_progress_callback progress_cb, void *progress_payload) { int retcode = GIT_ERROR; git_remote *origin = NULL; /* Create the "origin" remote */ if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) { /* Connect and download everything */ if (!git_remote_connect(origin, GIT_DIR_FETCH)) { if (!git_remote_download(origin, progress_cb, progress_payload)) { /* Create "origin/foo" branches for all remote branches */ if (!git_remote_update_tips(origin)) { /* Point HEAD to the same ref as the remote's head */ if (!update_head_to_remote(repo, origin)) { retcode = 0; } } } git_remote_disconnect(origin); } git_remote_free(origin); } return retcode; }
void test_network_remotes__add(void) { git_remote_free(_remote); cl_git_pass(git_remote_add(&_remote, _repo, "addtest", "http://github.com/libgit2/libgit2")); git_remote_free(_remote); cl_git_pass(git_remote_load(&_remote, _repo, "addtest")); _refspec = git_remote_fetchspec(_remote); cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*")); cl_assert(!strcmp(git_refspec_dst(_refspec), "refs/remotes/addtest/*")); }