]>
git.proxmox.com Git - libgit2.git/blob - tests/win32/longpath.c
1 #include "clar_libgit2.h"
3 #include "git2/clone.h"
7 #include "repository.h"
9 static git_buf path
= GIT_BUF_INIT
;
11 #define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
13 void test_win32_longpath__initialize(void)
16 const char *base
= clar_sandbox_path();
17 size_t base_len
= strlen(base
);
18 size_t remain
= MAX_PATH
- base_len
;
22 git_buf_puts(&path
, base
);
23 git_buf_putc(&path
, '/');
25 cl_assert(remain
< (MAX_PATH
- 5));
27 for (i
= 0; i
< (remain
- 5); i
++)
28 git_buf_putc(&path
, 'a');
32 void test_win32_longpath__cleanup(void)
34 git_buf_dispose(&path
);
35 cl_git_sandbox_cleanup();
38 void test_win32_longpath__errmsg_on_checkout(void)
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);
48 void test_win32_longpath__workdir_path_validated(void)
51 git_repository
*repo
= cl_git_sandbox_init("testrepo");
52 git_buf out
= GIT_BUF_INIT
;
54 cl_git_pass(git_repository_workdir_path(&out
, repo
, "a.txt"));
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);
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
);
68 static void assert_longpath_status_and_add(git_repository
*repo
, const char *wddata
, const char *repodata
) {
71 git_buf out
= GIT_BUF_INIT
;
72 const git_index_entry
*entry
;
73 unsigned int status_flags
;
75 cl_git_pass(git_repository_workdir_path(&out
, repo
, LONG_FILENAME
));
77 cl_git_rewritefile(out
.ptr
, wddata
);
79 cl_git_pass(git_status_file(&status_flags
, repo
, LONG_FILENAME
));
80 cl_assert_equal_i(GIT_STATUS_WT_NEW
, status_flags
);
82 cl_git_pass(git_repository_index(&index
, repo
));
83 cl_git_pass(git_index_add_bypath(index
, LONG_FILENAME
));
85 cl_git_pass(git_status_file(&status_flags
, repo
, LONG_FILENAME
));
86 cl_assert_equal_i(GIT_STATUS_INDEX_NEW
, status_flags
);
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
));
93 git_index_free(index
);
94 git_buf_dispose(&out
);
98 void test_win32_longpath__status_and_add(void)
101 git_repository
*repo
= cl_git_sandbox_init("testrepo");
103 cl_repo_set_bool(repo
, "core.longpaths", true);
106 * Doing no content filtering, we expect the data we add
107 * to be the data in the repository.
109 assert_longpath_status_and_add(repo
,
110 "This is a long path.\r\n",
111 "This is a long path.\r\n");
115 void test_win32_longpath__status_and_add_with_filter(void)
118 git_repository
*repo
= cl_git_sandbox_init("testrepo");
120 cl_repo_set_bool(repo
, "core.longpaths", true);
121 cl_repo_set_bool(repo
, "core.autocrlf", true);
124 * With `core.autocrlf`, we expect the data we add to have
125 * newline conversion performed.
127 assert_longpath_status_and_add(repo
,
128 "This is a long path.\r\n",
129 "This is a long path.\n");