Merge branch 'jk/attr-macro-fix'
authorJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:16 +0000 (14:26 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Feb 2019 22:26:16 +0000 (14:26 -0800)
Asking "git check-attr" about a macro (e.g. "binary") on a specific
path did not work correctly, even though "git check-attr -a" listed
such a macro correctly. This has been corrected.

* jk/attr-macro-fix:
attr: do not mark queried macros as unset

attr.c
t/t0003-attributes.sh
diff --git a/attr.c b/attr.c
index b63fe0fc0e99caa07dc2e6da816e1ac8d5942df6..0cba78912907e35a26e43156e124912467e46b27 100644 (file)
--- a/attr.c
+++ b/attr.c
@@ -1092,7 +1092,7 @@ static void collect_some_attrs(const struct index_state *istate,
                               const char *path,
                               struct attr_check *check)
 {
-       int i, pathlen, rem, dirlen;
+       int pathlen, rem, dirlen;
        const char *cp, *last_slash = NULL;
        int basename_offset;
 
@@ -1113,20 +1113,6 @@ static void collect_some_attrs(const struct index_state *istate,
        all_attrs_init(&g_attr_hashmap, check);
        determine_macros(check->all_attrs, check->stack);
 
-       if (check->nr) {
-               rem = 0;
-               for (i = 0; i < check->nr; i++) {
-                       int n = check->items[i].attr->attr_nr;
-                       struct all_attrs_item *item = &check->all_attrs[n];
-                       if (item->macro) {
-                               item->value = ATTR__UNSET;
-                               rem++;
-                       }
-               }
-               if (rem == check->nr)
-                       return;
-       }
-
        rem = check->all_attrs_nr;
        fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
 }
index 22499bce5f50637e574961f744b567b974a4d3d0..71e63d8b509d34fa4b860bac9ba1531e674799d7 100755 (executable)
@@ -322,4 +322,24 @@ test_expect_success 'bare repository: test info/attributes' '
        )
 '
 
+test_expect_success 'binary macro expanded by -a' '
+       echo "file binary" >.gitattributes &&
+       cat >expect <<-\EOF &&
+       file: binary: set
+       file: diff: unset
+       file: merge: unset
+       file: text: unset
+       EOF
+       git check-attr -a file >actual &&
+       test_cmp expect actual
+'
+
+
+test_expect_success 'query binary macro directly' '
+       echo "file binary" >.gitattributes &&
+       echo file: binary: set >expect &&
+       git check-attr binary file >actual &&
+       test_cmp expect actual
+'
+
 test_done