Skip to content

Commit 807d57e

Browse files
committed
tests: implement worktree helpers
1 parent 8acc3b1 commit 807d57e

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/worktree/worktree_helpers.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#include "clar_libgit2.h"
2+
#include "worktree_helpers.h"
3+
4+
void cleanup_fixture_worktree(worktree_fixture *fixture)
5+
{
6+
if (!fixture)
7+
return;
8+
9+
if (fixture->repo) {
10+
git_repository_free(fixture->repo);
11+
fixture->repo = NULL;
12+
}
13+
if (fixture->worktree) {
14+
git_repository_free(fixture->worktree);
15+
fixture->worktree = NULL;
16+
}
17+
18+
if (fixture->reponame)
19+
cl_fixture_cleanup(fixture->reponame);
20+
if (fixture->worktreename)
21+
cl_fixture_cleanup(fixture->worktreename);
22+
}
23+
24+
void setup_fixture_worktree(worktree_fixture *fixture)
25+
{
26+
if (fixture->reponame)
27+
fixture->repo = cl_git_sandbox_init(fixture->reponame);
28+
if (fixture->worktreename)
29+
fixture->worktree = cl_git_sandbox_init(fixture->worktreename);
30+
}

tests/worktree/worktree_helpers.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
typedef struct {
2+
const char *reponame;
3+
const char *worktreename;
4+
git_repository *repo;
5+
git_repository *worktree;
6+
} worktree_fixture;
7+
8+
#define WORKTREE_FIXTURE_INIT(repo, worktree) { (repo), (worktree), NULL, NULL }
9+
10+
void cleanup_fixture_worktree(worktree_fixture *fixture);
11+
void setup_fixture_worktree(worktree_fixture *fixture);

0 commit comments

Comments
 (0)