]> git.proxmox.com Git - libgit2.git/blame - tests/refs/basic.c
New upstream version 1.3.0+dfsg.1
[libgit2.git] / tests / refs / basic.c
CommitLineData
22a2d3d5
UG
1#include "clar_libgit2.h"
2
3#include "futils.h"
4#include "refs.h"
5#include "ref_helpers.h"
6
7static git_repository *g_repo;
8
9static const char *loose_tag_ref_name = "refs/tags/e90810b";
10
11void test_refs_basic__initialize(void)
12{
13 g_repo = cl_git_sandbox_init("testrepo");
14 cl_git_pass(git_repository_set_ident(g_repo, "me", "foo@example.com"));
15}
16
17void test_refs_basic__cleanup(void)
18{
19 cl_git_sandbox_cleanup();
20}
21
22void test_refs_basic__reference_realloc(void)
23{
24 git_reference *ref;
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";
27
28 /* Retrieval of the reference to rename */
29 cl_git_pass(git_reference_lookup(&ref, g_repo, loose_tag_ref_name));
30
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);
35
36 /* Reload, so we restore the value */
37 cl_git_pass(git_reference_lookup(&ref, g_repo, loose_tag_ref_name));
38
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);
44}
c25aa7cd
PP
45
46void test_refs_basic__longpaths(void)
47{
48#ifdef GIT_WIN32
49 const char *base;
50 size_t base_len, extra_len;
51 ssize_t remain_len, i;
52 git_buf refname = GIT_BUF_INIT;
53 git_reference *one = NULL, *two = NULL;
54 git_oid id;
55
56 cl_git_pass(git_oid_fromstr(&id, "099fabac3a9ea935598528c27f866e34089c2eff"));
57
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");
61
62 remain_len = (ssize_t)MAX_PATH - (base_len + extra_len);
63 cl_assert(remain_len > 0);
64
65 cl_git_pass(git_buf_puts(&refname, "refs/heads/"));
66
67 for (i = 0; i < remain_len; i++) {
68 cl_git_pass(git_buf_putc(&refname, 'a'));
69 }
70
71 /*
72 * The full path to the reflog lockfile is 260 characters,
73 * this is permitted.
74 */
75 cl_git_pass(git_reference_create(&one, g_repo, refname.ptr, &id, 0, NULL));
76
77 /* Adding one more character gives us a path that is too long. */
78 cl_git_pass(git_buf_putc(&refname, 'z'));
79 cl_git_fail(git_reference_create(&two, g_repo, refname.ptr, &id, 0, NULL));
80
81 git_reference_free(one);
82 git_reference_free(two);
83 git_buf_dispose(&refname);
84#endif
85}