archive-zip: load userdiff config
authorJeff King <peff@peff.net>
Mon, 2 Jan 2017 22:25:09 +0000 (17:25 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 8 Jan 2017 02:49:30 +0000 (18:49 -0800)
Since 4aff646d17 (archive-zip: mark text files in archives,
2015-03-05), the zip archiver will look at the userdiff
driver to decide whether a file is text or binary. This
usually doesn't need to look any further than the attributes
themselves (e.g., "-diff", etc). But if the user defines a
custom driver like "diff=foo", we need to look at
"diff.foo.binary" in the config. Prior to this patch, we
didn't actually load it.

Signed-off-by: Jeff King <peff@peff.net>
Acked-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-zip.c
t/t5003-archive-zip.sh
index 9db47357b02d4c33fc4e2d1edb8d948b2b3a496f..b429a8d974a02b06c9c6bc46850f4c9fae4a6d01 100644 (file)
@@ -554,11 +554,18 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time)
        *dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
 }
 
+static int archive_zip_config(const char *var, const char *value, void *data)
+{
+       return userdiff_config(var, value);
+}
+
 static int write_zip_archive(const struct archiver *ar,
                             struct archiver_args *args)
 {
        int err;
 
+       git_config(archive_zip_config, NULL);
+
        dos_time(&args->time, &zip_date, &zip_time);
 
        zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
index 14744b2a4b1e646890176ec53970d36de6f8ec3b..55c78709978ff75cdbd794ee4c816dfd1eb55ef0 100755 (executable)
@@ -64,6 +64,12 @@ check_zip() {
                test_cmp_bin $original/nodiff.crlf $extracted/nodiff.crlf &&
                test_cmp_bin $original/nodiff.lf   $extracted/nodiff.lf
        "
+
+       test_expect_success UNZIP " validate that custom diff is unchanged " "
+               test_cmp_bin $original/custom.cr   $extracted/custom.cr &&
+               test_cmp_bin $original/custom.crlf $extracted/custom.crlf &&
+               test_cmp_bin $original/custom.lf   $extracted/custom.lf
+       "
 }
 
 test_expect_success \
@@ -78,6 +84,9 @@ test_expect_success \
      printf "text\r"   >a/nodiff.cr &&
      printf "text\r\n" >a/nodiff.crlf &&
      printf "text\n"   >a/nodiff.lf &&
+     printf "text\r"   >a/custom.cr &&
+     printf "text\r\n" >a/custom.crlf &&
+     printf "text\n"   >a/custom.lf &&
      printf "\0\r"     >a/binary.cr &&
      printf "\0\r\n"   >a/binary.crlf &&
      printf "\0\n"     >a/binary.lf &&
@@ -112,15 +121,20 @@ test_expect_success 'add files to repository' '
 test_expect_success 'setup export-subst and diff attributes' '
        echo "a/nodiff.* -diff" >>.git/info/attributes &&
        echo "a/diff.* diff" >>.git/info/attributes &&
+       echo "a/custom.* diff=custom" >>.git/info/attributes &&
+       git config diff.custom.binary true &&
        echo "substfile?" export-subst >>.git/info/attributes &&
        git log --max-count=1 "--pretty=format:A${SUBSTFORMAT}O" HEAD \
                >a/substfile1
 '
 
-test_expect_success \
-    'create bare clone' \
-    'git clone --bare . bare.git &&
-     cp .git/info/attributes bare.git/info/attributes'
+test_expect_success 'create bare clone' '
+       git clone --bare . bare.git &&
+       cp .git/info/attributes bare.git/info/attributes &&
+       # Recreate our changes to .git/config rather than just copying it, as
+       # we do not want to clobber core.bare or other settings.
+       git -C bare.git config diff.custom.binary true
+'
 
 test_expect_success \
     'remove ignored file' \