Commit 939d8d579dcf722ca56578203df7c3134ba23ac1

Nika Layzell 2018-03-17T18:14:03

mailmap: Support path fixtures in cl_git_repository_init()

diff --git a/tests/clar.h b/tests/clar.h
index 5c674d7..dfb88d7 100644
--- a/tests/clar.h
+++ b/tests/clar.h
@@ -72,6 +72,7 @@ void cl_trace_register(cl_trace_cb *cb, void *payload);
 const char *cl_fixture(const char *fixture_name);
 void cl_fixture_sandbox(const char *fixture_name);
 void cl_fixture_cleanup(const char *fixture_name);
+const char *cl_fixture_basename(const char *fixture_name);
 #endif
 
 /**
diff --git a/tests/clar/fixtures.h b/tests/clar/fixtures.h
index f7b8d96..77033d3 100644
--- a/tests/clar/fixtures.h
+++ b/tests/clar/fixtures.h
@@ -20,19 +20,6 @@ fixture_path(const char *base, const char *fixture_name)
 	return _path;
 }
 
-static const char *
-fixture_basename(const char *fixture_name)
-{
-	const char *p;
-
-	for (p = fixture_name; *p; p++) {
-		if (p[0] == '/' && p[1] && p[1] != '/')
-			fixture_name = p+1;
-	}
-
-	return fixture_name;
-}
-
 #ifdef CLAR_FIXTURE_PATH
 const char *cl_fixture(const char *fixture_name)
 {
@@ -44,8 +31,20 @@ void cl_fixture_sandbox(const char *fixture_name)
 	fs_copy(cl_fixture(fixture_name), _clar_path);
 }
 
+const char *cl_fixture_basename(const char *fixture_name)
+{
+	const char *p;
+
+	for (p = fixture_name; *p; p++) {
+		if (p[0] == '/' && p[1] && p[1] != '/')
+			fixture_name = p+1;
+	}
+
+	return fixture_name;
+}
+
 void cl_fixture_cleanup(const char *fixture_name)
 {
-	fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
+	fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
 }
 #endif
diff --git a/tests/clar_libgit2.c b/tests/clar_libgit2.c
index 92404b5..b50633a 100644
--- a/tests/clar_libgit2.c
+++ b/tests/clar_libgit2.c
@@ -171,13 +171,17 @@ static git_repository *_cl_repo = NULL;
 
 git_repository *cl_git_sandbox_init(const char *sandbox)
 {
+	/* Get the name of the sandbox folder which will be created
+	 */
+	const char *basename = cl_fixture_basename(sandbox);
+
 	/* Copy the whole sandbox folder from our fixtures to our test sandbox
 	 * area.  After this it can be accessed with `./sandbox`
 	 */
 	cl_fixture_sandbox(sandbox);
 	_cl_sandbox = sandbox;
 
-	cl_git_pass(p_chdir(sandbox));
+	cl_git_pass(p_chdir(basename));
 
 	/* If this is not a bare repo, then rename `sandbox/.gitted` to
 	 * `sandbox/.git` which must be done since we cannot store a folder
@@ -200,7 +204,7 @@ git_repository *cl_git_sandbox_init(const char *sandbox)
 	cl_git_pass(p_chdir(".."));
 
 	/* Now open the sandbox repository and make it available for tests */
-	cl_git_pass(git_repository_open(&_cl_repo, sandbox));
+	cl_git_pass(git_repository_open(&_cl_repo, basename));
 
 	/* Adjust configs after copying to new filesystem */
 	cl_git_pass(git_repository_reinit_filesystem(_cl_repo, 0));
@@ -222,7 +226,9 @@ git_repository *cl_git_sandbox_reopen(void)
 		git_repository_free(_cl_repo);
 		_cl_repo = NULL;
 
-		cl_git_pass(git_repository_open(&_cl_repo, _cl_sandbox));
+		cl_git_pass(git_repository_open(
+			&_cl_repo,
+			cl_fixture_basename(_cl_sandbox)));
 	}
 
 	return _cl_repo;