summaryrefslogtreecommitdiff
path: root/tests/t12-repo.c
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-03-31 15:29:13 +0200
committerCarlos Martín Nieto <cmn@elego.de>2011-03-31 15:29:13 +0200
commitf026f2b9ee5f0aeced5c366c890c4a29eee2a1c7 (patch)
treec26b59992df7ebe645cb9485a4eb70c41e127816 /tests/t12-repo.c
parent11d0e70578baf47fb1cb565e0336e18d417e5da6 (diff)
parenta796d24cf697b0b51aa0ca7ef887e980f0d9fb7a (diff)
downloadlibgit2-f026f2b9ee5f0aeced5c366c890c4a29eee2a1c7.tar.gz
Merge upstream/development
Signed-off-by: Carlos Martín Nieto <cmn@elego.de>
Diffstat (limited to 'tests/t12-repo.c')
-rw-r--r--tests/t12-repo.c101
1 files changed, 93 insertions, 8 deletions
diff --git a/tests/t12-repo.c b/tests/t12-repo.c
index a9a93d147..adf20cfd7 100644
--- a/tests/t12-repo.c
+++ b/tests/t12-repo.c
@@ -113,22 +113,18 @@ static int ensure_repository_init(
return GIT_ERROR;
if (repo->path_workdir != NULL || expected_working_directory != NULL) {
- if (strcmp(repo->path_workdir, expected_working_directory) != 0)
- //return GIT_ERROR;
+ if (git__suffixcmp(repo->path_workdir, expected_working_directory) != 0)
goto cleanup;
}
- if (strcmp(repo->path_odb, path_odb) != 0)
- //return GIT_ERROR;
+ if (git__suffixcmp(repo->path_odb, path_odb) != 0)
goto cleanup;
- if (strcmp(repo->path_repository, expected_path_repository) != 0)
- //return GIT_ERROR;
+ if (git__suffixcmp(repo->path_repository, expected_path_repository) != 0)
goto cleanup;
if (repo->path_index != NULL || expected_path_index != NULL) {
- if (strcmp(repo->path_index, expected_path_index) != 0)
- //return GIT_ERROR;
+ if (git__suffixcmp(repo->path_index, expected_path_index) != 0)
goto cleanup;
}
@@ -162,11 +158,100 @@ BEGIN_TEST(init1, "initialize a bare repo")
must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL));
END_TEST
+BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory")
+ char path_repository[GIT_PATH_MAX];
+ char current_workdir[GIT_PATH_MAX];
+ const int mode = 0755; /* or 0777 ? */
+ git_repository* repo;
+
+ must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir)));
+
+ git__joinpath(path_repository, TEMP_REPO_FOLDER, "a/b/c/");
+ must_pass(gitfo_mkdir_recurs(path_repository, mode));
+
+ must_pass(chdir(path_repository));
+
+ must_pass(git_repository_init(&repo, "../d/e.git", 1));
+ must_pass(git__suffixcmp(repo->path_repository, "/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));
+ rmdir_recurs(TEMP_REPO_FOLDER);
+END_TEST
+
+#define EMPTY_BARE_REPOSITORY_NAME "empty_bare.git"
+#define EMPTY_BARE_REPOSITORY_FOLDER TEST_RESOURCES "/" EMPTY_BARE_REPOSITORY_NAME "/"
+
+BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git")
+ git_repository *repo;
+
+ must_pass(copydir_recurs(EMPTY_BARE_REPOSITORY_FOLDER, TEMP_REPO_FOLDER));
+ must_pass(remove_placeholders(TEMP_REPO_FOLDER, "dummy-marker.txt"));
+
+ must_pass(git_repository_open(&repo, TEMP_REPO_FOLDER));
+
+ git_repository_free(repo);
+ must_pass(rmdir_recurs(TEMP_REPO_FOLDER));
+END_TEST
+
+#define SOURCE_EMPTY_REPOSITORY_NAME "empty_standard_repo/.gitted"
+#define EMPTY_REPOSITORY_NAME "empty_standard_repo/.git"
+#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/" SOURCE_EMPTY_REPOSITORY_NAME "/"
+#define DEST_REPOSITORY_FOLDER TEMP_REPO_FOLDER DOT_GIT "/"
+
+BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git")
+ git_repository *repo;
+
+ must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, DEST_REPOSITORY_FOLDER));
+ must_pass(remove_placeholders(DEST_REPOSITORY_FOLDER, "dummy-marker.txt"));
+
+ must_pass(git_repository_open(&repo, DEST_REPOSITORY_FOLDER));
+
+ git_repository_free(repo);
+ must_pass(rmdir_recurs(TEMP_REPO_FOLDER));
+END_TEST
+
+
+BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory")
+ char new_current_workdir[GIT_PATH_MAX];
+ char current_workdir[GIT_PATH_MAX];
+ char path_repository[GIT_PATH_MAX];
+
+ const int mode = 0755; /* or 0777 ? */
+ git_repository* repo;
+
+ /* Setup the repository to open */
+ must_pass(gitfo_getcwd(current_workdir, sizeof(current_workdir)));
+ strcpy(path_repository, current_workdir);
+ git__joinpath_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git");
+ must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository));
+
+ /* Change the current working directory */
+ git__joinpath(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/");
+ must_pass(gitfo_mkdir_recurs(new_current_workdir, mode));
+ must_pass(chdir(new_current_workdir));
+
+ must_pass(git_repository_open(&repo, "../../d/e.git"));
+
+ git_repository_free(repo);
+
+ must_pass(chdir(current_workdir));
+ rmdir_recurs(TEMP_REPO_FOLDER);
+END_TEST
BEGIN_SUITE(repository)
ADD_TEST(odb0);
ADD_TEST(odb1);
ADD_TEST(init0);
ADD_TEST(init1);
+ ADD_TEST(init2);
+ ADD_TEST(open0);
+ ADD_TEST(open1);
+ ADD_TEST(open2);
END_SUITE