static void ensure_repository_init( const char *working_directory, int is_bare, const char *expected_path_repository, const char *expected_working_directory) { const char *workdir; cl_git_pass(git_repository_init(&_repo, working_directory, is_bare)); workdir = git_repository_workdir(_repo); if (workdir != NULL || expected_working_directory != NULL) { cl_assert( git__suffixcmp(workdir, expected_working_directory) == 0 ); } cl_assert( git__suffixcmp(git_repository_path(_repo), expected_path_repository) == 0 ); cl_assert(git_repository_is_bare(_repo) == is_bare); #ifdef GIT_WIN32 if (!is_bare) { cl_assert((GetFileAttributes(git_repository_path(_repo)) & FILE_ATTRIBUTE_HIDDEN) != 0); } #endif cl_assert(git_repository_is_empty(_repo)); }
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(); }
static void assert_config_entry_on_init_bytype(const char *config_key, int expected_value, bool is_bare) { git_config *config; int current_value; git_buf repo_path = GIT_BUF_INIT; cl_set_cleanup(&cleanup_repository, "config_entry"); cl_git_pass(git_buf_puts(&repo_path, "config_entry/test.")); if (!is_bare) cl_git_pass(git_buf_puts(&repo_path, "non.")); cl_git_pass(git_buf_puts(&repo_path, "bare.git")); cl_git_pass(git_repository_init(&_repo, git_buf_cstr(&repo_path), is_bare)); git_buf_free(&repo_path); git_repository_config(&config, _repo); if (expected_value >= 0) { cl_git_pass(git_config_get_bool(¤t_value, config, config_key)); cl_assert_equal_i(expected_value, current_value); } else { int error = git_config_get_bool(¤t_value, config, config_key); cl_assert_equal_i(expected_value, error); } git_config_free(config); }
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_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)); /* 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_status_worktree__first_commit_in_progress(void) { git_repository *repo; git_index *index; status_entry_single result; cl_git_pass(git_repository_init(&repo, "getting_started", 0)); cl_git_mkfile("getting_started/testfile.txt", "content\n"); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_WT_NEW); cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add(index, "testfile.txt", 0)); cl_git_pass(git_index_write(index)); memset(&result, 0, sizeof(result)); cl_git_pass(git_status_foreach(repo, cb_status__single, &result)); cl_assert_equal_i(1, result.count); cl_assert(result.status == GIT_STATUS_INDEX_NEW); git_index_free(index); git_repository_free(repo); }
void test_repo_init__bare_repo_escaping_current_workdir(void) { git_buf path_repository = GIT_BUF_INIT; git_buf path_current_workdir = GIT_BUF_INIT; cl_git_pass(git_path_prettify_dir(&path_current_workdir, ".", NULL)); cl_git_pass(git_buf_joinpath(&path_repository, git_buf_cstr(&path_current_workdir), "a/b/c")); cl_git_pass(git_futils_mkdir_r(git_buf_cstr(&path_repository), NULL, GIT_DIR_MODE)); /* Change the current working directory */ cl_git_pass(chdir(git_buf_cstr(&path_repository))); /* Initialize a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_init(&_repo, "../d/e.git", 1)); cl_git_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/")); git_repository_free(_repo); /* Open a bare repo with a relative path escaping out of the current working directory */ cl_git_pass(git_repository_open(&_repo, "../d/e.git")); cl_git_pass(chdir(git_buf_cstr(&path_current_workdir))); git_buf_free(&path_current_workdir); git_buf_free(&path_repository); cleanup_repository("a"); }
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_remote_callbacks callbacks = GIT_REMOTE_CALLBACKS_INIT; callbacks.transfer_progress = transfer_cb; 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)); git_remote_set_callbacks(origin, &callbacks); cl_git_pass(git_remote_connect(origin, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_download(origin, NULL)); cl_git_pass(git_remote_update_tips(origin, NULL, 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_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_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"); }
void test_network_remote_local__push_to_bare_remote(void) { char *refspec_strings[] = { "master:master", }; git_strarray array = { refspec_strings, 1, }; /* Should be able to push to a bare remote */ git_remote *localremote; /* Get some commits */ connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL)); /* Set up an empty bare repo to push into */ { git_repository *localbarerepo; cl_git_pass(git_repository_init(&localbarerepo, "./localbare.git", 1)); git_repository_free(localbarerepo); } /* Connect to the bare repo */ cl_git_pass(git_remote_create_anonymous(&localremote, repo, "./localbare.git")); cl_git_pass(git_remote_connect(localremote, GIT_DIRECTION_PUSH, NULL, NULL, NULL)); /* Try to push */ cl_git_pass(git_remote_upload(localremote, &push_array, NULL)); /* Clean up */ git_remote_free(localremote); cl_fixture_cleanup("localbare.git"); }
void test_stash_save__initialize(void) { cl_git_pass(git_repository_init(&repo, "stash", 0)); cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ setup_stash(repo, signature); }
/* Test that writing an invalid filename fails */ void test_index_tests__write_invalid_filename(void) { git_repository *repo; git_index *index; git_oid expected; p_mkdir("read_tree", 0700); cl_git_pass(git_repository_init(&repo, "./read_tree", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); cl_git_mkfile("./read_tree/.git/hello", NULL); cl_git_pass(git_index_add_bypath(index, ".git/hello")); /* write-tree */ cl_git_fail(git_index_write_tree(&expected, index)); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("read_tree"); }
git_repository *cl_git_sandbox_init_new(const char *sandbox) { cl_git_pass(git_repository_init(&_cl_repo, sandbox, false)); _cl_sandbox = sandbox; return _cl_repo; }
PyObject * init_repository(PyObject *self, PyObject *args) { git_repository *repo; Repository *py_repo; const char *path; unsigned int bare; int err; if (!PyArg_ParseTuple(args, "sI", &path, &bare)) return NULL; err = git_repository_init(&repo, path, bare); if (err < 0) return Error_set_str(err, path); py_repo = PyObject_GC_New(Repository, &RepositoryType); if (py_repo) { py_repo->repo = repo; py_repo->index = NULL; PyObject_GC_Track(py_repo); return (PyObject*)py_repo; } git_repository_free(repo); return NULL; };
void test_pack_indexer__corrupt_length(void) { git_indexer *idx = NULL; git_transfer_progress stats = { 0 }; git_repository *repo; git_odb *odb; git_oid id, should_id; cl_git_pass(git_repository_init(&repo, "thin.git", true)); cl_git_pass(git_repository_odb(&odb, repo)); /* Store the missing base into your ODB so the indexer can fix the pack */ cl_git_pass(git_odb_write(&id, odb, base_obj, base_obj_len, GIT_OBJ_BLOB)); git_oid_fromstr(&should_id, "e68fe8129b546b101aee9510c5328e7f21ca1d18"); cl_assert_equal_oid(&should_id, &id); cl_git_pass(git_indexer_new(&idx, ".", 0, odb, NULL, NULL)); cl_git_pass(git_indexer_append( idx, corrupt_thin_pack, corrupt_thin_pack_len, &stats)); cl_git_fail(git_indexer_commit(idx, &stats)); cl_assert(giterr_last() != NULL); cl_assert_equal_i(giterr_last()->klass, GITERR_ZLIB); git_indexer_free(idx); git_odb_free(odb); git_repository_free(repo); }
void test_repo_init__at_filesystem_root(void) { git_repository *repo; const char *sandbox = clar_sandbox_path(); git_buf root = GIT_BUF_INIT; int root_len; if (!cl_is_env_set("GITTEST_INVASIVE_FS_STRUCTURE")) cl_skip(); root_len = git_path_root(sandbox); cl_assert(root_len >= 0); git_buf_put(&root, sandbox, root_len+1); git_buf_joinpath(&root, root.ptr, "libgit2_test_dir"); cl_assert(!git_path_exists(root.ptr)); cl_git_pass(git_repository_init(&repo, root.ptr, 0)); cl_assert(git_path_isdir(root.ptr)); cl_git_pass(git_futils_rmdir_r(root.ptr, NULL, GIT_RMDIR_REMOVE_FILES)); git_buf_dispose(&root); git_repository_free(repo); }
void test_index_tests__remove_entry(void) { git_repository *repo; git_index *index; p_mkdir("index_test", 0770); cl_git_pass(git_repository_init(&repo, "index_test", 0)); cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); cl_git_mkfile("index_test/hello", NULL); cl_git_pass(git_index_add_bypath(index, "hello")); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index)); /* reload */ cl_assert(git_index_entrycount(index) == 1); cl_assert(git_index_get_bypath(index, "hello", 0) != NULL); cl_git_pass(git_index_remove(index, "hello", 0)); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_read(index)); /* reload */ cl_assert(git_index_entrycount(index) == 0); cl_assert(git_index_get_bypath(index, "hello", 0) == NULL); git_index_free(index); git_repository_free(repo); cl_fixture_cleanup("index_test"); }
void test_stash_foreach__can_enumerate_a_repository(void) { char *oids_default[] = { "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; char *oids_untracked[] = { "7f89a8b15c878809c5c54d1ff8f8c9674154017b", "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; char *oids_ignored[] = { "c95599a8fef20a7e57582c6727b1a0d02e0a5828", "7f89a8b15c878809c5c54d1ff8f8c9674154017b", "1d91c842a7cdfc25872b3a763e5c31add8816c25", NULL }; cl_git_pass(git_repository_init(&repo, REPO_NAME, 0)); setup_stash(repo, signature); cl_git_pass(git_stash_save( &stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); data.oids = oids_default; cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); cl_assert_equal_i(1, data.invokes); data.oids = oids_untracked; data.invokes = 0; cl_git_pass(git_stash_save( &stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); cl_assert_equal_i(2, data.invokes); data.oids = oids_ignored; data.invokes = 0; cl_git_pass(git_stash_save( &stash_tip_oid, repo, signature, NULL, GIT_STASH_INCLUDE_IGNORED)); cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); cl_assert_equal_i(3, data.invokes); }
git_repository * init_repository2(char * dir, unsigned bare){ git_repository *repo; int ret; ret = git_repository_init(&repo, dir, bare); if (ret < 0){ fprintf(stderr, "Error initializing repository\n"); } return repo; }
git_repository * init_repository(char * dir){ git_repository *repo; int ret; ret = git_repository_init(&repo, dir, 0); if (ret < 0){ fprintf(stderr, "Error initializing repository\n"); } return repo; }
void test_index_tests__add_frombuffer(void) { git_index *index; git_repository *repo; git_index_entry entry; const git_index_entry *returned_entry; git_oid id1; git_blob *blob; const char *content = "hey there\n"; cl_set_cleanup(&cleanup_myrepo, NULL); /* Intialize a new repository */ cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); /* Ensure we're the only guy in the room */ cl_git_pass(git_repository_index(&index, repo)); cl_assert(git_index_entrycount(index) == 0); /* Store the expected hash of the file/blob * This has been generated by executing the following * $ echo "hey there" | git hash-object --stdin */ cl_git_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); /* Add the new file to the index */ memset(&entry, 0x0, sizeof(git_index_entry)); entry.mode = GIT_FILEMODE_BLOB; entry.path = "test.txt"; cl_git_pass(git_index_add_frombuffer(index, &entry, content, strlen(content))); /* Wow... it worked! */ cl_assert(git_index_entrycount(index) == 1); returned_entry = git_index_get_byindex(index, 0); /* And the built-in hashing mechanism worked as expected */ cl_assert_equal_oid(&id1, &returned_entry->id); /* And mode is the one asked */ cl_assert_equal_i(GIT_FILEMODE_BLOB, returned_entry->mode); /* Test access by path instead of index */ cl_assert((returned_entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); cl_assert_equal_oid(&id1, &returned_entry->id); /* Test the blob is in the repository */ cl_git_pass(git_blob_lookup(&blob, repo, &id1)); cl_assert_equal_s( content, git_blob_rawcontent(blob)); git_blob_free(blob); git_index_free(index); git_repository_free(repo); }
void test_stash_save__cannot_stash_against_a_bare_repository(void) { git_repository *local; cl_git_pass(git_repository_init(&local, "sorry-it-is-a-non-bare-only-party", 1)); cl_assert_equal_i(GIT_EBAREREPO, git_stash_save(&stash_tip_oid, local, signature, NULL, GIT_STASH_DEFAULT)); git_repository_free(local); }
NotesModel::NotesModel(QObject *parent) : QAbstractListModel(parent) { m_categories=QStringList(QString("All")); m_filter=QString("All"); QDir notesdir = notesFolder(); if (!(git_repository_open_ext( NULL, notesdir.absolutePath().toUtf8().constData() , GIT_REPOSITORY_OPEN_NO_SEARCH, NULL) == 0)) { git_repository *repo = NULL; // Init Git Repository if not int gerr = git_repository_init(&repo, notesdir.absolutePath().toUtf8().constData(), false); if (gerr < 0) { const git_error *e = giterr_last(); qDebug() << "Libgit error : %s\n" << e->message; emit error(QString().fromLatin1(e->message)); } //Create Initial Commit git_signature *sig; git_index *index; git_oid tree_id, commit_id; git_tree *tree; gerr = git_signature_now(&sig, "sparkleNotes", "*****@*****.**"); gerr = git_repository_index(&index, repo); if (!checkGitErr(gerr)) { gerr = git_index_write_tree(&tree_id, index); if (!checkGitErr(gerr)) { git_index_free(index); gerr = git_tree_lookup(&tree, repo, &tree_id); if (!checkGitErr(gerr)) { gerr = git_commit_create_v( &commit_id, repo, "HEAD", sig, sig, NULL, "Initial commit", tree, 0); } git_tree_free(tree); } } git_signature_free(sig); git_repository_free(repo); } // Add already existing files in case created outside sparkleNotes updateGitStatus(); QtConcurrent::run(this, &NotesModel::pullMergePush); }
TEST(CGitAdminDir, IsAdminDirPath_BareRepo) { CAutoTempDir tmpDir; EXPECT_FALSE(GitAdminDir::IsAdminDirPath(tmpDir.GetTempDir())); CAutoRepository repo = nullptr; ASSERT_TRUE(git_repository_init(repo.GetPointer(), CUnicodeUtils::GetUTF8(tmpDir.GetTempDir()), true) == 0); EXPECT_FALSE(GitAdminDir::IsAdminDirPath(tmpDir.GetTempDir())); }
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_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); }
int git_clone( git_repository **out, const char *url, const char *local_path, const git_clone_options *_options) { int retcode = GIT_ERROR; git_repository *repo = NULL; git_remote *origin; git_clone_options options = GIT_CLONE_OPTIONS_INIT; int remove_directory_on_failure = 0; assert(out && url && local_path); if (_options) memcpy(&options, _options, sizeof(git_clone_options)); GITERR_CHECK_VERSION(&options, GIT_CLONE_OPTIONS_VERSION, "git_clone_options"); /* Only clone to a new directory or an empty directory */ if (git_path_exists(local_path) && !git_path_is_empty_dir(local_path)) { giterr_set(GITERR_INVALID, "'%s' exists and is not an empty directory", local_path); return GIT_ERROR; } /* Only remove the directory on failure if we create it */ remove_directory_on_failure = !git_path_exists(local_path); if ((retcode = git_repository_init(&repo, local_path, options.bare)) < 0) return retcode; if ((retcode = create_and_configure_origin(&origin, repo, url, &options)) < 0) goto cleanup; retcode = git_clone_into(repo, origin, &options.checkout_opts, options.checkout_branch); git_remote_free(origin); if (retcode < 0) goto cleanup; *out = repo; return 0; cleanup: git_repository_free(repo); if (remove_directory_on_failure) git_futils_rmdir_r(local_path, NULL, GIT_RMDIR_REMOVE_FILES); else git_futils_cleanupdir_r(local_path); return retcode; }
void test_repo_init__reinit_overwrites_filemode(void) { int expected = cl_is_chmod_supported(), current_value; /* Init a new repo */ cl_set_cleanup(&cleanup_repository, "overwrite.git"); cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); /* Change the "core.filemode" config value to something unlikely */ cl_repo_set_bool(_repo, "core.filemode", !expected); git_repository_free(_repo); _repo = NULL; /* Reinit the repository */ cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); /* Ensure the "core.filemode" config value has been reset */ current_value = cl_repo_get_bool(_repo, "core.filemode"); cl_assert_equal_i(expected, current_value); }
void test_stash_foreach__enumerating_a_empty_repository_doesnt_fail(void) { char *oids[] = { NULL }; data.oids = oids; cl_git_pass(git_repository_init(&repo, REPO_NAME, 0)); cl_git_pass(git_stash_foreach(repo, callback_cb, &data)); cl_assert_equal_i(0, data.invokes); }