Skip to content

Commit 939d8d5

Browse files
committed
mailmap: Support path fixtures in cl_git_repository_init()
1 parent b88cbf8 commit 939d8d5

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

tests/clar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ void cl_trace_register(cl_trace_cb *cb, void *payload);
7272
const char *cl_fixture(const char *fixture_name);
7373
void cl_fixture_sandbox(const char *fixture_name);
7474
void cl_fixture_cleanup(const char *fixture_name);
75+
const char *cl_fixture_basename(const char *fixture_name);
7576
#endif
7677

7778
/**

tests/clar/fixtures.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,6 @@ fixture_path(const char *base, const char *fixture_name)
2020
return _path;
2121
}
2222

23-
static const char *
24-
fixture_basename(const char *fixture_name)
25-
{
26-
const char *p;
27-
28-
for (p = fixture_name; *p; p++) {
29-
if (p[0] == '/' && p[1] && p[1] != '/')
30-
fixture_name = p+1;
31-
}
32-
33-
return fixture_name;
34-
}
35-
3623
#ifdef CLAR_FIXTURE_PATH
3724
const char *cl_fixture(const char *fixture_name)
3825
{
@@ -44,8 +31,20 @@ void cl_fixture_sandbox(const char *fixture_name)
4431
fs_copy(cl_fixture(fixture_name), _clar_path);
4532
}
4633

34+
const char *cl_fixture_basename(const char *fixture_name)
35+
{
36+
const char *p;
37+
38+
for (p = fixture_name; *p; p++) {
39+
if (p[0] == '/' && p[1] && p[1] != '/')
40+
fixture_name = p+1;
41+
}
42+
43+
return fixture_name;
44+
}
45+
4746
void cl_fixture_cleanup(const char *fixture_name)
4847
{
49-
fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
48+
fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
5049
}
5150
#endif

tests/clar_libgit2.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,17 @@ static git_repository *_cl_repo = NULL;
171171

172172
git_repository *cl_git_sandbox_init(const char *sandbox)
173173
{
174+
/* Get the name of the sandbox folder which will be created
175+
*/
176+
const char *basename = cl_fixture_basename(sandbox);
177+
174178
/* Copy the whole sandbox folder from our fixtures to our test sandbox
175179
* area. After this it can be accessed with `./sandbox`
176180
*/
177181
cl_fixture_sandbox(sandbox);
178182
_cl_sandbox = sandbox;
179183

180-
cl_git_pass(p_chdir(sandbox));
184+
cl_git_pass(p_chdir(basename));
181185

182186
/* If this is not a bare repo, then rename `sandbox/.gitted` to
183187
* `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)
200204
cl_git_pass(p_chdir(".."));
201205

202206
/* Now open the sandbox repository and make it available for tests */
203-
cl_git_pass(git_repository_open(&_cl_repo, sandbox));
207+
cl_git_pass(git_repository_open(&_cl_repo, basename));
204208

205209
/* Adjust configs after copying to new filesystem */
206210
cl_git_pass(git_repository_reinit_filesystem(_cl_repo, 0));
@@ -222,7 +226,9 @@ git_repository *cl_git_sandbox_reopen(void)
222226
git_repository_free(_cl_repo);
223227
_cl_repo = NULL;
224228

225-
cl_git_pass(git_repository_open(&_cl_repo, _cl_sandbox));
229+
cl_git_pass(git_repository_open(
230+
&_cl_repo,
231+
cl_fixture_basename(_cl_sandbox)));
226232
}
227233

228234
return _cl_repo;

0 commit comments

Comments
 (0)