Teach '--cached' option to check-attr

This option causes check-attr to consider .gitattributes only from the index, ignoring .gitattributes from the working tree. This allows the command to be used in situations where a working tree does not exist. Signed-off-by: Jay Soffian <jaysoffian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jay Soffian committed Sep 22, 2011 at 17:44 UTC b2b3e9c2d623359ed680a5eef850ef2fd313b73c
3 files changed +29 -4
Documentation/git-check-attr.txt
+3
@@ -24,6 +24,9 @@ OPTIONS
24 paths. If this option is used, then 'unspecified' attributes
25 will not be included in the output.
26
27 +--cached::
28 + Consider `.gitattributes` in the index only, ignoring the working tree.
29 +
30 --stdin::
31 Read file names from stdin instead of from the command-line.
32
builtin/check-attr.c
+5
@@ -5,6 +5,7 @@
5 #include "parse-options.h"
6
7 static int all_attrs;
8 +static int cached_attrs;
9 static int stdin_paths;
10 static const char * const check_attr_usage[] = {
11 "git check-attr [-a | --all | attr...] [--] pathname...",
@@ -16,6 +17,7 @@ static int null_term_line;
17
18 static const struct option check_attr_options[] = {
19 OPT_BOOLEAN('a', "all", &all_attrs, "report all attributes set on file"),
20 + OPT_BOOLEAN(0, "cached", &cached_attrs, "use .gitattributes only from the index"),
21 OPT_BOOLEAN(0 , "stdin", &stdin_paths, "read file names from stdin"),
22 OPT_BOOLEAN('z', NULL, &null_term_line,
23 "input paths are terminated by a null character"),
@@ -99,6 +101,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
101 die("invalid cache");
102 }
103
104 + if (cached_attrs)
105 + git_attr_set_direction(GIT_ATTR_INDEX, NULL);
106 +
107 doubledash = -1;
108 for (i = 0; doubledash < 0 && i < argc; i++) {
109 if (!strcmp(argv[i], "--"))
t/t0003-attributes.sh
+21 -4
@@ -134,10 +134,20 @@ test_expect_success 'attribute test: read paths from stdin' '
134
135 test_expect_success 'attribute test: --all option' '
136
137 - grep -v unspecified < expect-all | sort > expect &&
138 - sed -e "s/:.*//" < expect-all | uniq |
139 - git check-attr --stdin --all | sort > actual &&
140 - test_cmp expect actual
137 + grep -v unspecified <expect-all | sort >specified-all &&
138 + sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
139 + git check-attr --stdin --all <stdin-all | sort >actual &&
140 + test_cmp specified-all actual
141 +'
142 +
143 +test_expect_success 'attribute test: --cached option' '
144 +
145 + : >empty &&
146 + git check-attr --cached --stdin --all <stdin-all | sort >actual &&
147 + test_cmp empty actual &&
148 + git add .gitattributes a/.gitattributes a/b/.gitattributes &&
149 + git check-attr --cached --stdin --all <stdin-all | sort >actual &&
150 + test_cmp specified-all actual
151 '
152
153 test_expect_success 'root subdir attribute test' '
@@ -168,6 +178,13 @@ test_expect_success 'bare repository: check that .gitattribute is ignored' '
178
179 '
180
181 +test_expect_success 'bare repository: check that --cached honors index' '
182 + GIT_INDEX_FILE=../.git/index \
183 + git check-attr --cached --stdin --all <../stdin-all |
184 + sort >actual &&
185 + test_cmp ../specified-all actual
186 +'
187 +
188 test_expect_success 'bare repository: test info/attributes' '
189
190 (