git-check-attr: Add an --all option to show all attributes
[gitweb.git] / t / t0003-attributes.sh
index de38c7f7aab16a0c2766ef020a3fc03fadece555..8892ba3bb2e55f16e4de3ee02c297077a6025740 100755 (executable)
@@ -35,7 +35,25 @@ 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
+
+'
+
+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 &&
+       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
 
 '
 
@@ -57,9 +75,19 @@ test_expect_success 'attribute test' '
 
 '
 
+test_expect_success 'core.attributesfile' '
+       attr_check global unspecified &&
+       git config core.attributesfile "$HOME/global-gitattributes" &&
+       attr_check global global &&
+       git config core.attributesfile "~/global-gitattributes" &&
+       attr_check global global &&
+       echo "global test=precedence" >> .gitattributes &&
+       attr_check global precedence
+'
+
 test_expect_success 'attribute test: read paths from stdin' '
 
-       cat <<EOF > expect
+       cat <<EOF > expect &&
 f: test: f
 a/f: test: f
 a/c/f: test: f
@@ -79,6 +107,30 @@ EOF
        test_cmp expect actual
 '
 
+test_expect_success 'attribute test: --all option' '
+
+       cat <<EOF > 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 &&