]>
git.proxmox.com Git - libgit2.git/blob - tests/refs/basic.c
1 #include "clar_libgit2.h"
5 #include "ref_helpers.h"
7 static git_repository
*g_repo
;
9 static const char *loose_tag_ref_name
= "refs/tags/e90810b";
11 void test_refs_basic__initialize(void)
13 g_repo
= cl_git_sandbox_init("testrepo");
14 cl_git_pass(git_repository_set_ident(g_repo
, "me", "foo@example.com"));
17 void test_refs_basic__cleanup(void)
19 cl_git_sandbox_cleanup();
22 void test_refs_basic__reference_realloc(void)
25 git_reference
*new_ref
;
26 const char *new_name
= "refs/tags/awful/name-which-is/clearly/really-that-much/longer-than/the-old-one";
28 /* Retrieval of the reference to rename */
29 cl_git_pass(git_reference_lookup(&ref
, g_repo
, loose_tag_ref_name
));
31 new_ref
= git_reference__realloc(&ref
, new_name
);
32 cl_assert(new_ref
!= NULL
);
33 git_reference_free(new_ref
);
34 git_reference_free(ref
);
36 /* Reload, so we restore the value */
37 cl_git_pass(git_reference_lookup(&ref
, g_repo
, loose_tag_ref_name
));
39 cl_git_pass(git_reference_rename(&new_ref
, ref
, new_name
, 1, "log message"));
40 cl_assert(ref
!= NULL
);
41 cl_assert(new_ref
!= NULL
);
42 git_reference_free(new_ref
);
43 git_reference_free(ref
);
46 void test_refs_basic__longpaths(void)
50 size_t base_len
, extra_len
;
51 ssize_t remain_len
, i
;
52 git_str refname
= GIT_STR_INIT
;
53 git_reference
*one
= NULL
, *two
= NULL
;
56 cl_git_pass(git_oid_fromstr(&id
, "099fabac3a9ea935598528c27f866e34089c2eff"));
58 base
= git_repository_path(g_repo
);
59 base_len
= git_utf8_char_length(base
, strlen(base
));
60 extra_len
= CONST_STRLEN("logs/refs/heads/") + CONST_STRLEN(".lock");
62 remain_len
= (ssize_t
)MAX_PATH
- (base_len
+ extra_len
);
63 cl_assert(remain_len
> 0);
65 cl_git_pass(git_str_puts(&refname
, "refs/heads/"));
67 for (i
= 0; i
< remain_len
; i
++) {
68 cl_git_pass(git_str_putc(&refname
, 'a'));
72 * The full path to the reflog lockfile is 260 characters,
75 cl_git_pass(git_reference_create(&one
, g_repo
, refname
.ptr
, &id
, 0, NULL
));
77 /* Adding one more character gives us a path that is too long. */
78 cl_git_pass(git_str_putc(&refname
, 'z'));
79 cl_git_fail(git_reference_create(&two
, g_repo
, refname
.ptr
, &id
, 0, NULL
));
81 git_reference_free(one
);
82 git_reference_free(two
);
83 git_str_dispose(&refname
);