Skip to content

Commit 7297a44

Browse files
johnkeepinggitster
authored andcommitted
entry: fix filter lookup
When looking up the stream filter, write_entry() should be passing the path of the file in the repository, not the path to which the content is going to be written. This allows the file to be correctly looked up against the .gitattributes files in the working tree. This change makes the streaming case match the non-streaming case which passes ce->name to convert_to_working_tree later in the same function. The two tests added here test the different paths through write_entry since the CRLF filter is a streaming filter but the user-defined smudge filter is not streamed. Signed-off-by: John Keeping <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 013c3bb commit 7297a44

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

entry.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
188188
struct stat st;
189189

190190
if (ce_mode_s_ifmt == S_IFREG) {
191-
struct stream_filter *filter = get_stream_filter(path, ce->sha1);
191+
struct stream_filter *filter = get_stream_filter(ce->name, ce->sha1);
192192
if (filter &&
193193
!streaming_write_entry(ce, path, filter,
194194
state, to_tempfile,

t/t2003-checkout-cache-mkdir.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,30 @@ test_expect_success SYMLINKS 'use --prefix=tmp- where tmp-path1 is a symlink' '
9090
test -f tmp-path1/file1
9191
'
9292

93+
test_expect_success 'apply filter from working tree .gitattributes with --prefix' '
94+
rm -fr path0 path1 path2 tmp* &&
95+
mkdir path1 &&
96+
mkdir tmp &&
97+
git config filter.replace-all.smudge "sed -e s/./=/g" &&
98+
git config filter.replace-all.clean cat &&
99+
git config filter.replace-all.required true &&
100+
echo "file1 filter=replace-all" >path1/.gitattributes &&
101+
git checkout-index --prefix=tmp/ -f -a &&
102+
echo frotz >expected &&
103+
test_cmp expected tmp/path0 &&
104+
echo ====== >expected &&
105+
test_cmp expected tmp/path1/file1
106+
'
107+
108+
test_expect_success 'apply CRLF filter from working tree .gitattributes with --prefix' '
109+
rm -fr path0 path1 path2 tmp* &&
110+
mkdir path1 &&
111+
mkdir tmp &&
112+
echo "file1 eol=crlf" >path1/.gitattributes &&
113+
git checkout-index --prefix=tmp/ -f -a &&
114+
echo rezrovQ >expected &&
115+
tr \\015 Q <tmp/path1/file1 >actual &&
116+
test_cmp expected actual
117+
'
118+
93119
test_done

0 commit comments

Comments
 (0)