示例#1
0
void test_status_worktree__status_file_with_clean_index_and_empty_workdir(void)
{
	git_repository *repo;
	unsigned int status = 0;
	git_index *index;

	cl_git_pass(p_mkdir("wd", 0777));

	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
	cl_git_pass(git_repository_set_workdir(repo, "wd", false));

	cl_git_pass(git_index_open(&index, "my-index"));
	fill_index_wth_head_entries(repo, index);

	git_repository_set_index(repo, index);

	cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));

	cl_assert_equal_i(GIT_STATUS_WT_DELETED, status);

	git_repository_free(repo);
	git_index_free(index);
	cl_git_pass(p_rmdir("wd"));
	cl_git_pass(p_unlink("my-index"));
}
示例#2
0
文件: setters.c 项目: 1336/libgit2
void test_repo_setters__setting_a_workdir_turns_a_bare_repository_into_a_standard_one(void)
{
	cl_assert(git_repository_is_bare(repo) == 1);

	cl_assert(git_repository_workdir(repo) == NULL);
	cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));

	cl_assert(git_repository_workdir(repo) != NULL);
	cl_assert(git_repository_is_bare(repo) == 0);
}
示例#3
0
文件: new.c 项目: 1336/libgit2
void test_repo_new__is_bare_until_workdir_set(void)
{
	git_repository *repo;

	cl_git_pass(git_repository_new(&repo));
	cl_assert_equal_b(true, git_repository_is_bare(repo));

	cl_git_pass(git_repository_set_workdir(repo, clar_sandbox_path(), 0));
	cl_assert_equal_b(false, git_repository_is_bare(repo));

	git_repository_free(repo);
}
示例#4
0
void test_checkout_index__honor_coresymlinks_default(void)
{
	git_repository *repo;
	git_remote *origin;
	git_object *target;
	char cwd[GIT_PATH_MAX];

	const char *url = git_repository_path(g_repo);

	cl_assert(getcwd(cwd, sizeof(cwd)) != NULL);
	cl_assert_equal_i(0, p_mkdir("readonly", 0555)); // Read-only directory
	cl_assert_equal_i(0, chdir("readonly"));
	cl_git_pass(git_repository_init(&repo, "../symlink.git", true));
	cl_assert_equal_i(0, chdir(cwd));
	cl_assert_equal_i(0, p_mkdir("symlink", 0777));
	cl_git_pass(git_repository_set_workdir(repo, "symlink", 1));

	cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url));
	cl_git_pass(git_remote_fetch(origin, NULL, NULL, NULL));
	git_remote_free(origin);

	cl_git_pass(git_revparse_single(&target, repo, "remotes/origin/master"));
	cl_git_pass(git_reset(repo, target, GIT_RESET_HARD, NULL));
	git_object_free(target);
	git_repository_free(repo);

#ifdef GIT_WIN32
	check_file_contents("./symlink/link_to_new.txt", "new.txt");
#else
	{
		char link_data[1024];
		size_t link_size = 1024;

		link_size = p_readlink("./symlink/link_to_new.txt", link_data, link_size);
		link_data[link_size] = '\0';
		cl_assert_equal_i(link_size, strlen("new.txt"));
		cl_assert_equal_s(link_data, "new.txt");
		check_file_contents("./symlink/link_to_new.txt", "my new file\n");
	}
#endif

	cl_fixture_cleanup("symlink");
}
示例#5
0
int
Repository_workdir__set__(Repository *self, PyObject *py_workdir)
{
    int err;
    const char *workdir;
    PyObject *tworkdir;

    workdir = py_str_borrow_c_str(&tworkdir, py_workdir, NULL);
    if (workdir == NULL)
        return -1;

    err = git_repository_set_workdir(self->repo, workdir, 0 /* update_gitlink */);
    Py_DECREF(tworkdir);
    if (err < 0) {
        Error_set_str(err, workdir);
        return -1;
    }

    return 0;
}
示例#6
0
文件: setters.c 项目: 1336/libgit2
void test_repo_setters__setting_a_workdir_creates_a_gitlink(void)
{
	git_config *cfg;
	git_buf buf = GIT_BUF_INIT;
	git_buf content = GIT_BUF_INIT;

	cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", true));

	cl_assert(git_path_isfile("./new_workdir/.git"));

	cl_git_pass(git_futils_readbuffer(&content, "./new_workdir/.git"));
	cl_assert(git__prefixcmp(git_buf_cstr(&content), "gitdir: ") == 0);
	cl_assert(git__suffixcmp(git_buf_cstr(&content), "testrepo.git/") == 0);
	git_buf_free(&content);

	cl_git_pass(git_repository_config(&cfg, repo));
	cl_git_pass(git_config_get_string_buf(&buf, cfg, "core.worktree"));
	cl_assert(git__suffixcmp(git_buf_cstr(&buf), "new_workdir/") == 0);

	git_buf_free(&buf);
	git_config_free(cfg);
}
示例#7
0
void test_status_worktree__status_file_without_index_or_workdir(void)
{
	git_repository *repo;
	unsigned int status = 0;
	git_index *index;

	cl_git_pass(p_mkdir("wd", 0777));

	cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
	cl_git_pass(git_repository_set_workdir(repo, "wd", false));

	cl_git_pass(git_index_open(&index, "empty-index"));
	cl_assert_equal_i(0, git_index_entrycount(index));
	git_repository_set_index(repo, index);

	cl_git_pass(git_status_file(&status, repo, "branch_file.txt"));

	cl_assert_equal_i(GIT_STATUS_INDEX_DELETED, status);

	git_repository_free(repo);
	git_index_free(index);
	cl_git_pass(p_rmdir("wd"));
}
示例#8
0
void Repository::SetWorkingDir(const std::string& sWorkingDir, bool updateGitLink)
{
    ErrorUtility::ThrowOnError("git_repository_set_workdir", git_repository_set_workdir(m_pRepository, sWorkingDir.c_str(), updateGitLink));
}
示例#9
0
文件: setters.c 项目: 1336/libgit2
void test_repo_setters__setting_a_workdir_prettifies_its_path(void)
{
	cl_git_pass(git_repository_set_workdir(repo, "./new_workdir", false));

	cl_assert(git__suffixcmp(git_repository_workdir(repo), "new_workdir/") == 0);
}