longpath.c 3.81 KB
Newer Older
1 2 3 4
#include "clar_libgit2.h"

#include "git2/clone.h"
#include "clone.h"
5
#include "futils.h"
6
#include "repository.h"
7

8
static git_str path = GIT_STR_INIT;
9

10 11
#define LONG_FILENAME "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.txt"

12 13 14 15 16 17 18 19
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;

20 21 22
	git_str_clear(&path);
	git_str_puts(&path, base);
	git_str_putc(&path, '/');
23 24 25 26

	cl_assert(remain < (MAX_PATH - 5));

	for (i = 0; i < (remain - 5); i++)
27
		git_str_putc(&path, 'a');
28 29 30 31 32
#endif
}

void test_win32_longpath__cleanup(void)
{
33
	git_str_dispose(&path);
34
	cl_git_sandbox_cleanup();
35 36 37 38 39 40 41 42
}

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));
43
	cl_assert(git__prefixcmp(git_error_last()->message, "path too long") == 0);
44 45
#endif
}
46 47 48 49 50

void test_win32_longpath__workdir_path_validated(void)
{
#ifdef GIT_WIN32
	git_repository *repo = cl_git_sandbox_init("testrepo");
51
	git_str out = GIT_STR_INIT;
52 53 54 55

	cl_git_pass(git_repository_workdir_path(&out, repo, "a.txt"));

	/* 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 60

	cl_repo_set_bool(repo, "core.longpaths", true);
	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 64 65
#endif
}

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 73 74 75
	unsigned int status_flags;

	cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));

76
	cl_git_rewritefile(out.ptr, wddata);
77 78 79 80 81 82 83 84 85 86

	cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
	cl_assert_equal_i(GIT_STATUS_WT_NEW, status_flags);

	cl_git_pass(git_repository_index(&index, repo));
	cl_git_pass(git_index_add_bypath(index, LONG_FILENAME));

	cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
	cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status_flags);

87 88 89 90 91
	cl_assert((entry = git_index_get_bypath(index, LONG_FILENAME, 0)) != NULL);
	cl_git_pass(git_blob_lookup(&blob, repo, &entry->id));
	cl_assert_equal_s(repodata, git_blob_rawcontent(blob));

	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 100 101 102 103
{
#ifdef GIT_WIN32
	git_repository *repo = cl_git_sandbox_init("testrepo");

	cl_repo_set_bool(repo, "core.longpaths", true);

104 105 106 107 108 109 110
	/*
	 * Doing no content filtering, we expect the data we add
	 * to be the data in the repository.
	 */
	assert_longpath_status_and_add(repo,
	    "This is a long path.\r\n",
	    "This is a long path.\r\n");
111 112
#endif
}
113

114 115 116 117
void test_win32_longpath__status_and_add_with_filter(void)
{
#ifdef GIT_WIN32
	git_repository *repo = cl_git_sandbox_init("testrepo");
118

119 120
	cl_repo_set_bool(repo, "core.longpaths", true);
	cl_repo_set_bool(repo, "core.autocrlf", true);
121

122 123 124 125 126 127 128
	/*
	 * With `core.autocrlf`, we expect the data we add to have
	 * newline conversion performed.
	 */
	assert_longpath_status_and_add(repo,
	    "This is a long path.\r\n",
	    "This is a long path.\n");
129 130
#endif
}