]>
Commit | Line | Data |
---|---|---|
22a2d3d5 UG |
1 | #include "clar_libgit2.h" |
2 | #include "refs.h" | |
3 | #include "worktree/worktree_helpers.h" | |
4 | ||
5 | static git_repository *repo; | |
6 | ||
7 | static void assert_checked_out(git_repository *repo, const char *branch, int checked_out) | |
8 | { | |
9 | git_reference *ref; | |
10 | ||
11 | cl_git_pass(git_reference_lookup(&ref, repo, branch)); | |
12 | cl_assert(git_branch_is_checked_out(ref) == checked_out); | |
13 | ||
14 | git_reference_free(ref); | |
15 | } | |
16 | ||
17 | void test_refs_branches_checkedout__simple_repo(void) | |
18 | { | |
19 | repo = cl_git_sandbox_init("testrepo"); | |
20 | assert_checked_out(repo, "refs/heads/master", 1); | |
21 | assert_checked_out(repo, "refs/heads/executable", 0); | |
22 | cl_git_sandbox_cleanup(); | |
23 | } | |
24 | ||
25 | void test_refs_branches_checkedout__worktree(void) | |
26 | { | |
27 | static worktree_fixture fixture = | |
28 | WORKTREE_FIXTURE_INIT("testrepo", "testrepo-worktree"); | |
29 | ||
30 | setup_fixture_worktree(&fixture); | |
31 | ||
32 | assert_checked_out(fixture.repo, "refs/heads/master", 1); | |
33 | assert_checked_out(fixture.repo, "refs/heads/testrepo-worktree", 1); | |
34 | ||
35 | assert_checked_out(fixture.worktree, "refs/heads/master", 1); | |
36 | assert_checked_out(fixture.worktree, "refs/heads/testrepo-worktree", 1); | |
37 | ||
38 | cleanup_fixture_worktree(&fixture); | |
39 | } | |
40 | ||
41 | void test_refs_branches_checkedout__head_is_not_checked_out(void) | |
42 | { | |
43 | repo = cl_git_sandbox_init("testrepo"); | |
44 | assert_checked_out(repo, "HEAD", 0); | |
45 | cl_git_sandbox_cleanup(); | |
46 | } | |
47 | ||
48 | void test_refs_branches_checkedout__master_in_bare_repo_is_not_checked_out(void) | |
49 | { | |
50 | repo = cl_git_sandbox_init("testrepo.git"); | |
51 | assert_checked_out(repo, "refs/heads/master", 0); | |
52 | cl_git_sandbox_cleanup(); | |
53 | } |