From c0b13b21b8daa4bfb222e9c4d335c8b340c511a0 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:14 +0200 Subject: Disallow the empty string as an attribute name Previously, it was possible to have a line like "file.txt =foo" in a .gitattribute file, after which an invocation like "git check-attr '' -- file.txt" would succeed. This patch disallows both constructs. Please note that any existing .gitattributes file that tries to set an empty attribute will now trigger the error message "error: : not a valid attribute name" whereas previously the nonsense was allowed through. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index ebbc7554a7..8c76b79bb0 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -42,6 +42,12 @@ test_expect_success 'setup' ' ' +test_expect_success 'command line checks' ' + + test_must_fail git check-attr "" -- f + +' + test_expect_success 'attribute test' ' attr_check f f && -- cgit v1.2.3 From dcc04366a4658763500724888d9e74cae317c861 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:15 +0200 Subject: git-check-attr: Add missing "&&" Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 8c76b79bb0..dae76b39b8 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -35,7 +35,7 @@ test_expect_success 'setup' ' echo "h test=a/b/h" && echo "d/* test=a/b/d/*" echo "d/yes notest" - ) >a/b/.gitattributes + ) >a/b/.gitattributes && ( echo "global test=global" ) >"$HOME"/global-gitattributes -- cgit v1.2.3 From 09d7dd7ad62fef60fc223fa74eb04c8dc783c2f6 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:16 +0200 Subject: git-check-attr: Add tests of command-line parsing Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index dae76b39b8..f1debeb7ad 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -44,6 +44,13 @@ test_expect_success 'setup' ' test_expect_success 'command line checks' ' + test_must_fail git check-attr && + test_must_fail git check-attr -- && + test_must_fail git check-attr -- f && + echo "f" | test_must_fail git check-attr --stdin && + echo "f" | test_must_fail git check-attr --stdin -- f && + echo "f" | test_must_fail git check-attr --stdin test -- f && + echo "f" | test_must_fail git check-attr --stdin test f && test_must_fail git check-attr "" -- f ' -- cgit v1.2.3 From fdf6be8259fc59fc251b325f66e86df0fe905e79 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:29 +0200 Subject: git-check-attr: Error out if no pathnames are specified If no pathnames are passed as command-line arguments and the --stdin option is not specified, fail with the error message "No file specified". Add tests of this behavior. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 2 ++ 1 file changed, 2 insertions(+) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index f1debeb7ad..22540051d8 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -46,6 +46,8 @@ test_expect_success 'command line checks' ' test_must_fail git check-attr && test_must_fail git check-attr -- && + test_must_fail git check-attr test && + test_must_fail git check-attr test -- && test_must_fail git check-attr -- f && echo "f" | test_must_fail git check-attr --stdin && echo "f" | test_must_fail git check-attr --stdin -- f && -- cgit v1.2.3 From 4ca0f188f6ece3098b60b6ba732e1e8551466f60 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:30 +0200 Subject: git-check-attr: Add an --all option to show all attributes Add new usage patterns git check-attr [-a | --all] [--] pathname... git check-attr --stdin [-a | --all] < which display all attributes associated with the specified file(s). Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 22540051d8..8892ba3bb2 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -107,6 +107,30 @@ EOF test_cmp expect actual ' +test_expect_success 'attribute test: --all option' ' + + cat < all && +f: test: f +a/f: test: f +a/c/f: test: f +a/g: test: a/g +a/b/g: test: a/b/g +b/g: test: unspecified +a/b/h: test: a/b/h +a/b/d/g: test: a/b/d/* +onoff: test: unset +offon: test: set +no: notest: set +a/b/d/no: test: a/b/d/* +a/b/d/no: notest: set +a/b/d/yes: notest: set +EOF + + grep -v unspecified < all | sort > expect && + sed -e "s/:.*//" < all | uniq | git check-attr --stdin --all | sort > actual && + test_cmp expect actual +' + test_expect_success 'root subdir attribute test' ' attr_check a/i a/i && -- cgit v1.2.3 From c9d8f0ac3b9029d825c7d1c049953aacbc489e1c Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:31 +0200 Subject: git-check-attr: Drive two tests using the same raw data Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 59 ++++++++++++++++++++------------------------------- 1 file changed, 23 insertions(+), 36 deletions(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 8892ba3bb2..a49f8a9813 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -38,7 +38,25 @@ test_expect_success 'setup' ' ) >a/b/.gitattributes && ( echo "global test=global" - ) >"$HOME"/global-gitattributes + ) >"$HOME"/global-gitattributes && + cat <expect-all +f: test: f +a/f: test: f +a/c/f: test: f +a/g: test: a/g +a/b/g: test: a/b/g +b/g: test: unspecified +a/b/h: test: a/b/h +a/b/d/g: test: a/b/d/* +onoff: test: unset +offon: test: set +no: notest: set +no: test: unspecified +a/b/d/no: notest: set +a/b/d/no: test: a/b/d/* +a/b/d/yes: notest: set +a/b/d/yes: test: unspecified +EOF ' @@ -87,47 +105,16 @@ test_expect_success 'core.attributesfile' ' test_expect_success 'attribute test: read paths from stdin' ' - cat < expect && -f: test: f -a/f: test: f -a/c/f: test: f -a/g: test: a/g -a/b/g: test: a/b/g -b/g: test: unspecified -a/b/h: test: a/b/h -a/b/d/g: test: a/b/d/* -onoff: test: unset -offon: test: set -no: test: unspecified -a/b/d/no: test: a/b/d/* -a/b/d/yes: test: unspecified -EOF - + grep -v notest < expect-all > expect && sed -e "s/:.*//" < expect | git check-attr --stdin test > actual && test_cmp expect actual ' test_expect_success 'attribute test: --all option' ' - cat < all && -f: test: f -a/f: test: f -a/c/f: test: f -a/g: test: a/g -a/b/g: test: a/b/g -b/g: test: unspecified -a/b/h: test: a/b/h -a/b/d/g: test: a/b/d/* -onoff: test: unset -offon: test: set -no: notest: set -a/b/d/no: test: a/b/d/* -a/b/d/no: notest: set -a/b/d/yes: notest: set -EOF - - grep -v unspecified < all | sort > expect && - sed -e "s/:.*//" < all | uniq | git check-attr --stdin --all | sort > actual && + grep -v unspecified < expect-all | sort > expect && + sed -e "s/:.*//" < expect-all | uniq | + git check-attr --stdin --all | sort > actual && test_cmp expect actual ' -- cgit v1.2.3 From ca64d061e0ddf7fa1496a15c75eb5e730c4360e0 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:36:32 +0200 Subject: git-check-attr: Fix command-line handling to match docs According to the git-check-attr synopsis, if the '--stdin' option is used then no pathnames are expected on the command line. Change the behavior to match this description; namely, if '--stdin' is used but not '--', then treat all command-line arguments as attribute names. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 1 - 1 file changed, 1 deletion(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index a49f8a9813..5acb2d5bbd 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -70,7 +70,6 @@ test_expect_success 'command line checks' ' echo "f" | test_must_fail git check-attr --stdin && echo "f" | test_must_fail git check-attr --stdin -- f && echo "f" | test_must_fail git check-attr --stdin test -- f && - echo "f" | test_must_fail git check-attr --stdin test f && test_must_fail git check-attr "" -- f ' -- cgit v1.2.3 From fa92f3233c65251c3311f0834526ce96a1963554 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:47:43 +0200 Subject: git-check-attr: test that no output is written to stderr Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 5acb2d5bbd..4f2fbc0781 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -9,9 +9,10 @@ attr_check () { path="$1" expect="$2" - git check-attr test -- "$path" >actual && + git check-attr test -- "$path" >actual 2>err && echo "$path: test: $2" >expect && - test_cmp expect actual + test_cmp expect actual && + test_line_count = 0 err } -- cgit v1.2.3 From d4d4f8df14c3c19d445a8a79dca56bd33812ee04 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:47:44 +0200 Subject: git-check-attr: Demonstrate problems with unnormalized paths Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 4f2fbc0781..43957eae68 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -93,6 +93,15 @@ test_expect_success 'attribute test' ' ' +test_expect_failure 'unnormalized paths' ' + + attr_check ./f f && + attr_check ./a/g a/g && + attr_check a/./g a/g && + attr_check a/c/../b/g a/b/g + +' + test_expect_success 'core.attributesfile' ' attr_check global unspecified && git config core.attributesfile "$HOME/global-gitattributes" && -- cgit v1.2.3 From 0216af8356ef562147251c40fef72be25b8b9b07 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:47:45 +0200 Subject: git-check-attr: Demonstrate problems with relative paths Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 43957eae68..f6cf77d125 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -19,7 +19,7 @@ attr_check () { test_expect_success 'setup' ' - mkdir -p a/b/d a/c && + mkdir -p a/b/d a/c b && ( echo "[attr]notest !test" echo "f test=f" @@ -102,6 +102,19 @@ test_expect_failure 'unnormalized paths' ' ' +test_expect_failure 'relative paths' ' + + (cd a && attr_check ../f f) && + (cd a && attr_check f f) && + (cd a && attr_check i a/i) && + (cd a && attr_check g a/g) && + (cd a && attr_check b/g a/b/g) && + (cd b && attr_check ../a/f f) && + (cd b && attr_check ../a/g a/g) && + (cd b && attr_check ../a/b/g a/b/g) + +' + test_expect_success 'core.attributesfile' ' attr_check global unspecified && git config core.attributesfile "$HOME/global-gitattributes" && -- cgit v1.2.3 From f5114a40c0d0276ce6ff215a3dc51eb19da5b420 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 4 Aug 2011 06:47:46 +0200 Subject: git-check-attr: Normalize paths Normalize the path arguments (relative to the working tree root, if applicable) before looking up their attributes. This requires passing the prefix down the call chain. This fixes two test cases for different reasons: * "unnormalized paths" is fixed because the .gitattribute-file-seeking code is not confused into reading the top-level file twice. * "relative paths" is fixed because the canonical pathnames are passed to get_check_attr() or get_all_attrs(), allowing them to match the pathname patterns as expected. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t0003-attributes.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index f6cf77d125..ae2f1da28f 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -93,7 +93,7 @@ test_expect_success 'attribute test' ' ' -test_expect_failure 'unnormalized paths' ' +test_expect_success 'unnormalized paths' ' attr_check ./f f && attr_check ./a/g a/g && @@ -102,7 +102,7 @@ test_expect_failure 'unnormalized paths' ' ' -test_expect_failure 'relative paths' ' +test_expect_success 'relative paths' ' (cd a && attr_check ../f f) && (cd a && attr_check f f) && -- cgit v1.2.3