Hash :
50e01216
Author :
Date :
2021-03-20T16:39:29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
#include "clar_libgit2.h"
#include "git2/clone.h"
#include "clone.h"
#include "buffer.h"
#include "futils.h"
#include "repository.h"
static git_buf path = GIT_BUF_INIT;
void test_win32_longpath__initialize(void)
{
#ifdef GIT_WIN32
const char *base = clar_sandbox_path();
size_t base_len = strlen(base);
size_t remain = MAX_PATH - base_len;
size_t i;
git_buf_clear(&path);
git_buf_puts(&path, base);
git_buf_putc(&path, '/');
cl_assert(remain < (MAX_PATH - 5));
for (i = 0; i < (remain - 5); i++)
git_buf_putc(&path, 'a');
#endif
}
void test_win32_longpath__cleanup(void)
{
git_buf_dispose(&path);
cl_git_sandbox_cleanup();
}
#ifdef GIT_WIN32
void assert_name_too_long(void)
{
const git_error *err;
size_t expected_len, actual_len;
char *expected_msg;
err = git_error_last();
actual_len = strlen(err->message);
expected_msg = git_win32_get_error_message(ERROR_FILENAME_EXCED_RANGE);
expected_len = strlen(expected_msg);
/* check the suffix */
cl_assert_equal_s(expected_msg, err->message + (actual_len - expected_len));
git__free(expected_msg);
}
#endif
void test_win32_longpath__errmsg_on_checkout(void)
{
#ifdef GIT_WIN32
git_repository *repo;
cl_git_fail(git_clone(&repo, cl_fixture("testrepo.git"), path.ptr, NULL));
assert_name_too_long();
#endif
}
void test_win32_longpath__workdir_path_validated(void)
{
#ifdef GIT_WIN32
git_repository *repo = cl_git_sandbox_init("testrepo");
git_buf out = GIT_BUF_INIT;
cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));
/* even if the repo path is a drive letter, this is too long */
cl_git_fail(git_repository_workdir_path(&out, repo, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"));
cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
#endif
}