From 9b84447a806911bb93c67533b81f4d121e5ea3f1 Mon Sep 17 00:00:00 2001 From: nulltoken Date: Wed, 25 Jan 2012 12:35:25 +0100 Subject: [PATCH] clay: migrate a test initializing a repository which path escapes the current working directory A non migrated yet test has been removed as well as it's mostly redundant. --- tests-clar/repo/init.c | 45 +++++++++++++++++++++--------------------- tests-clar/repo/open.c | 31 ----------------------------- 2 files changed, 23 insertions(+), 53 deletions(-) diff --git a/tests-clar/repo/init.c b/tests-clar/repo/init.c index ab5edfb58..7e0a94568 100644 --- a/tests-clar/repo/init.c +++ b/tests-clar/repo/init.c @@ -1,5 +1,6 @@ #include "clar_libgit2.h" #include "fileops.h" +#include "repository.h" enum repo_mode { STANDARD_REPOSITORY = 0, @@ -75,32 +76,32 @@ void test_repo_init__bare_repo_noslash(void) ensure_repository_init("testrepo.git", 1, "testrepo.git/", NULL); } -#if 0 -BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory") +void test_repo_init__bare_repo_escaping_current_workdir(void) +{ git_buf path_repository = GIT_BUF_INIT; - char current_workdir[GIT_PATH_MAX]; - const mode_t mode = 0777; - git_repository* repo; + git_buf path_current_workdir = GIT_BUF_INIT; - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); + 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)); - must_pass(git_buf_joinpath(&path_repository, TEMP_REPO_FOLDER, "a/b/c/")); - must_pass(git_futils_mkdir_r(path_repository.ptr, mode)); + /* Change the current working directory */ + cl_git_pass(chdir(git_buf_cstr(&path_repository))); - must_pass(chdir(path_repository.ptr)); + /* 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); - must_pass(git_repository_init(&repo, "../d/e.git", 1)); - must_pass(git__suffixcmp(git_repository_path(_repo), "/a/b/d/e.git/")); - - git_repository_free(repo); - - must_pass(git_repository_open(&repo, "../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST -#endif + cleanup_repository("a"); +} diff --git a/tests-clar/repo/open.c b/tests-clar/repo/open.c index 3bd103c27..b5002843c 100644 --- a/tests-clar/repo/open.c +++ b/tests-clar/repo/open.c @@ -22,34 +22,3 @@ void test_repo_open__standard_empty_repo(void) git_repository_free(repo); } - -/* TODO TODO */ -#if 0 -BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory") - char current_workdir[GIT_PATH_MAX]; - git_buf new_current_workdir = GIT_BUF_INIT; - git_buf path_repository = GIT_BUF_INIT; - - const mode_t mode = 0777; - git_repository* repo; - - /* Setup the repository to open */ - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - must_pass(git_buf_join_n(&path_repository, 3, current_workdir, TEMP_REPO_FOLDER, "a/d/e.git")); - must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository.ptr)); - git_buf_free(&path_repository); - - /* Change the current working directory */ - must_pass(git_buf_joinpath(&new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/")); - must_pass(git_futils_mkdir_r(new_current_workdir.ptr, mode)); - must_pass(chdir(new_current_workdir.ptr)); - git_buf_free(&new_current_workdir); - - must_pass(git_repository_open(&repo, "../../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST -#endif