Skip to content

Commit

Permalink
Teach '--cached' option to check-attr
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jay Soffian authored and Junio C Hamano committed Sep 22, 2011
1 parent 167a580 commit b2b3e9c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Documentation/git-check-attr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ OPTIONS
paths. If this option is used, then 'unspecified' attributes
will not be included in the output.

--cached::
Consider `.gitattributes` in the index only, ignoring the working tree.

--stdin::
Read file names from stdin instead of from the command-line.

Expand Down
5 changes: 5 additions & 0 deletions builtin/check-attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "parse-options.h"

static int all_attrs;
static int cached_attrs;
static int stdin_paths;
static const char * const check_attr_usage[] = {
"git check-attr [-a | --all | attr...] [--] pathname...",
Expand All @@ -16,6 +17,7 @@ static int null_term_line;

static const struct option check_attr_options[] = {
OPT_BOOLEAN('a', "all", &all_attrs, "report all attributes set on file"),
OPT_BOOLEAN(0, "cached", &cached_attrs, "use .gitattributes only from the index"),
OPT_BOOLEAN(0 , "stdin", &stdin_paths, "read file names from stdin"),
OPT_BOOLEAN('z', NULL, &null_term_line,
"input paths are terminated by a null character"),
Expand Down Expand Up @@ -99,6 +101,9 @@ int cmd_check_attr(int argc, const char **argv, const char *prefix)
die("invalid cache");
}

if (cached_attrs)
git_attr_set_direction(GIT_ATTR_INDEX, NULL);

doubledash = -1;
for (i = 0; doubledash < 0 && i < argc; i++) {
if (!strcmp(argv[i], "--"))
Expand Down
25 changes: 21 additions & 4 deletions t/t0003-attributes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,20 @@ test_expect_success 'attribute test: read paths from stdin' '

test_expect_success 'attribute test: --all option' '
grep -v unspecified < expect-all | sort > expect &&
sed -e "s/:.*//" < expect-all | uniq |
git check-attr --stdin --all | sort > actual &&
test_cmp expect actual
grep -v unspecified <expect-all | sort >specified-all &&
sed -e "s/:.*//" <expect-all | uniq >stdin-all &&
git check-attr --stdin --all <stdin-all | sort >actual &&
test_cmp specified-all actual
'

test_expect_success 'attribute test: --cached option' '
: >empty &&
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
test_cmp empty actual &&
git add .gitattributes a/.gitattributes a/b/.gitattributes &&
git check-attr --cached --stdin --all <stdin-all | sort >actual &&
test_cmp specified-all actual
'

test_expect_success 'root subdir attribute test' '
Expand Down Expand Up @@ -168,6 +178,13 @@ test_expect_success 'bare repository: check that .gitattribute is ignored' '
'

test_expect_success 'bare repository: check that --cached honors index' '
GIT_INDEX_FILE=../.git/index \
git check-attr --cached --stdin --all <../stdin-all |
sort >actual &&
test_cmp ../specified-all actual
'

test_expect_success 'bare repository: test info/attributes' '
(
Expand Down

0 comments on commit b2b3e9c

Please sign in to comment.