]> git.proxmox.com Git - libgit2.git/blob - tests/win32/longpath.c
New upstream version 1.4.3+dfsg.1
[libgit2.git] / tests / win32 / longpath.c
1 #include "clar_libgit2.h"
2
3 #include "git2/clone.h"
4 #include "clone.h"
5 #include "futils.h"
6 #include "repository.h"
7
8 static git_str path = GIT_STR_INIT;
9
10 #define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
11
12 void test_win32_longpath__initialize(void)
13 {
14 #ifdef GIT_WIN32
15 const char *base = clar_sandbox_path();
16 size_t base_len = strlen(base);
17 size_t remain = MAX_PATH - base_len;
18 size_t i;
19
20 git_str_clear(&path);
21 git_str_puts(&path, base);
22 git_str_putc(&path, '/');
23
24 cl_assert(remain < (MAX_PATH - 5));
25
26 for (i = 0; i < (remain - 5); i++)
27 git_str_putc(&path, 'a');
28 #endif
29 }
30
31 void test_win32_longpath__cleanup(void)
32 {
33 git_str_dispose(&path);
34 cl_git_sandbox_cleanup();
35 }
36
37 void test_win32_longpath__errmsg_on_checkout(void)
38 {
39 #ifdef GIT_WIN32
40 git_repository *repo;
41
42 cl_git_fail(git_clone(&repo, cl_fixture("testrepo.git"), path.ptr, NULL));
43 cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
44 #endif
45 }
46
47 void test_win32_longpath__workdir_path_validated(void)
48 {
49 #ifdef GIT_WIN32
50 git_repository *repo = cl_git_sandbox_init("testrepo");
51 git_str out = GIT_STR_INIT;
52
53 cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));
54
55 /* even if the repo path is a drive letter, this is too long */
56 cl_git_fail(git_repository_workdir_path(&out, repo, LONG_FILENAME));
57 cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
58
59 cl_repo_set_bool(repo, "core.longpaths", true);
60 cl_git_pass(git_repository_workdir_path(&out, repo, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"));
61 cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
62 git_str_dispose(&out);
63 #endif
64 }
65
66 #ifdef GIT_WIN32
67 static void assert_longpath_status_and_add(git_repository *repo, const char *wddata, const char *repodata) {
68 git_index *index;
69 git_blob *blob;
70 git_str out = GIT_STR_INIT;
71 const git_index_entry *entry;
72 unsigned int status_flags;
73
74 cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
75
76 cl_git_rewritefile(out.ptr, wddata);
77
78 cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
79 cl_assert_equal_i(GIT_STATUS_WT_NEW, status_flags);
80
81 cl_git_pass(git_repository_index(&index, repo));
82 cl_git_pass(git_index_add_bypath(index, LONG_FILENAME));
83
84 cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
85 cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status_flags);
86
87 cl_assert((entry = git_index_get_bypath(index, LONG_FILENAME, 0)) != NULL);
88 cl_git_pass(git_blob_lookup(&blob, repo, &entry->id));
89 cl_assert_equal_s(repodata, git_blob_rawcontent(blob));
90
91 git_blob_free(blob);
92 git_index_free(index);
93 git_str_dispose(&out);
94 }
95 #endif
96
97 void test_win32_longpath__status_and_add(void)
98 {
99 #ifdef GIT_WIN32
100 git_repository *repo = cl_git_sandbox_init("testrepo");
101
102 cl_repo_set_bool(repo, "core.longpaths", true);
103
104 /*
105 * Doing no content filtering, we expect the data we add
106 * to be the data in the repository.
107 */
108 assert_longpath_status_and_add(repo,
109 "This is a long path.\r\n",
110 "This is a long path.\r\n");
111 #endif
112 }
113
114 void test_win32_longpath__status_and_add_with_filter(void)
115 {
116 #ifdef GIT_WIN32
117 git_repository *repo = cl_git_sandbox_init("testrepo");
118
119 cl_repo_set_bool(repo, "core.longpaths", true);
120 cl_repo_set_bool(repo, "core.autocrlf", true);
121
122 /*
123 * With `core.autocrlf`, we expect the data we add to have
124 * newline conversion performed.
125 */
126 assert_longpath_status_and_add(repo,
127 "This is a long path.\r\n",
128 "This is a long path.\n");
129 #endif
130 }