entry: fix filter lookup
authorJohn Keeping <john@keeping.me.uk>
Thu, 14 Mar 2013 20:00:51 +0000 (20:00 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Mar 2013 21:49:48 +0000 (14:49 -0700)
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 <john@keeping.me.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
entry.c
t/t2003-checkout-cache-mkdir.sh
diff --git a/entry.c b/entry.c
index 852fea13955475c1e2fda9cfc25a63a54a1f61c7..6a1eb80c387007b7c49999d5f47ded81a1bdcf0f 100644 (file)
--- a/entry.c
+++ b/entry.c
@@ -188,7 +188,7 @@ static int write_entry(struct cache_entry *ce, char *path, const struct checkout
        struct stat st;
 
        if (ce_mode_s_ifmt == S_IFREG) {
-               struct stream_filter *filter = get_stream_filter(path, ce->sha1);
+               struct stream_filter *filter = get_stream_filter(ce->name, ce->sha1);
                if (filter &&
                    !streaming_write_entry(ce, path, filter,
                                           state, to_tempfile,
index 63fd0a883542ac8c1caf34b9b860ffd22639367f..4c97468b82e69037290d43f18a14fe08e91adb1b 100755 (executable)
@@ -90,4 +90,30 @@ test_expect_success SYMLINKS 'use --prefix=tmp- where tmp-path1 is a symlink' '
        test -f tmp-path1/file1
 '
 
+test_expect_success 'apply filter from working tree .gitattributes with --prefix' '
+       rm -fr path0 path1 path2 tmp* &&
+       mkdir path1 &&
+       mkdir tmp &&
+       git config filter.replace-all.smudge "sed -e s/./=/g" &&
+       git config filter.replace-all.clean cat &&
+       git config filter.replace-all.required true &&
+       echo "file1 filter=replace-all" >path1/.gitattributes &&
+       git checkout-index --prefix=tmp/ -f -a &&
+       echo frotz >expected &&
+       test_cmp expected tmp/path0 &&
+       echo ====== >expected &&
+       test_cmp expected tmp/path1/file1
+'
+
+test_expect_success 'apply CRLF filter from working tree .gitattributes with --prefix' '
+       rm -fr path0 path1 path2 tmp* &&
+       mkdir path1 &&
+       mkdir tmp &&
+       echo "file1 eol=crlf" >path1/.gitattributes &&
+       git checkout-index --prefix=tmp/ -f -a &&
+       echo rezrovQ >expected &&
+       tr \\015 Q <tmp/path1/file1 >actual &&
+       test_cmp expected actual
+'
+
 test_done