]> git.proxmox.com Git - libgit2.git/blame - tests-clar/refs/branches/ishead.c
No such thing as an orphan branch
[libgit2.git] / tests-clar / refs / branches / ishead.c
CommitLineData
0c78f685 1#include "clar_libgit2.h"
2#include "refs.h"
cd1ef822 3#include "repo/repo_helpers.h"
0c78f685 4
5static git_repository *repo;
6static git_reference *branch;
7
8void test_refs_branches_ishead__initialize(void)
9{
10 cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
11}
12
13void test_refs_branches_ishead__cleanup(void)
14{
15 git_reference_free(branch);
9094d30b
SC
16 branch = NULL;
17
0c78f685 18 git_repository_free(repo);
9094d30b 19 repo = NULL;
0c78f685 20}
21
22void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void)
23{
24 cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
25
26 cl_assert_equal_i(true, git_branch_is_head(branch));
27}
28
605da51a 29void test_refs_branches_ishead__can_properly_handle_unborn_HEAD(void)
8b05bea8 30{
31 git_repository_free(repo);
32
33 repo = cl_git_sandbox_init("testrepo.git");
34
605da51a 35 make_head_unborn(repo, NON_EXISTING_HEAD);
8b05bea8 36
37 cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
38
39 cl_assert_equal_i(false, git_branch_is_head(branch));
40
41 cl_git_sandbox_cleanup();
42 repo = NULL;
43}
44
b1a3a70e 45void test_refs_branches_ishead__can_properly_handle_missing_HEAD(void)
46{
47 git_repository_free(repo);
48
49 repo = cl_git_sandbox_init("testrepo.git");
50
51 delete_head(repo);
52
53 cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master"));
54
55 cl_assert_equal_i(false, git_branch_is_head(branch));
56
57 cl_git_sandbox_cleanup();
58 repo = NULL;
59}
60
0c78f685 61void test_refs_branches_ishead__can_tell_if_a_branch_is_not_pointed_at_by_HEAD(void)
62{
63 cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/br2"));
64
65 cl_assert_equal_i(false, git_branch_is_head(branch));
66}
67
68void test_refs_branches_ishead__wont_be_fooled_by_a_non_branch(void)
69{
70 cl_git_pass(git_reference_lookup(&branch, repo, "refs/tags/e90810b"));
71
72 cl_assert_equal_i(false, git_branch_is_head(branch));
73}
74
75/*
76 * $ git init .
77 * Initialized empty Git repository in d:/temp/tempee/.git/
78 *
79 * $ touch a && git add a
80 * $ git commit -m" boom"
81 * [master (root-commit) b47b758] boom
82 * 0 files changed
83 * create mode 100644 a
84 *
85 * $ echo "ref: refs/heads/master" > .git/refs/heads/linked
86 * $ echo "ref: refs/heads/linked" > .git/refs/heads/super
87 * $ echo "ref: refs/heads/super" > .git/HEAD
88 *
89 * $ git branch
90 * linked -> master
91 * * master
92 * super -> master
93 */
94void test_refs_branches_ishead__only_direct_references_are_considered(void)
95{
96 git_reference *linked, *super, *head;
97
98 git_repository_free(repo);
99 repo = cl_git_sandbox_init("testrepo.git");
100
2508cc66
BS
101 cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0));
102 cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0));
103 cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1));
0c78f685 104
105 cl_assert_equal_i(false, git_branch_is_head(linked));
106 cl_assert_equal_i(false, git_branch_is_head(super));
107
108 cl_git_pass(git_repository_head(&branch, repo));
109 cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
110
111 git_reference_free(linked);
112 git_reference_free(super);
113 git_reference_free(head);
114 cl_git_sandbox_cleanup();
115 repo = NULL;
116}