Skip to content

Commit 26bf94c

Browse files
committed
If longpaths is true and filters are enabled, pass git_repository through the filtering code to ensure the cached longpath setting is returned.
Fixes: libgit2#6054
1 parent f1b89a2 commit 26bf94c

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/blob.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,13 @@ static int write_file_filtered(
138138
git_object_size_t *size,
139139
git_odb *odb,
140140
const char *full_path,
141-
git_filter_list *fl)
141+
git_filter_list *fl,
142+
git_repository* repo)
142143
{
143144
int error;
144145
git_buf tgt = GIT_BUF_INIT;
145146

146-
error = git_filter_list_apply_to_file(&tgt, fl, NULL, full_path);
147+
error = git_filter_list_apply_to_file(&tgt, fl, repo, full_path);
147148

148149
/* Write the file to disk if it was properly filtered */
149150
if (!error) {
@@ -238,7 +239,7 @@ int git_blob__create_from_paths(
238239
error = write_file_stream(id, odb, content_path, size);
239240
else {
240241
/* We need to apply one or more filters */
241-
error = write_file_filtered(id, &size, odb, content_path, fl);
242+
error = write_file_filtered(id, &size, odb, content_path, fl, repo);
242243

243244
git_filter_list_free(fl);
244245
}

tests/win32/longpath.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,31 @@ void test_win32_longpath__status_and_add(void)
9090
git_buf_dispose(&out);
9191
#endif
9292
}
93+
94+
void test_win32_longpath__status_and_add_with_filter(void)
95+
{
96+
#ifdef GIT_WIN32
97+
git_repository *repo = cl_git_sandbox_init("testrepo");
98+
git_index *index;
99+
git_buf out = GIT_BUF_INIT;
100+
unsigned int status_flags;
101+
102+
cl_repo_set_bool(repo, "core.longpaths", true);
103+
cl_repo_set_bool(repo, "core.autocrlf", true);
104+
cl_git_pass(git_repository_workdir_path(&out, repo, LONG_FILENAME));
105+
106+
cl_git_rewritefile(out.ptr, "This is a long path.\r\n");
107+
108+
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
109+
cl_assert_equal_i(GIT_STATUS_WT_NEW, status_flags);
110+
111+
cl_git_pass(git_repository_index(&index, repo));
112+
cl_git_pass(git_index_add_bypath(index, LONG_FILENAME));
113+
114+
cl_git_pass(git_status_file(&status_flags, repo, LONG_FILENAME));
115+
cl_assert_equal_i(GIT_STATUS_INDEX_NEW, status_flags);
116+
117+
git_index_free(index);
118+
git_buf_dispose(&out);
119+
#endif
120+
}

0 commit comments

Comments
 (0)