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