Skip to content

Commit 02bf766

Browse files
committed
Merge branch 'jk/attr-macro-fix'
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
2 parents 11494da + 7b95849 commit 02bf766

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

attr.c

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ static void collect_some_attrs(const struct index_state *istate,
10921092
const char *path,
10931093
struct attr_check *check)
10941094
{
1095-
int i, pathlen, rem, dirlen;
1095+
int pathlen, rem, dirlen;
10961096
const char *cp, *last_slash = NULL;
10971097
int basename_offset;
10981098

@@ -1113,20 +1113,6 @@ static void collect_some_attrs(const struct index_state *istate,
11131113
all_attrs_init(&g_attr_hashmap, check);
11141114
determine_macros(check->all_attrs, check->stack);
11151115

1116-
if (check->nr) {
1117-
rem = 0;
1118-
for (i = 0; i < check->nr; i++) {
1119-
int n = check->items[i].attr->attr_nr;
1120-
struct all_attrs_item *item = &check->all_attrs[n];
1121-
if (item->macro) {
1122-
item->value = ATTR__UNSET;
1123-
rem++;
1124-
}
1125-
}
1126-
if (rem == check->nr)
1127-
return;
1128-
}
1129-
11301116
rem = check->all_attrs_nr;
11311117
fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
11321118
}

t/t0003-attributes.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,4 +322,24 @@ test_expect_success 'bare repository: test info/attributes' '
322322
)
323323
'
324324

325+
test_expect_success 'binary macro expanded by -a' '
326+
echo "file binary" >.gitattributes &&
327+
cat >expect <<-\EOF &&
328+
file: binary: set
329+
file: diff: unset
330+
file: merge: unset
331+
file: text: unset
332+
EOF
333+
git check-attr -a file >actual &&
334+
test_cmp expect actual
335+
'
336+
337+
338+
test_expect_success 'query binary macro directly' '
339+
echo "file binary" >.gitattributes &&
340+
echo file: binary: set >expect &&
341+
git check-attr binary file >actual &&
342+
test_cmp expect actual
343+
'
344+
325345
test_done

0 commit comments

Comments
 (0)