]>
git.proxmox.com Git - libgit2.git/blob - tests/win32/longpath.c
1 #include "clar_libgit2.h"
3 #include "git2/clone.h"
6 #include "repository.h"
8 static git_str path
= GIT_STR_INIT
;
10 #define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"
12 void test_win32_longpath__initialize(void)
15 const char *base
= clar_sandbox_path();
16 size_t base_len
= strlen(base
);
17 size_t remain
= MAX_PATH
- base_len
;
21 git_str_puts(&path
, base
);
22 git_str_putc(&path
, '/');
24 cl_assert(remain
< (MAX_PATH
- 5));
26 for (i
= 0; i
< (remain
- 5); i
++)
27 git_str_putc(&path
, 'a');
31 void test_win32_longpath__cleanup(void)
33 git_str_dispose(&path
);
34 cl_git_sandbox_cleanup();
37 void test_win32_longpath__errmsg_on_checkout(void)
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);
47 void test_win32_longpath__workdir_path_validated(void)
50 git_repository
*repo
= cl_git_sandbox_init("testrepo");
51 git_str out
= GIT_STR_INIT
;
53 cl_git_pass(git_repository_workdir_path(&out
, repo
, "a.txt"));
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);
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
);
67 static void assert_longpath_status_and_add(git_repository
*repo
, const char *wddata
, const char *repodata
) {
70 git_str out
= GIT_STR_INIT
;
71 const git_index_entry
*entry
;
72 unsigned int status_flags
;
74 cl_git_pass(git_repository_workdir_path(&out
, repo
, LONG_FILENAME
));
76 cl_git_rewritefile(out
.ptr
, wddata
);
78 cl_git_pass(git_status_file(&status_flags
, repo
, LONG_FILENAME
));
79 cl_assert_equal_i(GIT_STATUS_WT_NEW
, status_flags
);
81 cl_git_pass(git_repository_index(&index
, repo
));
82 cl_git_pass(git_index_add_bypath(index
, LONG_FILENAME
));
84 cl_git_pass(git_status_file(&status_flags
, repo
, LONG_FILENAME
));
85 cl_assert_equal_i(GIT_STATUS_INDEX_NEW
, status_flags
);
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
));
92 git_index_free(index
);
93 git_str_dispose(&out
);
97 void test_win32_longpath__status_and_add(void)
100 git_repository
*repo
= cl_git_sandbox_init("testrepo");
102 cl_repo_set_bool(repo
, "core.longpaths", true);
105 * Doing no content filtering, we expect the data we add
106 * to be the data in the repository.
108 assert_longpath_status_and_add(repo
,
109 "This is a long path.\r\n",
110 "This is a long path.\r\n");
114 void test_win32_longpath__status_and_add_with_filter(void)
117 git_repository
*repo
= cl_git_sandbox_init("testrepo");
119 cl_repo_set_bool(repo
, "core.longpaths", true);
120 cl_repo_set_bool(repo
, "core.autocrlf", true);
123 * With `core.autocrlf`, we expect the data we add to have
124 * newline conversion performed.
126 assert_longpath_status_and_add(repo
,
127 "This is a long path.\r\n",
128 "This is a long path.\n");